Bottom view of binary tree

all test cases are not passing

@ayu2321 hey your logic for bottom view is not upto mark,see this logic:
The following are steps to print Bottom View of Binary Tree.

  1. We put tree nodes in a queue for the level order traversal.
  2. Start with the horizontal distance(hd) 0 of the root node, keep on adding left child to queue along with the horizontal distance as hd-1 and right child as hd+1.
  3. Also, use a TreeMap which stores key value pair sorted on key.
  4. Every time, we encounter a new horizontal distance or an existing horizontal distance put the node data for the horizontal distance as key. For the first time it will add to the map, next time it will replace the value. This will make sure that the bottom most element for that horizontal distance is present in the map and if you see the tree from beneath that you will see that element.

u have shared the algorithm of gfg but i am not understanding it

@ayu2321 ok ,I will explain,you have to find the bottom most nodes means the nodes which come at last for particular horizontal distance (hd).The hd of root is 0 and uske left ka 0-1 and right ka 0+1 ,aise hi sab node ka hota hai,to hm isme level order traverse krrhe hai and map lerhe hai hd ke coresponding nbode store krne ke lie ,suppose ek hd ke lie ek node ayi timne use us hd ke coresponding map me dal dia and us hd ki ek aur node ayi to tumhe woh wali leni hai kyunki tumne last node leni hai tavhi bottom view bnega.Hope you get it.

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.

@ayu2321 if your doubt is cleared please mark it as resolved

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.