Symbol Table is an important data structure that is created and maintained by the compilers in order to track information about the occurrences of various entities such as variable names, objects, function names, interfaces, etc. The information that is collected by the compiler inside the symbol table in the analysis phase is used by the synthesis phase to generate the target code.

Comparison between different implementations of Symbol Table :

**1. Array (Sorted) :**

**Insertion Time –**

When inserting an element traversing must be done in order to shift elements to right. Thus, it takes O(n) time.**Lookup Time –**

While looking up a binary search can be used to find an element. Thus, it takes O(log n) time.

**2. Linked List :**

**Insertion Time –**

Similar to arrays here in order to search for the position to insert the element traversing is required. Thus, it takes O(n) time.**Lookup Time –**

While fetching a data item the linked list must be traversed completely ( linear search ). Thus, this operation takes O(n) time.

**3. Unordered List :**

**Insertion Time –**

In an unordered array, insertion can be done at the beginning whereas in an unordered linked list insertion can be done at the end. Thus, it requires O(n) time.**Lookup Time –**

As it is an unordered list complete list must be searched in order to find an element. Thus, it takes O(n) time.

Disadvantages of using Array, Linked Lists, or Unsorted Lists for symbol table implementations :

- Lookup time is directly proportional to the table size.
- Every insertion operation is preceded with lookup operation.

**4. Self-organizing List :**

**Insertion Time –**

It is generally an unsorted list therefore, the time taken to insert an element is O(1).**Lookup Time –**

Searching for an element here requires to search an element and then shift it to the beginning of the list so that the most frequently used elements are at the beginning of the list. As it is, in general, an unsorted list searching requires O(n) time.

Disadvantages of using Self-organizing Lists for symbol table implementations :

The disadvantage in this implementation is that whenever less frequent elements are searched then the performance becomes poor.

**5. Search Trees (Balanced) :**

**Insertion Time –**

If there are n elements in the tree and the order of the tree is k, then the height of the tree will be logkn. Now, in the worst case, the insertion would happen at the height of the tree. Thus, the time required is O(logkn).**Lookup Time –**

In a balanced search tree, the time required for searching is O(logkn).

Disadvantages of using Search Trees for symbol table implementations :

The disadvantage of this implementation is that the tree always has to be kept balanced.

**6. Hashing :**

**Insertion Time –**

As in a hash table insertion takes constant time so the time required for insertion is O(1).**Lookup Time –**

Searching in a hash table requires constant time so the time required is O(1).

Disadvantages of using Hashing for symbol table implementations :

The disadvantage of this implementation is when there are too many collisions the time complexity increases to O(n).

Thus, we can see that every implementation of the symbol table is unique and has its own disadvantages. The implementer according to its requirements can choose any of the above implementations of Symbol Tables.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

## Recommended Posts:

- C++ Program to implement Symbol Table
- Symbol Table in Compiler
- Page Table Entries in Page Table
- Various Implicants in K-Map
- Inclusion-Exclusion and its various Applications
- Applications of various Automata
- Various terms in File System
- Advantages and Disadvantages of various CPU scheduling algorithms
- Various Properties of context free languages (CFL)
- Advantages and Disadvantages of various Page Replacement algorithms
- Basic Laws for Various Arithmetic Operations
- Advantages and Disadvantages of various Disk scheduling algorithms
- Various Instructions for five stage Pipeline
- Allowed Functional Dependencies (FD) in Various Normal Forms (NF)
- DFA of a string in which 2nd symbol from RHS is 'a'
- DFA of a string in which 3rd symbol from RHS is ‘a’
- Process Table and Process Control Block (PCB)
- Inverted Page Table in Operating System
- Decidability Table in Theory of Computation
- Construction of LL(1) Parsing Table

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.