Symbol Table Implementations

    by nikoo28

    Symbol Tables can be implemented in many ways and here are some of them.

    Unordered Array Implementation

    With this method, just maintaining an array is enough. It needs O(n) time for searching, insertion and deletion in the worst case.

    Ordered [Sorted] Array Implementation

    In this we maintain a sorted array of keys and values.

    • Store in sorted order by key
    • keys[i] = ith largest key
    • values[i] = value associated with ith largest key

    Since the elements are sorted and stored in arrays, we can use simple binary search for finding an element. It takes O(log n) time fir searching and O(n) time for insertion and deletion in the worst case.

    Unordered Linked List Implementation

    Just maintaining a linked list with two data values is enough for this method. It needs O(n) time for searching, insertion and deletion in the worst case.

    Ordered Linked List Implementation

    In this method, while inserting the keys, maintain the order of keys in the linked list. Even if the list is sorted, in the worst case it needs O(n) time for searching, insertion and deletion.

    Some of the other methods are:-

    • Binary Search Trees Implementations
    • Balanced Binary Search Trees Implementations
    • Ternary Search Implementation
    • Hashing Implementation

    COMPARISON OF SYMBOL TABLE IMPLEMENTATIONS

    The following comparison table gives a outlook:-

    Implementation Search Insert Delete
    Unordered array n n n
    Ordered Array log n n n
    Unordered List n n n
    Ordered List n n n
    Binary Search Trees (O(log n) on average) log n log n log n
    Balanced Binary Search Tree log n log n log n
    Ternary Search log n log n log n
    Hashing (O(1) on average 1 1 1
    0 comments
    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    Symbol Tables

    by nikoo28
    2 minutes read

    Since childhood, we have all used a dictionary, and many of us have used a word processor (say Microsoft WORD) which comes with a spell checker. The spell checker is also a dictionary but limited. There are many real time examples for dictionaries and few of them are:- Spelling checker The data dictionary found in database management applications Symbol tables generated by loaders, assemblers, and compilers Routing tables in networking companies (DNS Lookup) In computer science, we generally use the term symbol table rather than dictionary, when referring to the…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: Given the root pointer to a binary tree, find the sum of all its elements without using recursion. Input: Sample Tree (Pointer to node 1 is given). Output: Sum = 15 We discussed how to find the sum of all elements of a binary tree using recursion in this post. Given a binary tree, find the sum of all elements. If recursion seems tough to you , you can always go by the iterative approach and use Level Order Traversal of binary tree. While performing a level order traversal,…

    0 FacebookTwitterLinkedinWhatsappEmail

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More