Given a binary tree, write a function that returns true if the tree satisfies below property.
For every node, data value must be equal to sum of data values in left and right children. Consider data value as 0 for NULL children. Below tree is an example
Traverse the given binary tree. For each node check (recursively) if the node and both its children satisfy the Children Sum Property, if so then return true else return false.
The given tree satisfies the children sum property
Time Complexity: O(n), we are doing a complete traversal of the tree.
As an exercise, extend the above question for an n-ary tree.
This question was asked by Shekhar.
Please write comments if you find any bug in the above algorithm or a better way to solve the same problem.
- Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
- Maximum parent children sum in Binary tree
- Convert a given Binary tree to a tree that holds Logical AND property
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Check whether a binary tree is a full binary tree or not
- Check if a binary tree is subtree of another binary tree | Set 1
- Check if a binary tree is subtree of another binary tree | Set 2
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Node having maximum sum of immediate children and itself in n-ary tree
- Number of children of given node in n-ary Tree
- Find root of the tree where children id sum for every node is given
- Number of full binary trees such that each node is product of its children
- A program to check if a binary tree is BST or not