0% found this document useful (0 votes)
27 views32 pages

Graph Theory

DISCRETE MATHEMATICS UNIT: GRAPH THEORY

Uploaded by

halumsona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views32 pages

Graph Theory

DISCRETE MATHEMATICS UNIT: GRAPH THEORY

Uploaded by

halumsona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

WOMEN’S POLYTECHNIC

4, STRAND ROAD,
P.O. CHANDANNAGAR
DISTRICT - HOOGHLY.

DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY


2ND YEAR – 3RD SEMESTER
E-CONTENTS : DISCRETE MATHEMATICS
UNIT : GRAPH THEORY UNIT NO: 7

Developed By : Aniruddha Bhaduri, Lecturer


Computer Science & Technology
Women’s Polytechnic, Chandannagar
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Contents :

7.1 Introduction – Definition of a graph –Directed & Undirected graphs(Definition &


Example); Basic Terminology – Loop, Multi graph, Pseudo graph, Simple graph,
Finite and Infinite graphs- Definition and examples.

7.2 Sub-graph Spanning sub-graph-Removal of a Vertex and an edge-Induced sub-


graph- Definition & Example.

7.3 Graph Isomorphism – Definition and Examples.

7.4 Walk, Paths, length and Circuits –Definition and Examples.

7.5 Euler graphs –Euler path, Euler Circuit – Definition and examples.

7.6 Hamiltonian Graphs – Definition and example – Problems.

7.7 Sequential Representation of Graphs

7.8 Linked Representation of Graphs

7.9 Traversal of Graphs

7.8 Shortest Path, Shortest path algorithm – Dijkstra’s


algorithm, Floyd-Warshall algorithms – Problems.
BFS algorithm-DFS

7.9 Application of Graph

1
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.1 Introduction

Definition of a graph –Directed & Undirected graphs(Definition & Example); Basic


Terminology – Loop, Multi graph, Pseudo graph, Simple graph, Finite and Infinite
graphs- Definition and examples.

Definition of a graph : A graph G=(V,E) consists of a set of objects V = {v1,v2,v3,…..}


called vertices and another set E = {e1,e2,e3,…..}, whose elements are called edges,
such that each edge ek is associated with ordered or unordered pair (vi,vj) of vertices.

Directed graph : A directed graph or a digraph G consists of a set of vertices V =


{v1,v2,…..}, a set of edges E = {e1,e2,…..} such that each edge ek is associated with
an ordered pair (vi,vj) of vertices.

A vertex is represented by a point and an edge by line segment between vi an


vj with an arrow directed from vi to vj.

(Figure – 7.1.1)
Directed graph 5 vertices and 9 edges

A digraph is shown above (Figure – 7.1.1), where V = {v1,v2,v3,v4,v5} and


E={e1,e2,e3,e4,e5,e6,e7,e8,e9}

Here the edge e1 associated with the ordered pair (v1,v4) but not (v4,v1). In the
diagram we use directional arrow from initial vertex v1 to the terminal vertex v4 to
show the ordering.

The edges e6 , e7 are parallel edges, because both are in the same direction. But
edges e2 and e3 are not parallel edges, because the directions are different.

2
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Undirected graph : A graph G=(V,E) consists of a set of objects V = {v1,v2,v3,…..}


called vertices and another set E = {e1,e2,e3,…..}, whose elements are called edges,
such that each edge ek is associated with an unordered pair (vi,vj) of vertices.
End vertices : As we know that the edge ek is represented by a pair of vertices (vi,vj),
these vertices are known as end vertices of ek.
The most common representation of a graph is by means of diagram, in which the
vertices are represented as points and each edge as a line segment joining its end
vertices.

(Figure – 7.1.2)
Graph with 5 vertices and 7 edges

Here the edge e7 is associated with a vertex pair (v4,v5). Also the other edges of the
graph associated with some specific pair of vertices.

A graph is also called a linear complex, 1-complex, 1 dimensional complex.


A vertex is also referred to as a node, junction, point, 0-cell, 0-simplex.
An edge is also known as a branch, line, element, 1-cell, arc, 1-simplex.

Note - 1 : In drawing graph, it is immaterial whether the lines are drawn straight or
curved, long or short; what is important is the incidence between the edges and
vertices. Two graphs shown in [Figure – 7.1.3(a)] and [Figure – 7.1.3(b)] are same,
because incidence between edges and vertices is same in both the cases.

[Figure – 7.1.3(a)] [Figure – 7.1.3(b)]

3
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Note - 2 : In a diagram of graph, sometimes two edges may seem to intersect at a point
that does not represent a vertex, for example, edges e and f in the graph
(figure–7.1.4) given below. Such edge should be thought of as being in different planes
and thus having no common point.

(Figure – 7.1.4)
Edges ‘e’ and ‘f’ have no common point.

Basic Terminology :

Self loop : An edge having the same vertex as both its end vertices is called a self loop.
In the above mentioned graph (Figure – 7.1.2), the edge e1 is a self loop with both
end vertices v2.

Parallel edges : When there are more than one edge associated with a given pair of
vertices, then the edges are called parallel edges. In the above mentioned graph
(Figure – 7.1.2), the edges e4 and e5 are parallel edges, because both the edges
associated with same pair of vertices (v1,v3).

Multi graph : A graph consisting of parallel edges but no self loop is called a multi
graph.

(Figure – 7.1.5)
Multi graph

4
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Pseudo graph : A graph consisting of parallel edges as well as self loops is called a
pseudo graph. It is also known as general graph.

(Figure – 7.1.6)
Pseudo graph

Simple graph : A graph that has neither self loop nor parallel edges is called a simple
graph.

(Figure – 7.1.7)
Simple graph

Finite and Infinite graph : A graph G=(V,E) is said to be finite graph if it has finite
number of vertices and finite number of edges. A graph which is not finite is called
infinite graph.

[Figure – 7.1.8(a)] [Figure – 7.1.8(b)]


Finite graph Infinite graph

5
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Some more terminologies :

Incidence : When a vertex vi is an end vertex of some edge ej , vi and ej are


said to be incident with each other.

(Figure – 7.1.9)

Adjacent edges : Two non parallel edges are said to be adjacent, if they are incident
on a common vertex. For example, considering the above mentioned graph
(Figure– 7.1.9), edges e2 and e7 are adjacent.

Adjacent vertices : Two vertices are said to be adjacent, if they are end vertices of the
same edge. For example, in the above mentioned graph (Figure – 7.1.9), v4 and v5
are adjacent but v1 and v4 are not adjacent.

Degree of a vertex : The number of edges incident on a vertex vi , with self loop
counted twice, is called the degree, d(vi) of the vertex vi . The degree of a vertex is
also known as valence of a vertex.

For example, in the above mentioned graph (Figure – 7.1.9),


d(v1) = 3, d(v2) = 4, d(v3) = 3, d(v4) = 3, d(v5) = 1

6
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Out-degree and In-degree of a vertex in a digraph : The number of edges incident


out of a vertex vi is called the out-degree (or out valance) of vi and is written as
d+(vi). The number of edges incident into vi is called the in-degree (or in-valance) of
vi and is written as d-(vi).

(Figure – 7.1.10)
Digraph

Out-degree and In-degree of all the vertices of the above mentioned graph
(Figure – 7.1.10) is given below :

d+(v1) = 3 d-(v1) = 1
d+(v2) = 1 d-(v2) = 3
d+(v3) = 3 d-(v3) = 0
d+(v4) = 1 d-(v4) = 3
d+(v5) = 1 d-(v5) = 2

In any digraph G, the sum of all in-degrees is equal to the sum of all out-degrees, each
sum being equal to the number of edges in G.
n n
i.e Ʃd+(vi) = Ʃd-(vi)
i=1 I=1

7
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Odd and Even vertex : The vertex of odd degree is called odd vertex and the vertex of
even degree is called an even vertex.

(Figure – 7.1.11)

For example, considering the above mentioned graph (Figure – 7.1.11) , v1 , v3 are
even vertices and v2 , v4 are odd vertices.

Isolated vertex : A vertex with no incident edge is called an isolated vertex. The degree
of isolated vertex is zero.
For example, in the above mentioned graph (Figure – 7.1.11), v5 is an isolated vertex.

Pendant vertex : A vertex of degree one is called pendant vertex.


For example, in the above mentioned graph (Figure – 7.1.11), v4 is pendant vertex.

