Unit - 3 Tree Concepts
Unit - 3 Tree Concepts
Minister
s
County
Metropolitan
Council
police
Rural County Borough
District
Council
Council
More Trees Examples
• Unix / Windows file structure
Definition of Tree
• The ancestors of a node are all the nodes along the path
from the root to the node
• 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.
• n+1 = 2*h
• h = n+1/2
Complete Binary Tree
• A binary tree is called complete binary tree if each node has
exactly two children and all leaf nodes need not to be at same
level or depth.
• Total number of nodes in complete binary tree are 2 h+1 – 1
where h is a height of the tree.
• The number of leaf nodes n in a complete binary tree: n = 2 h
where n is total number of leaf nodes and h is the height of the
binary tree
• 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.
Note: All the perfect binary trees are the
complete binary trees as well as the full
binary tree, but vice versa is not true, i.e.,
all complete binary trees and full binary
trees are the perfect binary trees.
Degenerate Binary Tree
The degenerate binary tree is a tree in which all the internal nodes
have only one children.