Skip to content

Files

Latest commit

 

History

History

assignments

Horizontal distance between two nodes in binary tree

What is this?

  • This is program to find horizontal distance between first and last node at same level in binary tree.
  • It must calculate the nodes which are not present.
  • The solution has two variants,
    • Solution 1 need to be passed root node of the tree. It will tell distance between all the nodes at same level
    • Solution 2 need to be passed two nodes along with root node of the tree. It return the distance between specified nodes
  • Python 3.6+ is supported

Includes

  • binary_tree.py has binary tree blueprint
  • main.py is driver code for solutions.

How to run

  • run the main.py to get the output
  • Solution 2 can be tested with any two nodes in same level (check last line)

Constraints

  • Code is optimized for python 3.6+ only
  • Code is cross platform (Windows/UNIX)
  • No need to create env. no third party dependencies used