Properties and Types of Binary Tree
Properties and Types of Binary Tree
As we know that,
n = 2h+1 -1
n+1 = 2h+1
log2(n+1) = log2(2h+1)
log2(n+1) = h+1
h = log2(n+1) - 1
As we know that,
n = h+1
h= n-1
Types of Binary Tree
o The full binary tree is also known as a strict binary tree. The tree can only
be considered as the full binary tree if each node must contain either 0 or 2
children. The full binary tree can also be defined as the tree in which each
node must contain 2 children except the leaf nodes.
In the above tree, we can observe that each node is either containing zero or two
children; therefore, it is a Full Binary tree.
o The number of leaf nodes is equal to the number of internal nodes plus 1.
In the above example, the number of internal nodes is 5; therefore, the
number of leaf nodes is equal to 6.
o The maximum number of nodes is the same as the number of nodes in the
binary tree, i.e., 2h+1 -1.
o The minimum number of nodes in the full binary tree is 2*h-1.
o The minimum height of the full binary tree is log2(n+1) - 1.
o The maximum height of the full binary tree can be computed as:
n= 2*h - 1
n+1 = 2*h
h = n+1/2
The complete binary tree is a tree in which all the nodes are completely filled
except the last level. In the last level, all the nodes must be as left as possible. In
a complete binary tree, the nodes should be added from the left.
The above tree is a complete binary tree because all the nodes are completely
filled, and all the nodes in the last level are added at the left first.
A tree is a perfect binary tree if all the internal nodes have 2 children, and all the
leaf nodes are at the same level.
The below tree is not a perfect binary tree because all the leaf nodes are not at the
same level.
Degenerate Binary Tree
The degenerate binary tree is a tree in which all the internal nodes have only one
child.
The balanced binary tree is a tree in which both the left and right trees differ by
atmost 1. For example, AVL and Red-Black trees are balanced binary tree.
The above tree is not a balanced binary tree because the difference between the
left subtree and the right subtree is greater than 1.
Almost Complete Binary Tree-
An almost complete binary tree is a binary tree that satisfies the following 2
properties-
• Allthe levels are completely filled except possibly the last level.
• The last level must be strictly filled from left to right.
Example-
Here,
• Firstbinary tree is not an almost complete binary tree.
• This is because the last level is not filled from left to right.