You are on page 1of 11

Graph Theory

9.1 Definition
9.2 Paths and Cycles
9.3 Representation of graphs
9.3.1 Adjacency Matrix
9.3.2 Incidence Matrix
9. Co!p"tation of Paths
9.# $"ler Path and Cycle
9.% &a!iltonian Path and Cycle
9.' (rees
9.'.2 Mini!"! )eight *panning (rees
9.'.1 *panning (ree
9.1 Definition
A graph (undirected) G consists of a set V of vertices (or nodes) and a set E of edges
(or arcs) such that each edge e E is associated with an unordered pair of vertices.
$xa!ple 1+ Undirected graph
v3
e3 e4
e5
v e v! e! v4
V " # v$ v!$ v3$ v4 %
E " # e$ e!$ e3$ e4$ e5 %
An edge e in a graph (directed or undirected) that is associated with the pair of
vertices v and w is said to &e incident on v and w. v and w are said to &e incident on e
and to &e adjacent vertices.
$xa!ple 2+
'n the undirected graph in the e(a)p*e +
v and v! are incident on e
v and v! are ad,acent vertices
The degree of a vertex v " nu)&er of edges which are incident on v.
-or a graph G$ the su) of the degrees of a** vertices in a graph are even. 'n any graph
there are even nu)&er of vertices of odd degree.
$xa!ple 3+
'n the undirected graph in the e(a)p*e +
deg(v) "
deg(v!) " 4
deg(v3) " !
deg(v4) " 3
Tota* " . ( is e/uiva*ent to ! 0 tota* nu)&er of edges )
An edge incident on a sing*e verte( is ca**ed a loop.
$xa!ple
'n the undirected graph in the e(a)p*e +
e5 is ca**ed a *oop
'f a pair of verte( #v$ w% are associated with )ore than one edge$ then such edges are
1nown as para**e* edges (or )u*tip*e edges)
23
$xa!ple #+
'n the undirected graph in the e(a)p*e +
e3 and e4 are ca**ed )u*tip*e edges
A si!ple graph is a graph with neither *oops nor )u*tip*e edges.
A !"ltigraph is a graph with no *oops.
A pse"dograph is a graph with )u*tip*e edges and4or *oops.
A directed graph (digraph) G consists of a set V of vertices (or nodes) and a set E of
edges (or arcs) such that each edge e E is associated with an ordered pair of
vertices.
$xa!ple %+ 5irected Graph
v
e
e!
v! v3
e3
e4
v4
e5 v5
e3
V " # v$ v!$ v3$ v4$ v5 %
E " # e$ e!$ e3$ e4$ e5$ e3 %
A graph with nu)&ers on the edges is ca**ed the weighted graph. 'f edge e is *a&e**ed
1 then we said that the weight of edge e is 1. 'n a weighted graph the *ength of a path
is the su) of of the weights of the edges in the path.
$xa!ple '+ &
6
a 3