Pendant edge : The edge incident on to pendant vertex is known as pendant edge.
For example, in the above mentioned graph (Figure – 7.1.11), e4 is pendant edge.

Series : Two adjacent edges are said to be series if their common vertex is of degree
two.
For example, in the above mentioned graph (Figure – 7.1.11), edges e1 and e2 are
in series also edges e1 and e3 are in series.

Null graph : A graph without any edge, is called a null graph. All the vertices in a null
graph are isolated vertices.

(Figure – 7.1.12)
Null graph

8
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Regular graph : A graph in which all the vertices have same degree is called a regular
graph.

(Figure – 7.1.13)
A regular graph with three vertices, each of the vertices is of degree two.

Complete graph : A simple graph in which every pair of vertices are joined by edge is
called a complete graph.

(Figure – 7.1.14)
A complete graph.

Complement of a graph : If G be a simple graph then another graph Ḡ is said to be the


complement of G, if G and Ḡ have same set of vertices and pair of vertices in Ḡ would
be joined by edge, if they are not joined in G.

G Ḡ
[Figure – 7.1.15 (a)] [Figure – 7.1.15 (b)]

The graph G is shown in Figure – 7.1.15 (a) and the complement of G i.e. Ḡ is shown in
Figure– 7.1.15 (b)

9
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Theorems on Graphs :

Theorem - 1 : In a graph G with n vertices and e edges, the sum of degrees of


all vertices is twice the number of edges
n
i.e. Ʃ d(vi) = 2e.
I=1

Proof : Let G be any graph with n number of vertices and e number of edges.
Let ek be an edge of G . If ek be a self loop at the vertex vi , then it contributes
2 to the degree of vi , i.e. to the sum of the degree of all vertices.
If ek is not a self loop, it is incident to , two distinct vertices, say vi and vj . Then it
contributes 1 to the degree of each of the vertices vi and vj i.e. ek contributes
2 to the sum of degrees of all vertices.
So we see that, an edge always contributes 2 to the sum of the degree of all vertices.
Therefore Sum of the degree of all vertices = 2 x number of edges
n
i.e. Ʃ d(vi) = 2e. (Proved)
I=1

Theorem - 2 : The number of vertices of odd degree in a graph is always even.

Proof : If we consider the vertices with odd degrees and even degrees separately, the
sum of the degree of all vertices can be expressed as –
n
Ʃ d(vi) = Ʃ d(vj) + Ʃ d(vk) ---------(i)
I=1 even odd

We know that, the sum of degrees of all vertices is twice the number of edges.
n
i.e. Ʃ d(vi) = 2 x number of edges
I=1

So, the L.H.S. of equation (i) is even. Also Ʃ d(vj) is the sum of even numbers, so it
must be even
even

number.
Since, the L.H.S. of equation (i) is even and the first expression of R.H.S. of the same
equation is even, the second expression must be even.

Therefore Ʃ d(vk) = an even number


odd

Since, each d(vk) is odd, the total number of terms must be even to make the sum an
even number. Hence the theorem.

10
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Theorem – 3 : The maximum degree of any vertex in a simple graph with n vertices
is n – 1.

Proof : Let v be a vertex of a simple graph G and degree of v is m i.e. d(v) = m


So, m number of edges are incident to v.
Since G is a simple graph, no self loop or parallel edges are allowed in G.
So, on the other ends of those m edges, there are m distinct vertices.
Hence we get m + 1 number of vertices in G including v.
Therefore m + 1 ≤ n
or, m ≤ n – 1
i.e. d(v) ≤ n – 1.
Since v be any vertex in G, so the maximum degree of any vertex in a simple graph
with n vertices is n – 1 (Proved)

Theorem - 4 : The maximum number of edges in a connected simple graph with n


vertices is n ( n – 1 ) / 2.

Proof : Let G be a connected simple graph with n vertices and e edges..


Since the graph G is simple, no self loops or parallel edges are allowed in G.
We know that the maximum degree of any vertex in a simple graph with n vertices is
n–1
So, the maximum degree of of a vertex in G = n – 1
Therefore the maximum degree of n vertices in G = n (n – 1)
Again, we know that, the sum of degrees of all vertices in a graph G is equal to twice
the number of edges.
n
i.e Ʃd(vi) = 2e
I=1

