1

From sedgewick course, I learnt that,

Symbol table

Symbol table is a key-value pair abstraction

where, given a key, search for the corresponding value.

value is not null

get() returns null if key not present

put() overwrites old value with new value.

After introducing Symbol table abstraction, not sure, why the term Dictionary abstraction & Map abstraction is introduced? Stack overflow maintains these tags.

Symbol table representation using List implementation,

typedef struct{
  void **array;
  int size;
}List;

typedef struct{
  void *key;
  void *value; // cannot be null
}Pair;

typedef struct ST{

  List *keyValuePairList;
}ST;

From wiki, I learnt that,

A Set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set.

From wiki definition of Set, I would conclude,

Set is an abstraction that contains distinct items,

where, each item has a key,

maintaining corresponding value does not violate Set property,

value can be null,

get() returns null if key not present,

put() overwrite old value with new value, if value is not null.


From operation & data aspect, Set and Symbol Table look similar. It is difficult to understand, when to use what?

Set representation using List implementation,

typedef struct{
  void **array;
  int size;
}List;

typedef struct{
  void *key;
  void *value; // can be null
}Pair;

typedef struct{

  List *keyValuePairList;
}Set;

Question:

Isput() operation that differentiates Set and Symbol Table? I still see these two are same.

Community
  • 1
  • 1
overexchange
  • 15,768
  • 30
  • 152
  • 347

2 Answers2

2

A symbol table typically is is a (hash) table of symbols (or any other key/value oriented data structure) used in compilers and linkers to associate symbols with addresses.

The term is not commonly used as a notation for generic data structures.

Either you or the makers of the course have messed up the terminology between a generic data structure (e.g. "hash table", "map", "dictionary" which are all alternative names for a data structure that stores values ordered and accessible by keys) and the specific application of a generic data structure ("symbol table") in compiler and linker technology that stores addresses related to names.

tofro
  • 5,640
  • 14
  • 31
  • But Sedgewick introduce Symbol table, and then implement dictionary(word-definition) using symbol table, where symbol table can be implemented using list/hashtable/etc. Symbol tables used in C `staticbinary.a`, `sharedBinary.so` also use ST. – overexchange Jan 22 '17 at 10:41
  • 1
    *symbol table* denotes to **what it is used for** - *hash table* or *map* denotes to **what it is**. – tofro Jan 22 '17 at 10:48
2

A Set only stores values, not key-value pairs.

What this course is describing as a symbol table, is more commonly called a Map. It is not appropriate to use "symbol table" as the name of the abstraction because it might not be implemented in a tabular way and it might not store symbols.

So the difference between a Set and a Map is that a Map maps keys to values, and can look up values corresponding to keys, whereas a Set only stores values, and can only test whether a value is in itself. Although a Set can trivially be implemented by using a Map and mapping each element to be inserted to itself - or to null, as you suggested.

The purpose of having a separate Set abstraction, is to signal to other programmers that the mapping is not significant, and to abstract away the "dummy" values (the nulls or the copies of the values), which saves typing and decreases cognitive load on the programmer.

Robin Green
  • 32,079
  • 16
  • 104
  • 187