4 ! 3 2
c
3 5
d !
4 e
7e can find the )ini)u)8*ength paths &y *isting a** possi&*e paths fro) a to e that
pass every verte( e(act*y once and choose the shortest path.
29
:aths fro) a to e that pass through every verte( e(act*y one ti)e and their *engths.
Path ,ength
a$&$c$d$e !
a$&$d$c$e !6
a$c$&$d$e !4
a$c$d$&$e !3
a$d$&$c$e !9
a$d$c$&$e !!
Acti-ity 1
. -ind the degree of a** the vertices for the fo**owing graphs.
A ; A ;
;
< 5 < 5
9.2 Paths and Cycles
A path fro) v
0
to v
n
of *ength n is a se/uence of vertices and edges. (v
0
and v
n
are
vertices in a graph)
$xa!ple .+
v e v!
e! e3
v3 v4
e4
#v$ e$ v!$ e3$ v3$ e4$ v4 % is a path of *ength 3 fro) verte( v to verte( v4.
A graph G is connected if given any vertices v and w in G there is a path fro) v to w.
$xa!ple 9+
The graph in E(a)p*e 6 is a connected graph since given any vertices v and w in G
there is a path fro) v to w.
26
The fo**owing graph is not connected.
v v!
v4 v5
v3
A connected graph consists of one piece whi*e a graph that is not connected consists
of two or )ore =pieces>. These pieces are su&graphs of the origina* graph and are
ca**ed co)ponents.
A si!ple path fro) v to w is a path fro) v to w with no repeated vertices (hence no
edge is repeated).
A cycle /or circ"it0 is a path of non ?ero *ength fro) v to v with no repeated edges.
A si!ple cycle is a cyc*e fro) v to v in which e(cept for the &eginning and ending
vertices that &oth e/ua* to v there are no repeated vertices.
$xa!ple 11+
: :! :3
:4 :5 :3
@i)p*e path+ #:4$:$:5$:3$:3% *ength of 4
A cyc*e+ #:$:5$:!$:3$:5$:4$:%
A si)p*e cyc*e+ #:$:!$:3$:3$:5$:4$:%
Acti-ity 2
. -or (a) to (h)$ te** whether the given path in the graph is
(i) A si)p*e path (ii) A cyc*e (iii) A si)p*e cyc*e (iv) :ath
22
a &
c
d e
(&$ &)
(e$ d$ c$ &)
(a$ d$ c$ d$ e)
(e$ d$ c$ &)
(&$ c$ d$ a$ &$ e$ d$ c$ &)
(&$ c$ d$ e$ &$ &)
(a$ d$ c$ &$ e)
(&$&)
9.3 Representation of graphs
Aepresentation of graphs &y picture is he*pfu* if the nu)&er of edges and vertices is
s)a**. A*ternative*y we need a )ore for)a* representation ie.
a) ad,acency )atri(
&) incident )atri(
9.3.1 Adjacency Matrix
A si)p*e graph G with p vertices is the p ( p )atri( of ?eros (.) and ones ().
G "
1
1
1
1
1
1
]
1

pp p p p
p
a a a a
a
a a a a
.... ..........
.......
... ..........
3 !
!
3 !
where
if v
i
is ad,acent to v
,
ai, "
. if v
i
is not ad,acent to v
,
$xa!ple 11+
a &
c

d
e
The a&ove si)p*e graph can &e represented as
1
1
1
1
1
1
]
1

.
. . . .
. . .
. .
. . .
e
d
c
b
a
e d c b a
..
$xa!ple 12+
1
1
1
]
1

.
.
.
c
b
a
c b a
The a&ove ad,acency )atri( is the fo**owing graph
a &
c
9.3.2 Incidence Matrix
A graph G is represented with the )atri( where the rows represent the vertices and
the co*u)ns represent the edges. The entry for row v and co*u)n e is if e is incident
on v and . otherwise.
$xa!ple 13+ e3
v v! v3
e e! e5 e3
e4 v5
v4
1
1
1
1
1
1
]
1

. . . .
. . . .
. . . . .
. .
. . . .
5
4
3
!

3 5 4 3 !
v
v
v
v
v
e e e e e e
Bote + A co*u)n such as e4 is understood to represent a *oop. A graph without *oops
each co*u)n has two Cs and that the su) of a row gives the degree of the verte(
identified with that row.
9. Co!p"tation of Paths
'f A is the ad,acency )atri( of a si)p*e graph G$ then the powers A$ A
!
$ A
3
$ D$ count
the nu)&er of paths of various *engths. This )eans that the ijth entry in the )atri( A
n
is e/ua* to the nu)&er of paths fro) i to , of *ength n.
$xa!ple 1+
a &
c
d e
The ad,acency )atri( for the a&ove graph is
.
1
1
1
1
1
1
]
1

. . .
. . .
. .
. .
. . .
e
d
c
b
a
A
e d c b a
1
1
1
1
1
1
]
1

1
1
1
1
1
1
]
1

1
1
1
1
1
1
]
1