Therefore maximum sum of degrees of all vertices = n (n – 1)


i.e. 2e ≤ n (n – 1)
Therefore e ≤ n (n – 1) / 2
So, the maximum number of edges in a connected simple graph with n vertices is n
(n – 1) / 2

(Proved)

11
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Theorem - 5 : The number of edges in a complete graph with n vertices is n (n – 1)/ 2

Proof : Since the graph is complete, so it is simple graph.


i.e. there is no self loops and parallel edges and all the pair of vertices are joined by
edges.
We know that, maximum degree of any vertex in a simple graph with n vertices is n
–1
So, the degree of each vertex = n – 1
Therefore degree of n vertices = n (n – 1)
i.e. the sum of the degrees of all vertices = n (n – 1)
We know that, the sum of degrees of all vertices in a simple graph is twice the number
of edges
Therefore 2 x number of edges = n (n – 1)
So, the number of edges = n (n -1) / 2
Therefore, the number of edges in a complete graph with n vertices is n (n – 1) / 2
(Proved)

12
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.2 Sub-graphs

Sub-graph, Spanning sub-graph,-Removal of a Vertex and an edge-Induced sub-


graph- Definition & Example.

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.

[Figure – 7.2.1(a)] [Figure – 7.2.1(b)]


The graph shown in Figure – 7.2.1(b) is a sub-graph of the graph shown in
Figure – 7.2.1(a)

Observations :

(1) Every graph is its own sub-graph.


(2) A sub-graph of a sub-graph of G is a sub-graph of G.
(3) A single vertex in a graph G is a sub-graph of G.
(4) A single edge in G, together with its end vertices is also a sub-graph of G.

Edge-disjoint sub-graphs : Two (or more) sub-graphs g1 and g2 of a graph G are


said to be edge disjoint, if g1 and g2 do not have any edge in common, but they
may have vertices in common.

