Check whether a binary tree is a full binary tree or not
Write a program to check if a given binary tree is a full binary tree or not.
A binary tree is a full binary tree if all its nodes have either both children or no children. In other words, if any of its node has only one child then it is not a full binary tree. Both of the following trees are full binary trees.
Following two trees are not full binary trees.
In above tree, node 3 violates the constraint.
In above tree, node 4 violates the constraint.
Video coming soon!
Subscribe for more updates
Preparing for interviews? IDeserve team is here to help.
Create your profile
Create your profile, and here is what you will get:
1: Interview practice platform.
2: Once you are ready to take the interview, IDeserve team will help you get connected to the best job opportunities.
3: Personalized mentorship from IDeserve team once your interview process has started.
Creation of profile shouldn't take more than 2 minutes.
A simple level-order traversal is sufficient to solve this problem. While traversing the tree using level order traversal, if we visit any node with only one child, we return false.
Please checkout code snippet and algorithm visualization section for details of the algorithm.
Support us by whitelisting IDeserve in your ad-blocker.