Full Binary Tree: Types, Properties, and Program in C

Full Binary Tree: Types, Properties, and Program in C

3 mins read358 Views Comment
Updated on Mar 14, 2024 13:48 IST

A full binary tree or proper binary tree in which all the nodes have zero or two children. In this article, we will briefly discuss all full binary tree, its properties, example, and finally a c program to check whether the given binary tree is a full binary tree or not.

2022_12_MicrosoftTeams-image-101-1.jpg

Binary tree in data structure has numerous types, and one of its most important types is the full binary tree. A binary tree has either zero, one, or two child nodes but not more than two. The full binary tree is a type of binary tree; other types of binary trees include:

  • A Complete binary tree.
  • Balanced binary tree (AVL tree, Red black tree, etc.).
  • Skewed binary tree (left-skewed tree, right-skewed tree).
  • Degenerate binary tree. 

A full binary tree is such a binary tree whose all nodes have either zero or two child, meaning a tree with one child node will not be considered a full binary tree. In this article, we will learn the full binary tree, its properties, and the algorithm.

Recommended online courses

Best-suited IT & Software courses for you

Learn IT & Software with these high-rated online courses

β‚Ή18 K
1 year
β‚Ή39.88 K
2 years
– / –
2 years
β‚Ή18 K
1 year
– / –
2 years
β‚Ή10.8 K
6 months
β‚Ή19.5 K
12 months
β‚Ή16.25 K
4 weeks
name
ICACertificate
– / –
80 hours

What is Full Binary Tree?

A full binary tree is a full-fledged binary tree with few conditions, like a full binary tree, which should have either zero or two children only; if any node has one child node, then it would not be considered a full binary tree. A full binary tree is also known as a Proper binary tree. 

Some important terms related to the Full binary tree:

  • Root node: The root node does not have any edge coming towards it or any parent node.
  • Child node: The node having some incoming edge.
  • Internal/External node: non-leaf nodes are internal nodes, and leaf nodes are external nodes. 
  • Sibling: Two or more nodes having the same parent node.
  • Height: Total number of edges from that node to the root node.
  • Level: Number of nodes in the path from that node to the root node.  
  • Degree: A degree of any node is calculated by counting the number of child nodes of that particular node.  

Also Read: Types of Binary Tree

Also Read: Tree Traversal in Data Structure

Properties of Full Binary Tree

Before discussing the properties of the full binary tree, let’s understand the notations of some basic terms; in this article, we will be using 

i for the total number of internal nodes. 

n for the total number of nodes.

l for a number of leaves.

h for the number of levels.

The properties of the full binary tree are as follows:

  1. The total number of nodes is 2i +1 or 2l -1.
  2. The total number of internal nodes is (n-1)/2 or l – 1.
  3. A full binary tree has i +1 or 2l – 1 number of total leaves.
  4. A binary tree can have at most 2h -1. 

Also Read: All about Balanced Binary Tree

Also Read: Splitting in Decision Tree

Example of Binary Tree

1

2022_12_image-60.jpg

2

2022_12_image-61.jpg

The above two diagrams are examples of the full binary tree.

Program for Full Binary Tree

Here is the code to check whether the given binary tree is a Full binary tree or not.

 
int main() {
struct Node *root = NULL;
root = createNewNode(25);
root β†’ left = createNewNode(15);
root β†’ right = createNewNode(30);
root β†’ left β†’left = createNewNode(10);
root β†’ left β†’right = createNewNode(20);
root β†’ left β†’ left β†’ left = createNewNode(6);
root β†’ left β†’ left β†’ right = createNewNode(12);
root β†’ right β†’left = createNewNode(28);
root β†’ right β†’right = createNewNode(35);
if (isFullBinaryTree(root))
printf("The given tree is a full binary tree\n");
else
printf("The given tree is not a full binary tree\n");
}
#include
\n \n <stdio.h>\n \n
\n \n
\n \n
struct Node {\n \n
int item;\n \n
struct Node *left, *right;\n \n
};\n \n
\n \n
struct Node *createNewNode(char a) {\n \n
struct Node *node = (struct Node *)malloc(sizeof(struct Node));\n \n
node β†’ item = a;\n \n
node β†’ right = node β†’ left = NULL;\n \n
return node;\n \n
}\n \n
\n \n
bool isFullBinaryTree(struct Node *root) {\n \n
if (root == NULL)\n \n
return true;\n \n
\n \n
\n \n
if (root β†’ left == NULL && root β†’ right == NULL)\n \n
return true;\n \n
\n \n
if ((root β†’ left) && (root β†’ right))\n \n
return (isFullBinaryTree(root β†’ left) && isFullBinaryTree(root β†’ right));\n \n
\n \n
return false;\n \n
}\n \n
\n \n
\n \n </stdio.h>
Copy code

Also Read: Complete Binary Tree

Also Read: Red Black Tree

Conclusion

In this article, we have briefly discussed full binary tree, its types, properties, and program to check whether the given tree is a full binary tree or not.

Hope you will like the article.

Contributed By: Kanika Joshi

About the Author

This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio