Unit 2 Tree
Unit 2 Tree
y
Basic Terminology
Ro fig 1.1
1. Root Node : It is the top Most node of tree or the node which does not have any
am
parent node is called as root node eg. Node A
2. Parent Node : The node which is an immediate predecessor of a node is called
the parent node of that node eg. Node A,B,C,D,E
3. Child Node : The node which is the immediate successor of a node is called the
child node of that node. eg.B,C,D,E,F,G,H,I
4. Leaf Node or External Node: The nodes which do not have any child nodes are
ig
ancestor of x.
7. Sibling: Children of the same parent node are called siblings. eg. H,I
8. Level of a node: The count of edges on the path from the root node to that
node
9. Degree of the Node : Number of child nodes attached to a particular node is
called as degree of that node
10. Degree of the Tree : The node with maximum number of children is the degree
of that tree
11. Height of the Tree : The height of of the tree is maximum level of the tree
Binary Tree
The Tree with at most two children is called as binary tree referred to as the left child
and the right child.
oy
fig. 1.2
R
m
Properties of Binary Tree
a
1. At each Level ‘I’ , maximum possible nodes are 2^I eg. consider the fig 1.2
g
at level 3 max possible nodes are 2^3 = 8.
i
2. if the height of the tree is h then the maximum number of nodes that are
possible in the tree is :
(2^0 + 2^1 + 2^4 + ............. + 2^h) = 2^(h+1) - 1
N
3. Minimum Number of nodes which are possible is h+1(height+1)
4. If the no. of Node are n in the binary Tree then min possible height of the
of the tree will be h = log(n+1)-1
n = 2^(h+1) -1
n +1 = 2^(h+1)
taking log on both side we get,
log(n+1) = log2^(h+1)
log(n+1) = h+1
h = log(n+1) -1
Convert General Tree into Binary Tree
We can convert the given general tree into equivalent binary tree as follows -
i) The root of general tree becomes the root of the binary tree.
ii) Find the first child node of the node attach it as a left child to the current node in
binary tree.
iii) The right sibling can be attached as a right child of that node.
Q.1
y
-->
Ro i) The root of general tree becomes root of the binary
tree.
am
ii) The first left child becomes left child of the tree.
iii) The right sibling is attached as right child.
ig
Q.2
N
-->
oy
R
am
Q.4
ig
N