Difference between Full and Complete Binary Tree
A binary tree is a type of data structure where each node can only have two offspring at most named as “left” and “right” child.
There are different types of binary tree but here we are going to discuss about the difference of Complete binary tree and Full binary tree.
Full Binary Tree:
A full binary tree is a binary tree in which all of the nodes have either 0 or 2 offspring. In other terms, a full binary tree is a binary tree in which all nodes, except the leaf nodes, have two offspring.
Let, i be the number of internal nodes
n be the total number of nodes
l be number of leaves
λ be number of levels
The number of leaves is (i + 1).
The total number of nodes is (2i + 1).
The number of internal nodes is (n – 1) / 2.
The number of leaves is (n + 1) / 2.
The total number of nodes is (2l – 1).
The number of internal nodes is (l – 1).
The number of leaves is at most (2λ – 1).
Complete Binary Tree:
When all of the levels of a binary tree are entirely filled, except for the last level, which can contain 1 or 2 children nodes and is filled from the left, it is said to be a complete binary tree.
There are 2 points that you can recognize from here,
- The leftmost side of the leaf node must always be filled first.
- It isn’t necessary for the last leaf node to have a right sibling.
Check the following examples to understand the full and complete binary tree in a better way.
- Node C has just one child therefore, it is not a Full binary tree.
- Node C also has a right child but no left child, therefore it is also not a Complete binary tree.
Hence, the binary tree shown above is neither complete nor full binary tree.
- All of the nodes have either 0 or 2 offspring, therefore, it is a Full binary tree.
- It is not a Complete binary tree because node B has no children whereas node C has children, and according to a complete binary tree, nodes should be filled from the left side.
Hence, the binary tree shown above is a Full binary tree and it is not a Complete binary tree.
- It is a complete binary tree as all the nodes are left filled.
- Node B has just one child, therefore, it is not a full binary tree.
Hence, the binary tree shown above is a Complete binary tree and it is not a Full binary tree.
- It is a Complete binary tree because all the nodes are left filled.
- All of the nodes have either 0 or 2 offspring, therefore, it is a full binary tree.
Hence, the binary tree shown above is both a complete and a full binary tree.
|S. No.||Complete Binary Tree||Full Binary Tree|
|1.||In a complete binary tree, a node in the last level can have only one child.||In a full binary tree, a node cannot have just one child.|
|2.||In a complete binary tree, the node should be filled from the left to right.||There is no order of filling nodes in a full binary tree.|
|3.||Complete binary trees are mainly used in heap-based data structures.||Full binary tree has no application as such but is also called a proper binary tree.|
|4.||A complete binary tree is also called almost complete binary tree.||A full binary tree also called proper binary tree or 2-tree.|
|5||A complete binary tree must have the entire leaves node in the exact same depth.
||In full binary tree leaf level not necessarily have to be in the same depth.