-
I'm very curious on this and I would appreciate it if someone could answer my question on this subject, as I don't have the most experience, and I know there's programmers out there who could assist me on my question. thank you if you do decide to help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Approach: The idea is to traverse the tree once and get the minimum and maximum horizontal distance with respect to root. For the tree shown above, minimum distance is -2 (for node with value 4) and maximum distance is 3 (For node with value 9). |
Beta Was this translation helpful? Give feedback.
Approach:
The idea is to traverse the tree once and get the minimum and maximum horizontal distance with respect to root. For the tree shown above, minimum distance is -2 (for node with value 4) and maximum distance is 3 (For node with value 9).
Once we have maximum and minimum distances from root, we iterate for each vertical line at distance minimum to maximum from root, and for each vertical line traverse the tree and print the nodes which lie on that vertical line.