Bottom view of tree

why five is not considered the bottom of the the tree?? how to consider any node to be included in bottom view

@shampblocks hey ,the reason why 5 is not in output is because 1 5 6 are on same level as viewed from bottom , and so 6 is the last node to enter in that level , hence 6 is viewed .
The tree is basically like -
_______1
___2 _______3
_4 ____5 ___
______6 _______
Hope you get it :slight_smile:

How to get position of a particular node??

@shampblocks A node x is there in output if x is the bottommost node at its horizontal distance. Horizontal distance of left child of a node x is equal to horizontal distance of x minus 1, and that of right child is horizontal distance of x plus 1.So jo same hoga uska lowest wala lena hai jaise upr btaya mene.

But bhaiya it’s our assumption that when the horizontal distance is same we have to take the right one as lower one??

@shampblocks nhi bro hm har node ka horizontal distance nikal lenge by giving root hd as 0 and than root->left ka 0-1 and right ka 0+1 asi hi sabka ab hme woh woh nodes print krni hai jo particular hd ki last node ho.

But if we starting from. Root left then right then last node will be in right way for same hd but if we start from. Right root then left then left will be last jode in same hd??

@shampblocks bro take a tree manually and write hd of each node,and jin jin ka same hd hai woh dekho ki sabse last level pr us hd ki node kaun si hai,you will get it,I can;t explain in written here.Draw tree and finnd it pls.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.