!
! . ! .
. 3 !
! 3 .
. ! . !
. . .
. . .
. .
. .
. . .
. . .
. . .
. .
. .
. . .
!
e
d
c
b
a
A
e d c b a
The entry for row & and co*u)n d is ! ie the nu)&er of paths of *ength ! fro) the
verte( & to d is !. ;ased on the diagra) they are
#&$a$d% and #&$c$d%
'n genera* the entry in row ( and co*u)n y of the )atri( A
!
is the nu)&er of paths of
*ength ! fro) verte( ( to verte( y.
Acti-ity 3
. 5raw the graphs represented &y the incidence )atrices+
(i)

,
_

. . .
. . . .
. . . .
. . .
. . . .
e
d
c
b
a
(ii)

,
_

. . . .
. . . .
. . . . .
. . .
. . .
e
d
c
b
a
9.# $"ler Path and Cycle
A path in a graph G that contains each edge in G e(act*y once is ca**ed the Eu*er path.
A cy*e (or circuit) in a graph G that contains each edge in G e(act*y once is ca**ed the
Eu*er cyc*e.
'f a graph G is connected and has a Eu*er cyc*e then each verte( )ust &e of even
degree.
'f graph G is connected and has an Eu*er path then it )ust have e(act*y two vertices
of odd degree or no vertices of odd degree.
$xa!ple 1#+ v3
.!
v!
v
v4
5eg(v) " ! 5eg(v!) " ! 5eg(v3) " ! 5eg(v4) " !
The a&ove graph has an Eu*er path as we** as an Eu*er cy*e.
9.% &a!iltonian Path and Cycle
A Ea)i*tonian path in a graph G is a path that contains each verte( in G e(act*y once.
A Ea)i*tonian cyc*e in a graph G is a cyc*e that contains each verte( in G e(act*y
once e(cept that the first verte( is the sa)e as the *ast verte(.
$xa!ple 1%+
a &

f d c
g e
The a&ove graph has a Ea)i*tonian path #a$&$c$d$e$f$g%
The a&ove graph has a Ea)itonian cyc*e #a$&$c$d$e$f$g$a%
Bote + Un*i1e Eu*er paths and cyc*es$ Ea)i*tonian paths and cy*ces cannot &e easi*y
verified and there are no necessary and sufficient conditions.
.3
9.' (rees
A tree is defined as a connected graph with no cyc*es. A tree wi** have p vertices and
/ edges then p " /F
$xa!ple 1'+

! 9
3 6 2
4 5 3 .
The a&ove graph has no cyc*es and has vertices " . edges F
tree
9.'.1 *panning (ree
A tree T is a spanning tree of a graph G if T is a su&graph of G that contains a** of the
vertices of G.
$xa!ple 1.+
v
e e!
v! v3
e3
e5 e3
e4 e9
e6 e2
v5 e. v3
Eow )any edges wi** there &e in the spanning tree o&tained fro) the graph a&oveG
There are 3 vertices " 5 edges F
Eow to o&tain the spanning treeG
. @tart at v$ add edges and continue to v!$ add e! and continue to v3
!. Be(t at v!$ add e4 and continue to v5$ add e5 anc continue to v4
3. Be(t at v3$ add e9 and continue to v3
v
e e!
v! v3
e5
e4 e9
v4
v5 v3
Note : You can find other spanning trees by starting at different vertex.
.4
v4
9.'.2 Mini!"! )eight *panning (rees
Hini)u) weight spanning trees is a spanning tree for an edge *a&e**ed graph with the
)ini)u) su) of weights.
Using Irus1a*Cs A*gorith)+ The graph T initia**y consists of the vertices of G and no
edges. <hoose an edge in the graph with a )ini)u) weight. At each iteration we add
an edge to T having )ini)u) weight that does not co)p*ete a cyc*e in T with those
edges chosen. 7hen T has n8 edges we stop.
$xa!ple 19+

!
!
! !
4
3 !

4
!
Hini)u) 7eight @panning Tree

!
!


! Tota* weight + .
.5

You might also like