Total sum except adjacent of a given node in a Binary Tree
Given a BT and a key Node, find the total sum in BT, except those nodes which are adjacent to key Node.
- Traverse the tree using pre-order.
- If the current node is adjacent to the key then do not add it to the final sum.
- If the current node is the key then do not add its children to the final sum.
- If the key is not present then return the sum of all nodes.
Time Complexity: O(n) where n is the number of nodes in BT.
My Personal Notes arrow_drop_up
Please Login to comment...