Posted on by Kalkicode
Code Binary Tree

Print nodes in top view of binary tree

Printing of the top view of given tree that is one of the challenging problem of tree. We can solve this problem in many ways. Let see the possibility to print top view of tree.

First possibility : Get the head node of tree and print that element. After that if head node left subtree are exist then print top element of that nodes from top to bottom. Similar way if exist root node right subtree then print that elements form bottom to top.

Print Top view of Tree

In this example {1} is root element and {2 4 7} is left sub tree top view elements and {3 6 10} is top elements of right subtree. We can solve this problem by using recursion.

Here given code implementation process.


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment