You are on page 1of 17

Module-03

Graph Theory

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


• Graph
A graph is a pictorial representation of a set of objects where some pairs of objects are
connected by links. The interconnected objects are represented by points termed
as vertices, and the links that connect the vertices are called edges.
Representation of Graph:
• a graph is a pair of sets (V, E), where V is the set of vertices and E is the set of
edges, connecting the pairs of vertices. Take a look at the following graph −

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


Degree of Vertex:
It is the no. of edges having a vertex as an end point and is denoted by deg(v)
where v is the vertex.
For e.g. Take a look at the following graph −

In the above Undirected Graph,


deg(a) = 2, as there are 2 edges meeting at vertex ‘a’.
deg(b) = 3, as there are 3 edges meeting at vertex ‘b’.
deg(c) = 1, as there is 1 edge formed at vertex ‘c’.
So ‘c’ is a pendent vertex.
deg(d) = 2, as there are 2 edges meeting at vertex ‘d’.
deg(e) = 0, as there are 0 edges formed at vertex ‘e’.
So ‘e’ is an isolated vertex.
Compiled by...Prof.Shaziya Shaikh,TIMSCDR
Loop :
In a graph, if an edge is drawn from vertex to itself, it is called a loop.
For e.g .

In the above graph, V is a vertex for which it has an edge (V, V) forming a loop.
Adjacent Vertices :
In a graph, two edges are said to be adjacent, if there is a common vertex
between the two edges. Here, the adjacency of edges is maintained by the
single vertex that is connecting two edges.

Where , ‘a’ and ‘b’ are the adjacent vertices, as there is a common edge ‘ab’
between them. Vise versa ..
Compiled by...Prof.Shaziya Shaikh,TIMSCDR
Parallel Edges :
In a graph, if a pair of vertices is connected by more than one edge, then those
edges are called parallel edges.

where ,‘a’ and ‘b’ are the two vertices which are connected by two edges ‘ab’ and
‘ab’ between them. So it is called as a parallel edge.
Adjacency Matrix :
A graph is represented using square matrix and Adjacency matrix of an
undirected graph is always a symmetric matrix, i.e. an edge (i, j) implies the edge
(j, i).

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


Adjacency List :
• A graph can also be represented using linked list For each vertex, a list of
adjacent vertices is maintained using a linked list. It creates a separate linked list
for each vertex Vi in
the graph G = (V, E).
• Adjacency list of a graph with n nodes can be represented by an array of pointers.
Each pointer points to a linked list of the corresponding vertex. Below figure
shows the adjacency list representation of a graph.

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


Question : Find 1) Degree of Vertices
2) Adjacency Matrix
3) Adjacency List
For following graphs.
1
1) 0 2

3
4

5 6
2)
b c d e

f
a

i g
h by...Prof.Shaziya Shaikh,TIMSCDR
Compiled
• Connected And Disconnected Graph

If a graph is disconnected then its pieces are called as Components.

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


• Path and Circuit in a Graph

Path :It is a sequence of vertices such that from each of its vertices
there is an edge to the next vertex in the sequence.
Simple Path : A path is simple if each Vertex is distinct.
Circuit : A path is Circuit in which the terminal vertex coincides with
initial vertex.
For Example consider the following graph

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


• Euler Paths and Euler Circuits
Euler Path :
An Euler path is a path that visits each vertex of graph and uses every
edge of the graph exactly once and starts and ends at different vertices.

Characteristics of Euler Path :


a) A graph will contain an Euler Path if it contains at most two vertices
of ODD Degrees.

b) If a graph is connected and has just two vertices of odd degrees then
is has at least one Euler Path and any such path must start at one of the
odd vertices and end at other odd vertex.

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


For Example, Consider the following graphs…
1)
Euler Path = e,b,c,d,b,a,c

2) D
B
C
Euler Path = C,B,A,C,D

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


Euler Circuit :
An Euler circuit is a an Euler path that uses every edge of graph with
NO REPEATS and being a circuit it must start and end at same vertex.

Characteristics of Euler Path :

a) If a graph has any vertex of ODD Degree then it cannot have Euler
Circuit.

b) If a graph is connected and every vertex is of Even degree then it has


at least one Euler Circuit.

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


For Example, Consider the following graphs…
1) Q
A B
Euler Circuit = A,P,D,S,C,R,B,Q,P,S,R,Q
P R

C
D S

2) D
B
C
Euler Circuit = C,B,A,C,E,D,C

A E

Compiled by...Prof.Shaziya Shaikh,TIMSCDR


Exercise: Find Euler path and Euler Circuit if Exist.
1)
B F

C E
A G

D H

2)
A B

C
G D

E
F
Compiled by...Prof.Shaziya Shaikh,TIMSCDR
• Hamilton (Hamiltonian) Path And Circuit
Hamilton Path :
A Hamilton Path is a path that visits every vertex exactly once but it
does not have to use every edge of G.
For e.g.
b
a

h e
d f g

c c

Here Hamilton path = a,h,c,d,e,b,g,c,f


Compiled by...Prof.Shaziya Shaikh,TIMSCDR
Hamilton Circuit :
A Hamilton circuit is a circuit that visits every vertex exactly once but
it does not have to use every edge of G and start and ends at the same
vertex.
For e.g.
b
a

h e
d f g

c i

Here Hamilton circuit is as follows


C = a,h,c,d,e,f,i,g,b,a Compiled by...Prof.Shaziya Shaikh,TIMSCDR
Excercise : Find Hamilton Path and Hamilton Circuit.
1)
c

i d
b h j

g f

a
e

2)

Compiled by...Prof.Shaziya Shaikh,TIMSCDR

You might also like