Given a BST and a number. The task is to check whether the given number is equal to the sum of all the node from root leaf across any of the root to leaf paths in the given Binary Search Tree.
Approach: The idea is to traverse from root to all leaves in top-down fashion maintaining a path array to store current root to leaf path. While traversing, store data of all nodes of current path in the array path. Whenever a leaf node is reached, calculate the sum of all of the nodes on the current path using the array path and check if it is equal to the given sum.
Below is the implementation of above approach:
- Root to leaf path sum equal to a given number
- Shortest root to leaf path sum equal to a given number
- Implementing a BST where every node stores the maximum number of nodes in the path till any leaf
- Remove nodes on root to leaf paths of length < K
- Number of elements smaller than root using preorder traversal of a BST
- Largest number in BST which is less than or equal to N
- Smallest number in BST which is greater than or equal to N
- Largest number less than or equal to N in BST (Iterative Approach)
- Smallest number in BST which is greater than or equal to N ( Iterative Approach)
- Delete leaf nodes with value as x
- Delete leaf nodes with value k
- Sum of leaf nodes at minimum level
- Print all nodes that are at distance k from a leaf node
- Product of all leaf nodes of binary tree
- Remove all leaf nodes from the binary search tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.