5 Tree 1
5 Tree 1
GTU # 3130702
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 𝑽𝟎 𝑽𝟎
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 𝑽𝟏 𝑽𝟕 𝑽𝟕 𝑽𝟏
𝑽𝟏 𝑽𝟕 𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 𝑽𝟖 𝑽𝟗 𝑽𝟐 𝑽𝟑 𝑽𝟒
𝑽𝟎 𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 𝑽 𝟏𝟎 𝑽 𝟓 𝑽 𝟔
(a) (b) (c)
Level of Node
The level of any node is the length of its path from the root.
Ordered Tree
In a directed tree an ordering of the nodes at each level is prescribed then such a tree is called ordered tree.
The diagrams (b) and (c) represents same directed tree but different ordered tree.
Forest
If we delete the root and its edges connecting the nodes at level 1, we obtain a set of disjoint tree. A set of
disjoint tree is a forest.
𝑽𝟎 Root Node
𝑽𝟏 𝑽𝟕
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗
Terminal or
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 Leaf Node
Non-Linear Data Structure (Tree Part-1) 5
Representation of Directed Tree
Other way to represent directed tree are
Venn Diagram
𝑽𝟎
Nesting of Parenthesis
𝑽𝟏 𝑽𝟕
Like table content of Book
Level Format
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎
𝑽𝟎
V0
𝑽𝟏 𝑽𝟕 V1 V7
V2 V9
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 V3
V5 V10
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 V6
V4
V8
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 V7
V8
V9
V10
(V0 (V1 (V2 (V5) (V6) ) (V3) (V4) ) (V7 (V8) (V9 (V10) ) ) )
Nesting of Parenthesis
Non-Linear Data Structure (Tree Part-1) 8
Level Format
𝑽𝟎 1 V0
2 V1
𝑽𝟏 𝑽𝟕 3 V2
4 V5
4 V6
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 3 V3
3 V4
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 2 V7
3 V8
3 V9
4 V10
Binary Tree
A binary tree is either empty or consists of a node called the root together with two binary trees called the left
subtree and the right subtree
If in a directed tree the out degree of every node is less than or equal to 2 then tree is called binary tree.
0 1 0 1 0 1
00 01 11 00 01 11 11 00 01 10
b f b f
c f
g
d
c d g j k c d g j k
h j
e
e h i e h i i k
a g
a
b c
h i
b g
d e f
j k l
d c h
a g
e j i
b c h i
f k l
d e f j k l