Find maximum (or minimum) in Binary Tree | GeeksforGeeks

preview_player
Показать описание


Read More: Find maximum (or minimum) in Binary Tree | GeeksforGeeks

This video is contributed by Anant Patni

Please Like, Comment and Share the Video among your friends.

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

Your binary search tree is incorrect. Node 5 is in the wrong place...

5 > 1, therefore go right.
5 > 3, therefore go right.
Reached NULL pointer, so insert node 5.

Not quite sure how you ended up with node 5 where you have it displayed in your diagram....

gollumei
Автор

In case of findMin logic, we just need to find the min of left subtree and min of right subtree.In the video it is just wrongly mentioned in the englist letters(I think it is just a copy paste mistake from the findMax :) )but the programme is correct only

tejeswarsahu
Автор

Sadly this can never work. Just imagine a parent node with value of 5 and one single node to the left with 2. Its already not working anymore for the maximum. In root node res=5 left=2 right=INT_MIN---> is left=2>right=INTMIN? YES! res = return res= 2. Sadly its really hard to find an actually working algorithm for even basic things like this....

Laurenan
Автор

If you switch the node 4 and 5.. you will get max as 4 in the left subtree which is not correct. Please check..!

mayankbatra
Автор

max(res, max(lres, rres)); this is less confusing

suhaasbadada