Menu
Back to Explore Page
Given a Binary Tree. Check whether the Binary tree is a full binary tree or not.
What is a Binary Tree?
A binary tree is a tree data structure with a maximum of 2 children per node. We commonly refer to them as the left and right child as each element in a binary tree may only have two children.
What is a Full Binary Tree?
A full binary tree is a binary tree with either zero or two child nodes for each node.
Example 1:
Input: 1 / \ 2 3 / \ 4 5 Output: 1 Explanation: Every node except leaf node has two children so it is a full tree.
Example 2:
Input: 1 / \ 2 3 / 4 Output: 0 Explanation: Node 2 has only one child so this is not a full tree.
Your Task:
You don't need to read input or print anything. Your task is to complete the function isFullTree() which takes the root node of the tree as input and returns True if the given Binary Tree is full. Else, it returns False.
(The driver code will print 1 if the returned value is true, otherwise 0).
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1<=Number of nodes<=1000