5 Tree 1
5 Tree 1
GTU # 3130702
Non-Linear Data
Structure
Tree Part-1
Basic Notations of Graph Theory
1 2 x1 1 1
x3 x1 x3
v1 v2
x2 x2
(a) 2 3 2 3
x4 x5 x4 x5
4 4
1 2 5
(d) (f)
v1 v2
(b)
x1 1 x3 x1 1 x3
x2 x2
2 3 2 3
1 2
v1 v2 x4 x5 x4
4 x5
4
(c)
(e) (g)
Non-Linear Data Structure (Tree Part-1) 2
Basic Notations of Graph Theory
Consider diagrams shown in above figure
Every diagrams represent Graphs
Every diagram consists of a set of points which are shown by dots or
circles and are sometimes labelled V1, V2, V3… OR 1,2,3…
In every diagrams, certain pairs of such points are connected by lines or
arcs
Note that every arc start at one point and ends at another point
Isolated Node
In a graph a node which is not adjacent to any other node is called isolated node
Null Graph
A graph containing only isolated nodes are called null graph. In other words set
of edges in null graph is empty
Indegree of Node
The no of edges which have V as their terminal node is call as 1
indegree of node V.
Outdegree of Node
4
The no of edges which have V as their initial node is call as
2 3
outdegree of node V.
Total degree of Node
Sum of indegree and outdegree of node V is called its Total Degree or
Degree of vertex.
Non-Linear Data Structure (Tree Part-1) 8
Path of the Graph
Some of the path from 2 to 4
1 2 P1 = ((2,4))
P2 = ((2,3), (3,4))
P3 = ((2,1), (1,4))
P4 = ((2,3), (3,1), (1,4))
4 3
P5 = ((2,3), (3,2), (2,4))
P6 = ((2,2), (2,4))
Let G=(V, E) be a simple digraph such that the terminal node of any edge
in the sequence is the initial node of the edge, if any appearing next in the
sequence defined as path of the graph.
Length of Path
The number of edges appearing in the sequence of the path is called length of path.
Non-Linear Data Structure (Tree Part-1) 9
Graph – Concepts & Definitions
Simple Path (Edge Simple)
A path in a diagraph in which the edges are distinct is called simple path or edge
simple
Path P5, P6 are Simple Paths
Elementary Path (Node Simple)
A path in which all the nodes through which it traverses are distinct is called
elementary path
Path P1, P2, P3 & P4 are elementary Path
Path P5, P6 are Simple but not Elementary
Cycle (Circuit)
A path which originates and ends in the same node is called cycle (circuit)
E.g. C1 = ((2,2)), C2 = ((1,2),(2,1)), C3 = ((2,3), (3,1), (1,2)
Acyclic Diagraph
A simple diagraph which does not
Non-Linear Datahave
Structure any cycle is called Acyclic Diagraph.
(Tree Part-1) 10
Tree– Concepts & Definitions
Directed Tree
A directed tree is an acyclic digraph which has one node called its root with in degree
0, while all other nodes have in degree 1.
Every directed tree must have at least one node.
An isolated node is also a directed tree.
𝑽𝟎 Root Node
𝑽𝟏 𝑽𝟕
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗
Terminal or
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 Leaf Node
Non-Linear Data Structure (Tree Part-1) 11
Tree– Concepts & Definitions
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 𝑽𝟎 𝑽𝟎
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 𝑽𝟏 𝑽𝟕 𝑽𝟕 𝑽𝟏
𝑽𝟏 𝑽𝟕 𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 𝑽𝟖 𝑽𝟗 𝑽𝟐 𝑽𝟑 𝑽𝟒
𝑽𝟎 𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 𝑽 𝟏𝟎 𝑽 𝟓 𝑽 𝟔
(a) (b) (c)
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.
Non-Linear Data Structure (Tree Part-1) 13
Representation of Directed Tree
Other way to represent directed tree are
Venn Diagram
𝑽𝟎
Nesting of Parenthesis
𝑽𝟏 𝑽𝟕
Like table content of Book
Level Format
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎
𝑽𝟎
V
𝑽𝟏 𝑽𝟕 V
0
V
1 7
V V V
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 2 3 9
V V1
5 0
V
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 V 4
6
V
8
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 V7
V8
V9
V10
𝑽𝟎 1V0
2V1
𝑽𝟏 𝑽𝟕 3V2
4V5
4V6
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 3V3
3V4
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 2V7
3V8
3V9
4V10
0 1 0 1 0 1
0 0 1 0 0 1 1 0 0 1
0 1 1 0 1 1 1 0 1 0
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