Skip to main content

Posts

Showing posts with the label The Crazy Programmer Bottom View of Binary Tree in Java Bottom View of Binary Tree in Java The Crazy Programmer

Bottom View of Binary Tree in Java Vijay Sinha The Crazy Programmer

In this article, we see how to print the bottom view of Binary Tree. We discuss our approach to solve this problem and analyze the time and space complexities. It is recommended to first learn Top View Of Binary Tree before proceeding with this problem. A lot of the implementation is based on the Top View Approach. By Bottom View of Binary Tree, we mean the nodes visible when the tree is viewed from the bottom or from the leaves. A node is present in our bottom view it is the last node or the bottom-most node at it’s respective horizontal distance. We calculate the horizontal distance of each node as follows: We fix the Horizontal Distance of Root of tree=0. Then, Horizontal Distance of Left Child=Horizontal Distance of it’s Parent Node – 1. Horizontal Distance of Right Child=Horizontal Distance of it’s Parent Node + 1. Now let us look into an example. Consider this binary tree:   The Bottom View of this tree will be : 2 5 6 7. Explanation The nodes highlighted in the fi