Address
304 North Cardinal St.
Dorchester Center, MA 02124

Work Hours
Monday to Friday: 7AM - 7PM
Weekend: 10AM - 5PM

This article assumes that you have some basic knowledge of trees that’s why it is made for experienced professionals.

Just YOU and TREES here. Enjoy…

Quick Recap – A tree data structure is a hierarchical data structure consisting of nodes connected by edges, where each node has zero or more child nodes, with one designated as the root node. Trees are widely used for representing hierarchical relationships and organizing data & searching efficiently.

Points to Remember –

  • Tree has directed edges, has one way links between nodes.
  • There are no cycles in trees.
  • Binary tree can have at most 2 Childs.
  • There can only be one way to get to a certain node.

Applications –

  • Files and folders on computer (implemented with trees, NOT binary trees as they can have only 2 children)
  • Word auto completion
  • Compiler parse tree
  • for example – a = (b+c) * d, following is the tree for the expression
Compiler Parse Tree

Tree Implementation(in Python) :

Here’s a Challenge for YOU. if you can make following functions in a 2 hour then you can consider yourself knowledgable in Tree Data Structure.

  1. Insert() – To insert an element in a Binary Search Tree.
  2. LookUp(value) – To check if a value is present in Tree or not.
  3. MinValue() – To fetch the minimum value from the Tree.
  4. MaxValue() – To fetch the maximum value from the Tree.
  5. PrintTree() – Prints the whole Tree.
  6. NumberOfNodes() – To find how many nodes are there in Tree.
  7. HeightOfTree() – To find the height of Tree (max root-to-leaf count).
  8. DepthOfNode() – To find the depth of a Node(count of nodes above that node).
  9. PostOrderTraversal() – Print Left subtree then right subtree and then node.
  10. PreOrderTraversal() – Print node then Left subtree then right subtree.
  11. PrintPaths() – Prints all the path(root-to-leaf)
  12. MirrorTree() – All left node’s value swap with right node’s value
  13. BSTCheck() – check if a tree is Binary search tree(left < right)
  14. TotalTrees() – Count total number of trees in a tree(root.left and root.right should not be null)

And That’s it. Now you need to invest 3 hours in above questions.