A tree whose elements have at most 2 children is called a binary tree.
The three common types of Binary Trees.
- Full Binary Tree
- Complete Binary Tree
- Perfect Binary Tree
Full Binary Tree
A Binary Tree is a full binary tree if every node has 0 or 2 children. The nodes of full binary tree have two children except leaf nodes.
Complete Binary Tree
A Binary Tree is a complete binary tree if all levels completely filled except last level and nodes in last level are as left as possible.
Max no of nodes at level i = 2iPerfect Binary Tree
A Binary Tree is a perfect binary tree in which all internal nodes have two children and all leaf nodes are at the same depth or same level.
Maximum no of nodes in a binary tree with height h = 2h+1 – 1
Height of complete binary tree h = floor (log2n)
Balanced Binary Tree is a tree in which height of the left and the right sub trees of every node may differ by at most 1.
The complete binary trees can be represented in memory with the use of an array A. The nodes shall be labelled from top to bottom and left to right order.
Left child of A[i] is at position A[2i]
Right child of A[i] is at position A[2i + 1]
Parent of A[i] is at A[i/2]