Given a BST and a key Node, find the total sum in BST, except those Node which are adjacent to key Node.
1:-First find the total sum of BST
2:-Search the key Node and trace its parent Node.
3:-If the key Node is present then, subtract the sum of its adjacent Node from total sum
4:-If key is not present in BST then return -1.
Time Complexity : O(n) + O(h) where n is number of nodes in BST and h is height of BST. We can write time complexity as O(n).
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find k-th smallest element in BST (Order Statistics in BST)
- Two nodes of a BST are swapped, correct the BST
- K'th Largest Element in BST when modification to BST is not allowed
- Convert a normal BST to Balanced BST
- Two nodes of a BST are swapped, correct the BST | Set-2
- Sum of cousin nodes of a given node in a BST
- Add all greater values to every node in a given BST
- Find a pair with given sum in a Balanced BST
- Find a pair with given sum in BST
- Root to leaf path sum equal to a given number in BST
- Check if a triplet with given sum exists in BST
- Pair with a given sum in BST | Set 2
- Triplet with a given sum in BST | Set 2
- Check if each internal node of a BST has exactly one child
- Implementing a BST where every node stores the maximum number of nodes in the path till any leaf
- Convert a BST to a Binary Tree such that sum of all greater keys is added to every key
- Transform a BST to greater sum tree
- Sum of k smallest elements in BST
- BST to a Tree with sum of all smaller keys
- Sum of k largest elements in BST
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.