Add all greater values to every node in a given BST - GeeksforGeeks
Add all greater values to every node in a given BST Given a Binary Search Tree (BST), modify it so that all greater values in the given BST are added to every node. For example, consider the following BST. 50 / \ 30 70 / \ / \ 20 40 60 80 The above tree should be modified to following 260 / \ 330 150 / \ / \ 350 300 210 80 We strongly recommend you to minimize the browser and try this yourself first. A simple method for solving this is to find sum of all greater values for every node. This method would take O(n^2) time. We can do it using a single traversal. The idea is to use following BST property. If we do reverse Inorder traversal of BST, we get all nodes in decreasing order. We do reverse Inorder traversal and keep track of the sum of all nodes visited so far, we add this sum to every node. // C program to add all greater values in every node of BST #includeRead full article from Add all greater values to every node in a given BST - GeeksforGeeks