Introduction to Graph Theory Concepts
Introduction to Graph Theory Concepts
Graph Theory
Study of Graphs
Königsberg Bridge Problem
6
Graph
v1 e3 v2
e5 v5
e4 e2
e7
v3 e6 v4
• Graph with five vertices and seven edges. Edge e1 is a self loop
• Edges e4 and e5 are parallel edges.
e1
v1 e3 v2
e5 e4 e2 v5
e7
v3 e6 v4
• A graph that has neither self-loop nor parallel edges is called a
simple graph.
v1 e3 v2
e1
e2
v3 e4 v4
• A graph with a finite number of vertices and edges is called
finite graph ,otherwise it is called infinite graph.
• Simple Graph
– A graph with out any self loops or parallel edges
v1 e3 v2
e4 e2 v5
e1
• pseudo graph v3 e5 v4
e1
v1 e3 v2
e5 e4 e2 v5
e7
v3 e6 v4
Two vertices are said to be adjacent if they are the end vertices of
the same edge.
Vertices v4 and v5 are adjacent
The number of edges incident on a vertex vi, with self-loop counted
twice is called the degree, d(vi) of vertex vi.
d(v1)=d(v3)=d(v4)=3, d(v2)=4, d(v5)=1
e1
v1 e3 v2
e5 e4 e2 v5
e7
v3 e6 v4
A vertex having no incident edge is called an isolated vertex
Vertex v5 is an isolated vertex
Isolated vertex has degree zero.
A vertex of degree one is called a pendant vertex .
Vertex v3 is a pendant vertex
Two adjacent edges are said to be in series if their common
vertex is of degree two
Edges e3 and e5 incident on v1 are in series
e1
v1 e3 v2
e5 e2 .v5
v3 e4 v4
• A graph with out any edges is called a null
graph.
– A null graph with 5 vertices
.v2
.v3
.v1
.v5
.v4
• Complete graph
– A simple graph in which there exists an edge between every
pair of vertices.
– a complete graph with n vertices is represented as Kn.
– It is also known as universal graph or clique.
– The degree of every vertex in a complete graph with n
vertices(Kn) is n-1.
– Total number of edges in G is n(n-1)/2.
Complete Graphs
• Denoted by Kn.
Representation of Graphs
• Adjacency List
• Adjacency Matrix
• Incidence matrix
Adjacency List Representation
Two vertices are said to be adjacent if they are the end vertices of the same edge.
Adjacency matrix
e3 e5
e1
v5 e7
e2
e6 v6
v1
V1 v2 v3 v4 v5 v6
V1 0 1 0 0 1 1
V2 1 0 0 1 1 0
V3 0 0 0 1 0 0
V4 0 1 1 0 1 1
V5 1 1 0 1 0 0
V6 1 0 0 1 0 0
Matrix representation of graphs
• Incidence matrix
• Let G be a graph with n vertices , e edges.
• Define an n by e matrix A=[aij], whose n rows correspond to
the n vertices and the e columns correspond to the e edges, as
follows:
a ij=1, if j th edge ej is incident on ith vertex vi,
aij=0, otherwise
• Such a matrix A is called vertex-edge incident matrix
• The incidence matrix contains only two elements 0 and 1. such a
matrix is called a binary matrix or a (0,1) matrix.
v3
a
h
v6
v2 e b
v4
f
g c
v1 d v5
a b c d e f g h
V1 0 0 0 1 0 1 0 0
V2 0 0 0 0 1 1 1 1
v3 0 0 0 0 0 0 0 1
v4 1 1 1 0 1 0 0 0
V5 0 0 1 1 0 0 1 0
V6 1 1 0 0 0 0 0 0
• Since every edge is incident on exactly two vertices,
each column (representing an edge )has exactly
two 1’s.
• The number of 1’s in each row equals the degree
of the corresponding vertex.
• A row with all zeros, therefore, represents an isolated
vertex
• Parallel edges in a graph produce identical columns
in incidence matrix.
• Walk
– An alternate sequence of vertices and edges, beginning and
ending with vertices, such that each edge is incident with the
vertices preceding and following it.
– In the following fig: v1 a v2 b v3 c v3 d v4 e v2 f v5 is a walk
v1
g a
v3
c
b v2
e
d f
h
v4
v5
Vertices with which a walk begins and end is
called its terminal vertices.
Length of the walk is the number of edges in the
walk.
A walk in which terminal vertices are the same is
called a closed walk
Eg: v1 a v2 b v3 c v3
• Path
– If no vertex of the walk appears more than once, then the
walk is called a path.
• Eg: v1 a v2 b v3 d v4 is a path
• The number of edges in a path is called the length of a
path
v1
g a
v3
c
b v2
e
d f
h
v4
v5
• Circuit
– A walk which starts and ends at the same vertex.
– No repetition of edges in a circuit.
– Every vertex in a circuit is of degree 2.
Eg: v2 b v3 d v4 e v2 is a circuit
Cycle
A circuit that does not contain any repetition of vertices
except the starting and ending vertex is called a cycle.
v1
g a
c v3
b v2
e
d f
v4 h
v5
Cycles with 3 ,4,5,6 Vertices
Wheels
• When an additional vertex is added to the
cycle Cn, for n>=3 and connect this new
vertex to each of the n vertices in Cn by
new edges , we obtain a Wheel.
• Let G=(V,E) be a directed graph.
• The incoming or in-degree of v is the number of edges in G
that are incident into v and is denoted by id(v).
• The outgoing or outdegree of v is the number of edges in G
that are incident from v and is denoted by od(v).
If the directed graph has one or more loops, each loop at a given
vertex v contributes a count of 1 to each of id(v) and od(v).
What are the in-degrees and out-degrees of the vertices
a, b, c, d in this graph:
id(b) = 4
a od(b) = 2
id(a) = 1 b
od(a) = 2
id(d) = 2 id(c) = 0
od(d) = 1 d c od(c) = 2
SUB GRAPHS
A graph g is said to be a sub-graph of a graph G if all the vertices
and all the edges of g are in G, and each edge of g has the same
end vertices in g as in G.
Every graph is its own sub graph
A single vertex in a graph G is a sub-graph of G
A single edge in G together with its end vertices is also a sub-
graph of G
Fig (b) is one of the sub-graph of fig (a)
e1
v1 e3 v2 v2
e5 e4 e2 v5 e2 v5
e7 e7
v3 e6 v4 v4
fig (a)-Graph G Fig (b)- Graph g1
SPANNING SUBGRAPH OF A GRAPH
v1 v1
c
g a g
v3 v3 v7
c b v2 b v2
e
a
e d f v8
d f
c
h v4 h
v4 v5 v5
v6
g a
v3
c
b v2
e
d f
h
v4
v5
v1
c
fig (a)
g
v3 v7
b v2
e
a
d f v8
c
v4 h
v5
fig (b) v6
Connectedness in Directed Graphs
• A directed graph is strongly connected if there is a
path from a to b and from b to a whenever a and b
are vertices in the graph.
Weakly Connected graph
Multigraph
• A graph which is permitted to have multiple edges (parallel
edges) between a pair of vertices.
• Multiplicity of a multigraph
• Multiplicity of edge (a,b) = 3
• ” (b,c) and (d,e) =2
• ” (e,d) =1
e1
v1 e3 v2
e5 e4 e2 v5
e7
v3 e6 v4
v3
c
b v2
e
d f
h
v4
v5
• The Handshaking Theorem
g a
c v3
b v2
e
d f
• Sum of degrees = 2+4+5+3+2 =16
v4 h
• [Link] edges =8 v5
• Therefore 16 = 2*8
Try the following Qn
• How many edges are there in a graph with 10
vertices each of degree six?
Try the following Qn
• How many edges are there in a graph with 10
vertices each of degree six?
• Ans: 30 Edges
Isomorphism
• Two graphs are said to be isomorphic (equivalent) if they
have identical behavior in terms of graphic theoretic
properties
• A graph that can not be drawn on a plane with out a cross over
between its edges is called non-planar.
or
Properties of kuratowski’s two graphs
5
1
2 4
3
6
Cut-set
• In a connected graph G, a cut-set is a set of edges whose
removal from G will disconnect the graph G, provided
removal of no proper subset of these edges disconnects
G.
• A cut –set is a minimal disconnecting set of edges.
Whenever a cut-set for a connected graph consists of
only one edge, that edge is called a bridge for the
graph.
– Eg: Different cut-sets are
{a,c,d,f},
{a,b,g} ,
{a,b,e,f},
{d,h,f} and
{k} .
The set {a,c,h,d} is not a cut set, because one of its
proper subset {a,c,h} is a cut-set.
• Edge connectivity:
– The number of edges in the smallest cut-set (cut-set with
fewest number of edges) is called the edge connectivity of G.
• Vertex connectivity:
– Vertex connectivity of a connected graph G is defined as the
minimum number of vertices whose removal from G leaves the
remaining graph disconnected.
Cut vertex
Euler Circuit
• Euler Circuit
- A closed walk that includes all the edges in a graph exactly
once and starts and ends at the same vertex.
A given connected graph G is an Euler graph if and only if all
vertices of G are of even degree
Cut Edge
A D E G
Solution
CE and GH are cut edges, if either is removed, it
would disconnect the graph.
Fleury’s Algorithm
• Fleury’s algorithm can be used to find an Euler circuit in any
connected graph in which each vertex has even degree.
• Step 1: Start at any vertex. Go along any edge from this
vertex to another vertex. Remove this edge from the graph.
• Step 2: Choose any edge from this vertex, but not a cut
edge, unless one have no other option. Go along the chosen
edge. Remove this edge from the graph.
• Step 3: Repeat Step 2 until all the edges have used and
arrived at the vertex at which you started the walk.
Example: Using Fleury’s Algorithm
Find an Euler circuit for the graph below.
B C
F
A D E
Solution
B C
Remove F
BC
A D E
© 2008 Pearson Addison-
Wesley. All rights reserved 15-2-78
Example: Using Fleury’s Algorithm
Solution (continued)
B C
F
Remove
CF
A D E
B C
F
Remove
FD
A D E
© 2008 Pearson Addison-
Wesley. All rights reserved 15-2-79
Example: Using Fleury’s Algorithm
Solution (continued)
B C
F
Remove
DE
A D E
AAAnswer:6 a->d->e->z
Using Dijkstra’s Algorithm find shortest path from a to z
Solution
Euler Graph
v1 e3 v2
e4 e2
v3 e1 v4
24
2 3
9
s
18
14
2 6
6
30 4 19
11
15 5
5
6
20 16
t
7 44
100
Draw 2 Hamiltonian Circuits
• Proofs
1.
Prove that K5 or K3,3. are not planar graphs.
– In a simple connected planar graph with r
regions, n vertices and e edges (e>2), the
following inequalities hold:
3r 2e
e 3n-6
A 0 14 12 7 10
B 14 0 9 13 5
C 12 9 0 6 8
D 7 13 6 0 11
E 10 5 8 11 0
Some solutions for TSP
• Let the Starting city be A
A –D – C – E – B – A
distance=40
e3 e5
e1
v5 e7
e2
e6 v6
v1
3+3+1+3+4+2 = 2*8
Euler’s formula
A connected planar graph with n vertices and e edges has e
- n+2 regions. ( that is, r = e – n + 2)
Proof:
Consider the planar graph G with n vertices and e edges. The
theorem can be proved by constructing a sequence of
subgraphs G1, G2, G3,…….Ge by successively adding an edge
at each stage. Arbitrarily pick one edge of G to obtain G1.
Obtain Gn from Gn-1 by adding an edge that is incident with
a vertex already in Gn-1. This construction is possible because
G is connected. G is obtained after e edges are added.
Let rn,en,and vn represent the number of regions, edges and
vertices of the planar representation of Gn. The relation
r1=e1-v1+2 is true for G1
The relation r1=e1-v1+2 is true for G2,because e1=1,v1=2, and
r1=1.
Now assume that rn=en-vn+2.
Let {an+1,bn+1}be the edge that is added to Gn to obtain Gn+1.
There are two possibilities to [Link] the first case, both
an+1 and bn+1 are already in [Link] two vertices must be
on the boundary of a common region R, or else it would be
impossible to add the edge{an+1,bn+1} to Gn without two
edges crossing( and Gn+1 is planar). The addition of this new
edge splits R into two regions. Consequently, in this case,
rn+1 =rn+1,
en+1=en+1and ,
Vn+1=Vn. The formula is still true.
In other words, rn+1=en+1-vn+1+2 is true.
In the second case, one of the two vertices of the new edge is not
already in Gn. Suppose that an+1 is in Gn but bn+1 is not. Adding
this edge does not produce any new regions , because bn+1
must be in the region that has an+1 on its boundary.
Consequently,
rn+1= rn. Moreover,
en+1= en+1 and
Vn+1= Vn+1. Here also formula remains the same and is true.
In other words rn+1= en+1-vn+1+2 is true.
Hence Euler’s Formula is true for all planar graphs.
For G1
r= e-n+2 = 0-1+2 = 1 region
For G2
r =2-n+2 = 1-2+2 =1 region
For G3
case1
r= 2-3+2 =1 region
Case 2
r= 3-3+2 =2 regions
• Theorem 2-4
A given connected graph G is an Euler
graph if and only if all vertices of G are of
even degree
Proof:
Suppose that G is an Euler Graph. It therefore
contains an Euler line (which is a closed walk). In
tracing this walk we observe that every time the walk
meets a vertex v it goes through two “new” edges
incident on v- with one vertex “entered” v and with
the other “exited”. This is true not only of all
intermediate vertices of the walk but also of the
terminal vertex, because we “exited and “entered” the
same vertex at the beginning and end of the walk,
respectively. Thus if G is an Euler Graph, the degree
of every vertex is even.
To prove the sufficiency of the condition, assume
that all vertices of G are of even degree. Now we
construct a walk starting at an arbitrary vertex v and
going through the edges of G such that no edge is
traced more than once. We continue tracing as far as
possible. Since every vertex is of even degree , we can exit
from every vertex we enter; the tracing cannot stop at any
vertex but v. And since v is also of even degree, we shall
eventually reach v when tracing comes to an end. If this closed
walk h we just traced includes all the edges of G, G is an
Euler graph.
Ans
Find shortest path from s to t.
24
2 3
9
s
18
14
2 6
6
30 4 19
11
15 5
5
6
20 16
t
7 44
119
Dijkstra's Shortest Path Algorithm
S={ }
PQ = { s, 2, 3, 4, 5, 6, 7, t }
24
2 3
0 9
s
18
14 2 6
6
30 4 19
11
15 5
5
6
20 16
t
7 44
distance
120 label
Dijkstra's Shortest
S={ }
Path Algorithm
PQ = { s, 2, 3, 4, 5, 6, 7, t }
delmin
24
2 3
0 9
s
18
14 2 6
6
30 4 19
11
15 5
5
6
20 16
t
7 44
distance
121 label
Dijkstra's Shortest
S={s}
Path Algorithm
PQ = { 2, 3, 4, 5, 6, 7, t }
decrease key
X
9
24
2 3
0 9
s
18
14 X
14 6
2
6
30 4 19
11
15 5
5
6
20 16
t
7 44
distance
122 label 15
X
Dijkstra's Shortest
S={s}
Path Algorithm
PQ = { 2, 3, 4, 5, 6, 7, t }
delmin
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
30 4 19
11
15 5
5
6
20 16
t
7 44
distance
123 label 15
X
Dijkstra's Shortest
S = { s, 2 }
Path Algorithm
PQ = { 3, 4, 5, 6, 7, t }
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
30 4 19
11
15 5
5
6
20 16
t
7 44
124 15
X
Dijkstra's Shortest
S = { s, 2 }
Path Algorithm
PQ = { 3, 4, 5, 6, 7, t }
decrease key
X
33
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
30 4 19
11
15 5
5
6
20 16
t
7 44
125 15
X
Dijkstra's Shortest
S = { s, 2 }
Path Algorithm
PQ = { 3, 4, 5, 6, 7, t }
X
33
X 9
24
2 3
0 9
delmin
s
18
14 X 14
6
2
6
30 4 19
11
15 5
5
6
20 16
t
7 44
126 15
X
Dijkstra's Shortest
S = { s, 2, 6 }
Path Algorithm
PQ = { 3, 4, 5, 7, t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
44
30 X
4 19
11
15 5
5
6
20 16
t
7 44
127 15
X
Dijkstra's Shortest
S = { s, 2, 6 }
Path Algorithm
PQ = { 3, 4, 5, 7, t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
44
30 X
4 19
11
15 5
5
6
20 16
t
7 44
128 15
X delmin
Dijkstra's Shortest
S = { s, 2, 6, 7 }
Path Algorithm
PQ = { 3, 4, 5, t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 35
44
30 X
4 19
11
15 5
5
6
20 16
t
7 44
129 15
X
59 X
Dijkstra's Shortest
S = { s, 2, 6, 7 }
Path Algorithm
PQ = { 3, 4, 5, t } delmin
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 35
44
30 X
4 19
11
15 5
5
6
20 16
t
7 44
130 15
X
59 X
Dijkstra's Shortest
S = { s, 2, 3, 6, 7 }
Path Algorithm
PQ = { 4, 5, t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44
30 X
4 19
11
15 5
5
6
20 16
t
7 44
131 15
X 51 59
X X
Dijkstra's Shortest
S = { s, 2, 3, 6, 7 }
Path Algorithm
PQ = { 4, 5, t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44
30 X
4 19
11
15 5
5
6
20 16
delmin
t
7 44
132 15
X 51 59
X X
Dijkstra's Shortest Path
S = { s, 2, 3, 5, 6, 7 }
Algorithm
PQ = { 4, t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44 45 X
30 X
4 19
11
15 5
5
6
20 16
t
7 44
133 15
X 50 51
X 59
X X
Dijkstra's Shortest Path
S = { s, 2, 3, 5, 6, 7 }
Algorithm
PQ = { 4, t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44 45 X
30 X
4 19
11
15 5 delmin
5
6
20 16
t
7 44
134 15
X 50 51
X 59
X X
Dijkstra's Shortest Path
S = { s, 2, 3, 4, 5, 6, 7 }
Algorithm
PQ = { t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44 45 X
30 X
4 19
11
15 5
5
6
20 16
t
7 44
135 15
X 50 51
X 59
X X
Dijkstra's Shortest Path
S = { s, 2, 3, 4, 5, 6, 7 }
Algorithm
PQ = { t }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44 45 X
30 X
4 19
11
15 5
5
6
20 16
t
7 44
delmin 50 51
X 59
X X
136 15
X
Dijkstra's Shortest Path
S = { s, 2, 3, 4, 5, 6, 7, t }
Algorithm
PQ = { }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44 45 X
30 X
4 19
11
15 5
5
6
20 16
t
7 44
137 15
X 50 51
X 59
X X
Dijkstra's Shortest Path
S = { s, 2, 3, 4, 5, 6, 7, t }
Algorithm
PQ = { }
32
X
33
X
X 9
24
2 3
0 9
s
18
14 X 14
6
2
6
X 34
X 35
44 45 X
30 X
4 19
11
15 5
5
6
20 16
t
7 44
138 15
X 50 51
X 59
X X