DS Lecture16
DS Lecture16
A tree is a connected graph that does not contain any nontrivial circuit. (i.e.,
it is circuit-free)
A trivial circuit is one that consists of a single vertex.
TREE
TREE
1
TREE
EXAMPLES OF NON TREES
1. TRIVIAL TREE
A graph that consists of a single vertex is called a trivial
tree or degenerate tree.
2. EMPTY TREE
A tree that does not have any vertices or edges is called an
empty tree.
3. FOREST
A graph is called a forest if, and only if, it is circuit-free.
Hence, the connected components of a forest are trees.
2
A forest
In the above example of forest it has only two trees in it and not a very thick
forest.
PROPERTIES OF TREES
and
4
EXERCISE
(b)
(c)
EXERCISE
Draw a graph with six vertices, five edges that is not a tree.
SOLUTION
Two such graphs are:
v5
v3
v7
v6 v8
ROOTED TREE
A rooted tree is a tree in which one vertex is distinguished from the others
and is called the root.
The level of a vertex is the number of edges along the unique path between
it and the root.
The height of a rooted tree is the maximum level to any vertex of the tree.
The children of any internal vertex v are all those vertices that are adjacent
to v and are one level farther away from the root than v.
If w is a child of v, then v is called the parent of w.
Two vertices that are both children of the same parent are called siblings.
Given vertices v and w, if v lies on the unique path between w and the6 root,
then v is an ancestor of w and w is a descendant of v.
Examples
We redraw the tree as and see what are the relations, in order to redraw the
graph we choose a vertex as root and draw the graph from upward to
downward as given below.
root level 0
u
level 1
v w level 2
level 3
level 4
v is a child of u
Vertices in enclosed region
u is the parent of v
are descendants of u, which
v and w are siblings
is an ancestor of each
height = 4
7
EXERCISE
v1 v2
Level 1
v3 v5 v6
Level 2 v4 v12
Level 3 v10
v7 v8 v9 v11
v17
Level 4
v13 v14 v15 v16
Level 5
v18 v19
(a) What is the level of v8?
From above figure it is clear that the level of v 8 is 3.
(b) What is the level of v0?
Clearly its level is 0.
A binary tree is a rooted tree in which every internal vertex has at most two
children.
Every child in a binary tree is designated either a left child or a right child.
A full binary tree is a binary tree in which each internal vertex has exactly
two children.
EXAMPLE
root
u w
v
x
THEOREMS
b c
d e f g 10
EXERCISE
Draw a binary tree with height 3 and having seven terminal vertices.
SOLUTION
a
c b
d f g
e
h i j k l m n
/
/
a b
a
+
c
d
Note that the internal vertices are arithmetic operators, the terminal vertices
are variables and the operator at each vertex acts on its left and right sub
trees in left-right order.
12