Regarding bottom view of a binary tree using unordered_map

lets say we have a binary tree as :
20
/
8 22
/ \ /
5 3 4 25
/ \
10 14

in this tree 3 , 4 are at same level how do we know which one will be in bottom view ? if i use this unordered map method as in this video ??

hi @Ramitgoel

the node which is discover later will be consider in bottom view (i.e right one 4)

first we write hashmap[0]=20
then again hashmap[0]=3
then again hashmap[0]=4
it will overwrite and at end we have correct ans

That would depend on the code as if
i write left part is discovered before right and vice versa then your ans would be changed .
@asaurabh_26

yes you have to use preorder travesal
first iterate in left part

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.