Home Author
Author

nikoo28

  • Trees

    Find the left view of a binary tree.

    by nikoo28
    2 minutes read

    Question: Given the root pointer to a binary tree, find the left view of the tree. Input: Sample Tree (Pointer to node 1 is given). Output: 1, 2, 4 At a single glance of the problem, we can understand that we need to perform a level order traversal on the tree. This is similar to finding the number of levels in a tree. At the start of each level, we just print the first element. This can be done with the algorithm below:- Time Complexity:- O(n) Space Complexity:- O(n) Ideone …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Theory

    Symbol Table Implementations

    by nikoo28
    2 minutes read

    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 …

    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