A full binary tree is defined as a binary tree in which all nodes have either zero or two child nodes. Conversely, there is no node in a full binary tree, which has one child node. More information about full binary trees can be found here.
For Example :
To check whether a binary tree is a full binary tree we need to test the following cases:-
1) If a binary tree node is NULL then it is a full binary tree.
2) If a binary tree node does have empty left and right sub-trees, then it is a full binary tree by definition.
3) If a binary tree node has left and right sub-trees, then it is a part of a full binary tree by definition. In this case recursively check if the left and right sub-trees are also binary trees themselves.
4) In all other combinations of right and left sub-trees, the binary tree is not a full binary tree.
Following is the implementation for checking if a binary tree is a full binary tree.
The Binary Tree is full
Time complexity of the above code is O(n) where n is number of nodes in given binary tree.
This article is contributed by Gaurav Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
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.
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Check whether a given binary tree is skewed binary tree or not?
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Check whether a given Binary Tree is Complete or not | Set 1 (Iterative Solution)
- Check whether a given binary tree is perfect or not
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Check whether BST contains Dead End or not
- Check whether a node is leaf node or not for multiple queries
- Check whether nodes of Binary Tree form Arithmetic, Geometric or Harmonic Progression
- Check whether every node of binary tree has a value K on itself or its any immediate neighbours
- Check if a Binary Tree is an Even-Odd Tree or not
- Calculate depth of a full Binary tree from Preorder
- Print all full nodes in a Binary Tree
- Count full nodes in a Binary tree (Iterative and Recursive)
- Construct Full Binary Tree from given preorder and postorder traversals
- A program to check if a binary tree is BST or not
- Check if an array represents Inorder of Binary Search tree or not
- Check if a Binary Tree (not BST) has duplicate values
- Check if a binary tree is sorted level-wise or not
- Check if Inorder traversal of a Binary Tree is palindrome or not