• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 02, 2022 |360 Views

Vertical width of Binary tree | Set 2

Description
Discussion

In this Approach, we use the approach for printing vertical View of binary tree. Store the horizontal distances in a set and return 1 + highest horizontal distance – lowest horizontal distance. 1 is added to consider horizontal distance 0 as well. While going left, do hd – 1 and for right do hd + 1. We insert all possible distances in a hash table and finally return size of the hash table.

Input : 


            7
          /  \
         6    5
        / \  / \
       4   3 2  1 


Output : 5

Vertical width of Binary tree  Set 2: https://www.geeksforgeeks.org/vertical-width-binary-tree-set-2/