Be the first user to complete this post
|
Add to List |
Print the Bottom View of the Binary Tree.
Objective: - Given a binary tree, print it in Bottom View of it.
What is Bottom View: Bottom view means when you look the tree from the bottom the nodes you will see will be called the bottom view of the tree. See the example below.

as you can see in the example above,8, 4, 9, 5, 3, 7 is the bottom view of the given binary tree.
Approach:
This Approach is quite similar to the - Print the Binary Tree in Vertical Order Path.
and Print The Top View of a Binary Tree. Just modified the code so that it will print only the last element it will encounter in the vertical order. That will be the bottom view.
How will you know that you are visiting the last node at every level(Vertically)?
- Take a variable called level, whenever you go left, do level++ AND whenever you go right do level–.
- With step above we have separated out the levels vertically.

Code:
Output:
: 4 6 5 7 8
Also Read: