Graph Theory
Graph Theory
Graph Theory
Properties of Trees
Trees and
6.13
Atree is
connected graph without any cycle. For example, the graphs in Fig. 6.37 are
a
two, three, four and five vertices. Atree must be a simple graph because self-
with one,
trees
parallel edges,
both form cycles. Agraph is called acyclic if it contains no cycles.
and
treeis
Thus a
Theorem 6.27 Every nontrivial tree contains at least two pendant vertices.
Proof. Suppose that Tis atree with n vertices, and let d, d,., d, denote the degrees of
its vertices and are
ordered so that di Sdz S...s d,. Since Tis a nontrivial connected tree,
G r a p hT h e o r y
269
21,for each i =1, 2,., n. If T contains only one pendant vertex then d, l and d, 22
,
therefore
Thus
3..,#.
forie2
contradicts
the inequality (1).
which
Tcontains at least two
pendant vertices.
Hence
Distance
between two vertices in a Graph
graph Gthe distance d(u, v) between two of its distinct vertices uand v, is
In a connected
the. shortest u-v path.
length of
the of the u -v paths between the vertices uand vin the following
example, some
For
ucvfusho, ucvyevsgVsh, ucvfosjv,lu, ucvevsgvgjv,lu, ubvdugevfu_hv. But the
graph are which is of length 3. Hence d(u, v) = 3.
ucvsfushu,
shortestpath is pair of vertices, so it becomes much
t atree, there is precisely one path between any
vertices.
distance between any two of
its
oasier to determine the
k m V10
a
p
e Ve
b
h
V Vg Vg
V d
three
Fig. 6.38 : Distance between u and v is
Eccentricity cf a vertex
eccentricity E(v) of avertex in
v a graph G=(V, E)is the distance of the farthest
The
vertex v, from vin G. Thus
E(v) = max (d(u,v) lv;e V}.
Center of aGraph A
called the center of G.
The vertex in the graph Ghaving minimum eccentricity is center. However,
graph may have many centers. For example, in a cycle graph every vertex is a
atree has one or two centers
only.
Theorem 6.28 Every tree has either one or two centers.
of T. If Thas two
Proof, Let T"be atree. If T has only one vertex, then it is the center vertices. Since
vertices, then both are the centers of T. Now Suppose that T has more than two
the maximum occurs only when
v; is a
distance other vertex v, the
pendant vertex and from a given vertex vto any
tree has at least two pendant vertices, therefore,
if we delete all
every
Elements of
270 Discrete
Mathematies
pendant vertices from the tree T, the resulting graph T; is still a tree in which the eccentricities
vertices that are the
of all the vertices are reduced by one. Therefore, all the centers of T.
remain the centers in T1. Again we delete all the perndant vertices in TË to get another still
that has same centers as that of T1. We continue the process of deletion of pendant tree T
vertices
we are left with either one vertex (which is the center of T) or an edge (whose end
until
the centers of T). This completes the proof.
vertices are
The deletion process of pendant vertices in a tree T is shown in the following figure.
The numbers associated with the vertices denote their eccentricities.
C(5) h(4)
O(5)
d(4) e(3) f(3) m(4) d(3) e(2) f(2) m(3)
T2
e(1) f(1)
two centers e and fofG
T3
Fig. 6.39: Tree centers
Radius and Diamneter of a Tree
In a tree, the eccentricity of the center (or centers) (i.e., the distance from the center o
the tree to the farthest vertex) is said to be the radius of the tree.
The diameter of a tree Tisdefined as the length of the longest path in T.
The radius of the tree Tin Fig. 6.39 is thus 4 and the diameter in 7.
Rooted Tree
of a
In many trees a particular vertex of the tree is designated as the root. Once a root
tree is specified, the direction of each edge can be assigned. Since there is only one path from
the root to each vertex of the tree, we direct each vertex away from the root. Thus a tree
together with its root intends a directed graph called the rooted tree. from all the
Thus in a rooted tree one root is distinguished
particular vertex called the the tree is
other vertices. To differentiate the from nonrooted trees, the root of
rooted tree
marked distinctly by enclosing a small triangle.
271
Graph Theory
b
k
=p-1.
In abinary tree a vertex v is said to be at a level l, if vis at a distance l, from
the root of
the tree. The root of the binary tree is said to be at level
zero. There can be only one vertex at
level zero (.e., the root), at most 2', i.e., two vertices at level one, at
most 22, i.e., four vertices
at level two and so on. Thus the maximum number of
with n vertices is
vertices possible in a k-level binary ree
20 + 2' +...+ 2* 2n ..(1)
Ine max1mum level may of any vertex in a binary tree is called the height of the binary
tree.
since to construct an n-vertex binary tree such that the farthest vertex is as far as possible from
the root, we must have exactly two vertices at each level, and of course one at zero level.
For example, for n = 19, we have
level 0
level 0
level 1
level 1
level 2 level 2
level 3 level 3
level 4 level 4
level5
level6
level 7
level 8
level 9
h (k =0, 1,., h)
n = 2k= 2h+1-1
k=0 k=0
..2)
From (1) and (2), we have
n s2h+1-1
Again since *..(3)
h+1 =) 1s) ny =1
k=0 k=0
therefore, h+1 sn
From (3) and (4), we get .(4)
h+1 sns2h+1 1.
Spanning trees
There are many subgraphs of a givern graph G. Some of
are interested in those trees which contain all the these subgraphs are trees. We
vertices of G. These are called spanning trees
oG. These tress are the largest among all the trees in G
with maximum number of edges, hence
these are also known as maxinal tree subgraphs.
Atree Tis called a spanning tree (maxi
mal tree of a connected graph G if T is a sub
graph ofG and it contains all vertices of G. For
example, the subgraph of Gshown in bold lines,
in Fig. 6A4 is a spanning tree of G.
G
A full spanning forest of a graph Gis
a
spanning forest consisting of a collection of
trees, such that each tree is a
spanning tree of a
differentcomponent of G. Fig. 6.44 : Spanning tree of the graph G
Theorem 6.31
Agraph G is
Proof. Let us first assume thatconnected if and onlygraph
Gis aconnected if it has
witha spanning
nvertices tree.
and eedges. Then
e2n-1. If e =n-1, thern Gis atree and so we can say that T=G is a spanning tree of G. But if
e>n-1, then Gis not atree. Therefore it: must contain acircuit. Let e, be an edge in this circuit.
275
Graph Theory
Deleting this edge e from G, the remaining graph G-e, is connected that has n vertices and
e-1edges. Ife-1 =n -1, thenG-e, is a tree and so T =G-e, is a spanning tree of G. But if
e-1>n-1, then G-e, is not atree and so it must have some circuit. Deletion of an edge e, from
his circuit, gives us a subgraph G- (e, eg) which is connected and has n vertices and e -2
dces We continue to delete edges from Guntil we are leftwith e- (e-n + 1)edges, arnd get a
connected subgraph TofGthat has nvertices and e-(e-n+1), ie, n-1 edges. This shows that
Tis a tree. Since Thas the same vertices as that in G, itis a spanning tree of. G.
Conversely, let Tbe a spanning tree of G. Suppose that uand v are any two arbitrary
vertices in G. Then u and vare the vertices of Talso. Since Tis a tree, uand vare connected by a
path in T. Consequently, uand vare connected by apath in Gand so Gis connected.
Above theorem shows that finding a spanning tree of aconnected graph Gis simple,
because if Ghas no circuit, it is already a spanning tree and if it has a circuit then deleting an
edge from the circuit leave that graph still connected. Repeating this operation till a circuit
free graph is obtained containing all the vertices of G. An edge in a spanning tre Tis called a
branch of Tand an edge of Gthat is notin its spanning tree T is called a chord with respect to T.
So a connected graph G is aunion of two subgraphs consisting of branches and chords
respectively with respect to a spanning tree T. It iseasy to see that if Ghas n vertices and e
edges then there are (n - 1)tree branches and (e-n + 1) chords. If G is disconnected with k
components then it has a spanning forest consisting of k spanning trees. We define two
important numbers as
(1)Rank of a graph G=n-k = number of branches in any spanning tree or forest
of G,
(2) Nullity of agraph G=e-n +k= number of chords in G.
Thus we have,
number of edges in G= Rank of G+Nullity of G.
If Gis a connected graph,then k= 1 and then the rank of Gis (n -1), and the nullity of G
is (e-n+ 1).
Spanning Tree in a Weighted Graph
Let G be a connected weighted graph. Recall that in a weighted graph there is a real
number associated with its each edge, called the weight or length of the edge.
Then the weight ofa spanning tree Tof Gis defined as the sum of the weights of all the
edges (branches) in T. Various spanning trees of Gmay have different weights. Aspanning tree
with the smallest weight is called a shortest or minimal spanning tree. However, there may be
several spanning trees with the smallest weight in a weighted graph.
There are several methvds available for finding a shortest spanning tree in a given
weignted graph. We shall explin two such algorithms which are due to Kruskal and Prim.
276 Elements of Discrete Mathematics
Algorithm for Shortest (minimal) Spanning Tree
One algorithm due to Kruskal is as follows:
(1) Kruskal's Algorithm
Let G be a weighted connected graph. First list all edges of the graph G in order at
nondecreasing weights. The algorithm suggests us to first select an edge of the
weighted graph G, that has the smallest weight among all the edges of G which are connected
not loops.
Again avoiding loops, we choose from the remaining edges, the one, having the smalles
weight and which does not form acircuit with the edge already chosen. We repeat the
taking edges having smallest weight among those not already chosen and not forming aprocess
cireuit
with those edges that have already been chosen. The process is
terminated after having chosen
n-1 edges (if the graph has n vertices). These edges form an acyclic subgraph
T of G, which is
minimal spanning tree of G. The whole procedure consists of three steps given below:
Step 1. Choose e, an edge of the weighted graph G, such that e
has the smallest
weight we;) and is not a loop.
Step 2. If the edges ej, e., e, have been chosen, then
choose the edge e;, that has not
been chosen so far, such that
(i) the induced subgraph of G, having the edges e,,
(ü)we.) is the smallest weight associated with
ez,ei1 iS acyclic and
the edge ej among all the weights
associated with edges not already chosen.
Step 3. If Ghas nvertices, then stop after
having chosen n -1 edges. Otherwise repeat
step 2.
Example 6.26 The air line distances (in hundred of
C, D, Eand F are given in the following kilometers) between six cities A, B,
tables:
A B D F
A 56 35 2 51 60
B 56 21 57 78 70
C 35 21 36 68 68
D 2 57 36 51 61
51 78 68 51 13
F 60 70
68 61 13
Find the minimal spanning tree in the graph G.
where the table deternne
weighted (complete) graph G with vertices A, B, C, D,
E and F.
Sol. The minimal spanning tree of the graph Gis shown in the following Fig. o4
277
c a p hT h e o r y
A
A
60 56 60 56
56
60 51 35 61 35
34
B 70 2
70 B 702
13 68 21 13 68 |21
21 78 78
78
68 68 68
13
61 61
68 51 36 51 36
61 57 36
5
D D
D
A A
56 60 56
60
56
51 35 51/ 35\
u
3 B 70
B 770
702 21 13 78 68 |21 -
|21 ’ 13 78 68
13 18 68 68
C E C
C 68 61
61 57
36
36 51
36 51
51
D
D
A
B
51 35 21
13
2
E
D
where i e (1, 2), but vy D or t2. We repeat the process of Choosing the edoeet
e= lo. Da), the end vertices of the edge is a vertex that has
weight with the property that one of
smallest first time, until alln vertices of
chosen and the other end vertex appears for the
been previously
connected by edges. The resultng subgraph is a tree and so a spanning tree r
Ghave been
following four teps:
whole algorithm involves the
of G.
Step 1. Choose any vertex v
that v, # VË and e, has the small..
Step 2. Choose an edge ej = (, D2) 0f G such
incident with U.
weight among all the edges
Step 3. If edges e eg, e, have been Chosen nvolvng end vertices Uj, V2,., Viu1, then
such that e.,hae
choose an edgee1= {o,}, with v;e (v1, V2,Vit1) and v; E {U1, V2, Vil),
smallest weight among all the edges incident with the vertex in the vertex set (u,, D,.. D. .)
Step 4. If n -1edges have been chosen, thern stop. Otherwise go to step 3.
Example 6.27 Obtain a minimal spanning tree of the following weighted graph.
3
B
3 3
Sol. We perform the Prim's algorithm, indicating at each stage, the edges chosen, by
heavy lines A
2
2 2
3
B B
3 4
3 3
3
C C
1 1
2 2
2
D D
(Vertex V, =C)
(e, ={C, D}, V, =D) (e, ={D.A). V, =A)
Graph Theory A A
B
4 3 3 3
3 4
E E
4
1
2 2
2
D
D
(e, {A,F}, V; =F) (e, =(F.E). V, =E)
(e, ={A, B}, V, = B) 2 1
D
Fig. 6.46 : Construction of minimal spanning tree using the Prim's algorithm
Depth-First Search
One of the powerful techniques for solving many graph theory problems is depth-first
search. Recall that a spanning tree of a graph G is a tree that is a subgraph of Gand has
precisely the same vertex set V of G. Also recall that G has a spanning tree if and only if G is a
connected graph. There are many graph theory algorithms that require a systematic method of
traversing the graph. One such algorithm is depth-first search.
Let G=(V,E) be agraph with V= (v1 Vyy) that is represented by its adjacency list.
Without loss of generality we can assume that in the adjacency list of a given vertex v, the
vertices adjacent to vare listed in increasing order of their subscripts. In the depth-first search
of the graph G, the vertex that is currently visited is called the active vertex. We begin a
depth-first search of G by selecting vË as the first active vertex and assign it label 1. Next we
Select avertex that is adjacent toland assign it label 2.This vertex now becomes the new actve
Vertex. We place edge joining the vertices labelled l and 2in a set S.
n general, let r denote the label of the current active vertex in the search, and let not
all vertices in G, containing r have been visited, then we proceed as follows : If there are
Vertices adjacent to r, then select the first vertex on the adjacency list of r, that nas
not been visited and assign it, the next available label. The vertex just labelled now becomes
S.
ve vertex, The edge joining Yand this new active vertex is now placed in the set
280 Elements of Discrete Mathematics
On the other hand if all vertices adjacent to r have been visited, we revisit the vertex that .
the active vertex before r was first visited, and designate as the current active vertex. W
repeat this process until every vertex in G has been visited. If all the vertices of Ghave
been visited then a vertex not yet visited so far is selected as the next active vertex and sh
process is continued.
The label assigned to a vertex vin Gby the depth-first search is called the
depth-first
search index of v and is denoted by dfi (v). After the depth-first search of Gis completed. he
number df (o) is the order in which vwas first visited during the search. Everyedge of Gin s
is the join of two vertices, one of which is being visited for the first time. < S> is called .,
depth-first search forest and is a spanning forest of G. If Gis connected, then <S > is a spannin
tree and iscalled a depth-first search tree.
The Fig. 6.47(6) displays the sequence of steps while applying the depth-first search t
the graph G in Fig. 6.47(a).
V
V
V6
Fig. 6.47(a)
2 Va V6
(ii)
Active vertex changes from v, to vs
V
3 Ve 2 V4 V6
(iii)
Active vertex changes from vs to v, (All vertices in the hrs
connected component of Gare visited, v, is the new active vertex).
1 V
3
V6 2
281
Graph Theory
is complete 4 V,
Fig. 6.47(b) : Depth-first search 6.48la). The depth
algorithm for the graph G is shown in Fig.
The depth-first search and again in Fig. 6.48(c),
where
shown in Fig. 6.48(b),
first search tree T is Vs
dfi (v)
Va 2
V
6
7 V6
3
V6 4
V 5 V4
VA
(a)
V5 V3
V7 V6
8 Vg
V V
(b) (c)
is drawn as a rooted tree. The back edges ofFig.G6.48
are shown in Fig. 6.48(c), and the index of every
vertex of Gis also given in Fig. 6.48(c).
282
Elements of Diserete
Mathemathes
Example 6.28 Apply the depth-first search algorithm to find a spanning tree
folloving graph G. for the
are
and scan its
rfrom
list for
The first vertex appearing on the adjacency list for r is then assigned the
2, and this vertex is added to Q. We continue to label the vertices adjacent
adjacerncy
namely,
label.
the last vertex adjacent with r is labelled deg r +1 and is added to
them to Quntil
next
add
next vertex from Q, say w, and scan its adjacent vertices in the order in
and
to r
then delete the
Q We
appear on the
adjacency list of w. Ifa vertex adjacent with wstill has label 0, then
which they available label and add it to , otherwise we do not change its label.
We
it the next
we assign untilQis empty. When
all the vertices of Gare labelled, we stop.
this
search of the graph Gof Fig. 6.48(a) is shown in Fig. 6.50.
Continue
breadth-first
The Queue
Vye6
5 V6
2V2
2V2 5Vs
VA
V,4 3043
Fig. 6.50
tree for the following
Example 6.29 Ayply breadth-first search to find aspanning
graph. b
f
de
G
m
Elements of Discrete
284 Mathematics
Sol. We select the vertex e as the starting vertex. Then we add all the four vertices b.
them label 1. Next we add the yerti
d, f and iin order that are adiacent with e and assign
Hence the vertices adjacent with
adjacent with these vertices at label 1 not already visited.
namely aand c are added, as are the vertices
h, g andËand k. Thus we have added the vertices
+h.
we add the vertices adjacent with these vertices
a, C, h, 8. jand k at the second step. Next
m.
have not been visited so far. This adds the vertices l and
b
d
k
b C h
g i ka m
a
G
Fig. 6.51: A breadth-first search of