[Figure - 7.2.2(a)] [Figure – 7.2.2(b)] [Figure – 7.2.2(c)


Graph G Graph g1 Graph g2

13
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Vertex-disjoint sub-graphs : Two sub-graphs g1 and g2 of a graph G are said


to be vertex disjoint, if g1 and g2 do not vahe any vertex in common.

[Figure – 7.2.3(a)] [Figure – 7.2.3(b)] [Figure – 7.2.3(c)]


Graph G Graph g1 Graph g2

Spanning sub-graphs : A sub-graph G’ of a graph G is said to be spanning sub-


graph of G, if G’ consists of all the vertices of G. i.e. if both the graphs G and
G’ have same vertex set.

[Figure – 7.2.4(a)] [Figure – 7.2.4(b)]


Graph G Graph G’

The graph G’ is a spanning sub-graph of the graph G. Both the graphs G and
G’ have same vertex set i.e. V(G) = V(G’) = {v1,v2,v3,v4,v5}

14
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Removal of a vertex : The sub-graph G’ of a graph G obtained by removing


vertex v along with all the edges incident on v is called the graph obtained by
removal of vertex v. It is denoted by G – v.

[Figure – 7.2.5(a)] [Figure – 7.2.5(b)]


Graph G Graph G’

Graph obtained by removal of vertex v5 is G – v5

Removal of an edge : The sub-graph G’ of a graph G obtained by removing the


edge e is called the graph obtained by removal of edge e.

[Figure – 7.2.6(a)] [Figure – 7.2.6(b)]


Graph G Graph G’

The graph obtained by removal of the edges e5, e6 is G – (e5,e6)

15
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Induced sub-graphs : Let V be the vertex set of the graph G and V’ is a sub-
set of V. Then the sub-graph with the vertex set V’ together with all the edges of
G connecting the vertices in V’ is called the V’ – induced sub-graph of G.

[Figure – 7.2.7(a)] [Figure – 7.2.7(b)]


Graph G Graph G’

The graph G’ is the V’ – induced sub-graph of the graph G, where V’ = {v1,v2,v3,v4}

16
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.3 Isomorphism

Graph Isomorphism – Definition and Examples.

Isomorphism : Two graphs G and G’ are said to be isomorphic to each other, if


there is one-to-one correspondence between their vertices and between their edges
such that the incidence relationship is preserved.

Note : It is observed by the definition of isomorphism that, two isomorphic graphs must
have –
(i) The same number of vertices.
(ii) The same number of edges.
(iii) An equal number of vertices with a given degree.

[Figure – 7.3.1(a)] [Figure – 7.3.1(b)


Graph G Graph G’

All the three conditions of isomorphism are satisfied by the graph G and G’. So they
are isomorphic

[Figure – 7.3.2(a)] [Figure – 7.3.2(b)]


Graph G Graph G’

All the three conditions of isomorphism are satisfied by the graph G and G’. So they
are isomorphic

17
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

[Figure – 7.3.3(a)] [Figure – 7.3.3(b)]


Graph G Graph G’

The two graphs shown in the Figure – 7.3.3(a) and Figure – 7.3.3(b) satisfies all three
conditions, but they are not isomorphic.

In graph G, the vertex d is of degree 3, it must corresponds to the


vertex r of G’, which is the only vertex of degree 3. In G vertex d is adjacent to
two vertices of degree 1 and one vertex of degree 2. But in G’ vertex r is adjacent to
one vertex of degree 1 and two vertices of degree 2. So the adjacency is not
preserved here. Hence the graphs G and G’ are not isomorphic.

[Figure – 7.3.4(a)] [Figure – 7.3.4(b)]


Graph G Graph G’

The two graphs shown in the Figure – 7.3.4(a) and Figure – 7.3.4(b) satisfies all three
conditions, but they are not isomorphic.

18
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.4 Walk, Path and Circuit

Walk, Paths, length and Circuits –Definition and Examples.

Walk : A walk is defined as a finite alternating sequence of vertices and edges,


beginning and ending with vertices, such that each edge is incident with the vertices
preceding and following it.

(Figure – 7.4.1)

For example, v1 a v2 b v3 c v3 d v4 e v2 f v5 is a walk of the above mentioned graph


(Figure – 7.4.1)

Note : (i) Walk is also known as an edge train or chain.


(ii) No edge appears more than once in a walk.
(iii) A vertex may appear more than once in a walk.
(iv) Vertices with which a walk begins and ends are called its terminal vertices.
(v) A self loop may also be present in a walk.

Length of a walk : The number of edges present in a walk is the length of the walk.
For example, in the walk v3 d v4 e v2 f v5, of above mentioned graph (Figure – 7.4.1).
The length of the walk is 3.

Closed walk : If the starting and ending vertices of a walk are same vertices then the
walk is called a closed walk.
For example, the walk v2 b v3 d v4 e v2 of above mentioned graph (Figure – 7.4.1) is a
closed walk.

Open walk : If the starting and ending vertices of a walk are different then the walk is
called an open walk.
For example, the walk v3 d v4 e v2 f v5 of the above mentioned graph (figure – 7.4.1) is
an open walk.

19
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Path : An open walk in which no vertex appears more than once is called a path.
For example : v1 a v2 b v3 d v4 is a path of the above mentioned graph (Figure – 7.4.1)

Note : (i) A path is also called a simple path or an elementary path.


(ii) Self loop cannot be exists in path.
(iii) The terminal vertices of a path are of degree one and rest of the vertices,
known as intermediate vertices, are of degree two.
(iv) The degree is counted only with respect to the edge included in the path
and not the entire graph in which the path may contained.

Length of a path : The number of edges in a path is called the length of a path.
For example : Considering the path v1 a v2 b v3 d v4 of above mentioned graph
(Figure– 7.4.1), the length of path is 3.

Connected and disconnected graph : A graph G is said to be connected if there is at


least one path between every pair of vertices in G. A graph which is not connected is
called a disconnected graph.

Component : A disconnected graph consists of two or more connected graphs. Each of


these connected sub-graphs is called a component.

(Figure – 7.4.2)
Connected graph

(Figure – 7.4.3)
Disconnected graph with 2 components

20
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Circuit : A closed walk in which no vertex, except the initial and the final vertex appears
more than once is called a circuit.
For example : v2 b v3 d v4 e v2 is a circuit drawn from the above mentioned graph
(Figure – 7.4.1)

Note : (i) A circuit is also called a cycle, elementary cycle, circular path, polygon.
(ii) Every vertex of a circuit is of degree two.
(iii) Every self loop is a circuit but not every circuit is self loop.

(Figure – 7.4.4)
Different circuits

21
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.5 Euler graphs.

Euler graphs –Euler path, Euler Circuit – Definition and examples.

Euler Path : A path in a graph is said to be an Euler path if the path consists of all the
edges of the graph exactly once.

Euler Circuit : An Euler path which is a circuit is called an Euler circuit.

Euler graphs : If some closed walk in a graph contains all the edges of the graph, then
the walk is called an Euler line and the graph an Euler graph.

Note : (i) A walk is always connected. Since the Euler line contains all all the edges
of the graph, an Euler graph is always connected.
(ii) It is assumed that Euler graph do not have any isolated vertex.

(Figure – 7.5.1)
The above mentioned graphs (Figure – 7.5.1) are Euler Graphs.

22
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.6 Hamiltonian Graphs

Hamiltonian Graphs – Definition and example – Problems.

Hamiltonian graphs are named after Sir William Rowan Hamilton. He introduced the
problems of finding the circuit, which consists of all vertices of the graph exactly once.

Hamiltonian Circuit : A circuit in a connected graph G is said to be Hamiltonian


circuit, if it includes each vertex ov G exactly once, except the starting and ending
vertex that appears twice.
For example, the circuit v1 e1 v2 e3 v3 e4 v4 e5 v1 of the graph shown in Figure –
7.6.1(a) is Hamiltonian circuit.

Hamiltonian Graph : A connected graph G is said to be a Hamiltonian graph, if it has


a Hamiltonian circuit.

[Figure – 7.6.1(a)] [Figure – 7.6.1(b)]


The above mentioned graphs are Hamiltonian Graphs.

Hamiltonian Path : A simple path of a connected graph which contains all vertices of
the graph exactly once is called a Hamiltonian path.
For example, the path v1 e1 v2 e3 v3 e4 v4 of the graph shown in Figure – 7.6.1(a)
is Hamiltonian path.

Note : (i) A Hamiltonian circuit in a graph with n vertices has exactly n number of
edges.
(ii) All the edges of the graph may not be included in the Hamiltonian circuit.
(iii) A Hamiltonian circuit contains exactly two edges incident on a vertex.
(iv) A Hamiltonian path is obtained by removing one edge from a Hamiltonian
circuit.
(v) A graph consisting of Hamiltonian circuit also contains a Hamiltonian path.
(vi) A graph without having any Hamiltonian circuit may have Hamiltonian path

23
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.7 Sequential Representation of Graphs

Matrix Representation of Graphs : The matrix form of a graph is very convenient to


represent a graph for computer processing. Here we shall discuss two matrix
representations, Incidence Matrix and Adjacency Matrix.

Incidence matrix of a connected graph : Let G be a graph with n vertices, e edges


and no self loops. Define a n x e matrix A = [aij], whose n rows correspond to the n
vertices and the e columns correspond to e edges as follows :

Aij = 1, when edge ej incident on vertex vi


=0 otherwise.

Example 1: Find the incident matrix of the following graph.

Solution : The given graph has 6 vertices and 8 edges. So the incidence matrix is of
order 6 x 8. The required incidence matrix is given below.

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

24
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Example 2 : Draw the graph whose incidence matrix is

e1 e2 e3 e4 e5 e6 e7
v1 1 0 1 0 0 1 0

v2 1 1 0 0 0 0 0

v3 0 1 1 1 1 0 0

v4 0 0 0 1 1 1 1

v5 0 0 0 0 0 0 1

Solution : In the incidence matrix 5 rows correspond to 5 vertices and 7 columns


correspond to 7 edges. The graph will be :

Incidence matrix of a connected di-graph : The incidence matrix of a di-graph with


n vertices, e edges and no self loops is a n x e matrix A = [aij], whose n rows
correspond to the n vertices and the e columns correspond to e edges as
follows :

Aij = 1, when edge ej incident out of the vertex vi


= -1, when edge ej incident into the vertex vi
=0 otherwise.

25
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Example 3 : Find the incidence matrix of the following di-graph.

Solution : The given graph has 6 vertices and 8 edges. So the incidence matrix is of
order 6 x 8. The required incidence matrix is given below :

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

Example 4 : Draw the graph of the following incidence matrix.

e1 e2 e3 e4 e5 e6 e7
v1 1 0 1 0 0 0 -1

v2 -1 1 0 0 0 0 0

v3 0 -1 -1 1 0 0 0

v4 0 0 0 -1 1 -1 0

v5 0 0 0 0 -1 1 1

26
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Solution : The graph is given below :

Adjacency matrix of connected graph : The adjacency matrix of a graph G with n


vertices and no parallel edges is an n x n symmetric binary matrix X = [ xij] such that
Xij = 1, if there is an edge between vertices vi and vj
= 0, if there is no edge between them.

Example 5 : Find the adjacency matrix of the graph.

Solution : The required adjacency matrix is given below :

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

27
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Example 6 : Construct a graph whose adjacency matrix is given below :

X= 1 0 0 1

0 0 1 1

0 1 1 1

1 1 1 0

Solution : If the v1, v2, v3, v4 be the vertices of the graph G, then the matrix can be –

v1 v2 v3 v4
X(G) = v1 1 0 0 1

v2 0 0 1 1

v3 0 1 1 1

v4 1 1 1 0

The graph is given below :

Adjacency matrix of a connected di-graph : Let G be a di-graph with n vertices,


containing no parallel edges. Then the adjacency matrix X = [xij] of the di-graph G is an
n x n, matrix, whose elements are
Xij = 1, if there is an edge directed from vi to vj
= 0, otherwise

28
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Example 7 : Construct the adjacency matrix of the following di-graph.

Solution : The required adjacency matrix is given below.

1 2 3 4 5
1 0 0 1 1 0

2 1 1 0 0 0

3 0 0 0 0 1

4 0 0 0 0 0

5 0 1 1 0 0

29
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

7.8 Algorithms

Shortest Path, Shortest path algorithm – Dijkstra’s algorithm, Floyd-Warshall


algorithms – Problems. BFS algorithm-DFS

Shortest Path : The shortest path between a pair of vertices is the path of minimum
length among all paths between the pair of vertices.

Shortest path algorithm : There are several algorithms to find the shortest path
between two vertices in a connected weighted graph. Dijkstra’s algorithm and Floyd-
Warshall algorithms are the two important algorithms.

Dijkstra’s Algorithm : Dijkstra’s algorithms labels the vertices of the given graph. At
each stage in the algorithm some vertices have permanent labels and others temporary
labels. The algorithm begins by assigning a permanent label 0 to the starting vertex s
and a temporary label .∞ to the remaining n – 1 vertices.

From then on, in each iteration another vertex gets a permanent label, according to the
following rules.

1. Every vertex j that is not yet permanently labeled gets a new temporary label
whose value is given by
Min [ old label of j, (old label of I + dij) ]
Where i is the latest vertex permanently labeled, in the previous iteration and dij is
the direct distance between vertices I an j. If I and j are not joined by an edge,
then dij = .∞

2. The smallest value among all the temporary labels is found and this becomes the
permanent label of the corresponding vertex. In case of a tie, select any one of the
candidates for permanent labeling.

Steps 1 an 2 are repeated alternately until the destination vertex t gets a permanent
label.

30
E-CONTENTS : DISCRETE MATHEMATICS UNIT : GRAPH THEORY UNIT NO: 7

Floyd –Warshall Algorithm : Dijkstra’s algorithm is not suitable when our aim to find
the shortest distance between every pair of vertices in a connected weighted graph with
n vertices. There is another algorithm which determines the shortest distance between
every pair of vertices in a connected weighted graph. This algorithm is very popular
because of its simplicity. The algorithm is as follows.

Step 1 : If the graph contains any self loop discard it, If it contains parallel edges, then
discard all except that having the least weight.

Step 2 : For I = 1 to n, set d(I,i) = 0


For I ≠ j set d(I,j) = weight of the edge (vi,vj)
Set d(I,j) = ∞, otherwise.

Step 3 : For k = 1 to n
For I,j = 1 to n
Change d(I,j) by d(I,j) = min [d(I,j),d(I,k) + d(k,j)]

The final value of d(I,j) gives the shortest distance from vi to vj

31

You might also like