can someone pls explain the output of this ques
Replace with Sum of greater nodes1
The original tree looks like
50 / \ 30 70 / \ / \ 20 40 60 80
We are supposed to replace the elements by the sum of elements larger than it.
80 being the largest element remains unaffected .
70 being the second largest element gets updated to 150 (70+80)
60 becomes 210 (60 + 70 + 80)
50 becomes 260 (50 + 60 + 70 + 80)
40 becomes 300 (40 + 50 + 60 + 70 + 80)
30 becomes 330 (30 + 40 + 50 + 60 + 70 + 80)
20 becomes 350 (20 + 30 + 40 + 50 + 60 + 70 + 80)
The new tree looks like
260 / \ 330 150 / \ / \ 350 300 210 80
The Pre-Order traversal (Root->Left->Right) looks like :
260 330 350 300 150 210 80.
Hope this helped.
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.