Graph Theory
By:Ms N. S. Khairnar
Graph Theory
● A graph G is an ordered pair (V,E) where V is the set of vertices and
E is the set of edges.
● Each edge is associated with an unordered pair (vi , vj). The vertices
vi & vj are called the end vertices or the terminal vertices of the edge
Eij.
Basic Terminology
● Incident : An edge is said to be incident with the vertices it joins.
● Adjacent :
○ Two vertices are said to be adjacent if they are joined by an edge.
○ Two edges are said to be adjacent if they are joined by common
vertices.
● Degree of Vertices: No. of edges incident on a particular vertex are
called degree of that vertex.
● Indegree & Outdegree: Number of edges incident on to a vertex &
number of vertex incident out of a vertex.
Basic Terminology..
● Loop: If the initial vertex vi and the terminal vertex vj are same for an
edge eij, then eij are called self loop or simply loop.
● Parallel edges: If there are more than one edges associated with a
given pair of vertices then those edges are called parallel edges or
multiple edges.
● Isolated Vertex: A vertex is said to be isolated vertex if no edge is
incident on it.
● Pendant vertex: A vertex with degree 1 is called a Pendant vertex.
Representation of graph
● Adjacent matrix.
● Incidence Matrix.
Adjacent Matrix
A B C D E
E
A 0 1 1 1 0 e
B 1 0 1 1 0 C
C 1 1 0 0 1 c
a g
D 1 1 0 0 1 B
b f
E 0 0 1 1 0
A d
D
Incidence Matrix for Undirected Graph
a b c d e
E
A 1 1 0 1 0 e
B 0 1 1 0 0 C
C 1 0 1 0 1 c
D 0 0 0 1 0 a g
E 0 0 0 0 1 B
b f
A d
D
Incidence Matrix for Directed Graph
Types of Graph
● Multigraph
● Pseudograph
● Directed Graph
● Weighted Graph
● Finite and Infinite Graph
● Null Graph
● Simple Graph
● Complete Graph
● Regular Graph
● Bipartite Graph
● Complete Bipartite Graph
● Acyclic Graph, Trivial Graph
Multigraph, Pseudograph
● A Multigraph is a graph which is permitted to have multiple
edges/parallel edges.
● Self Loops are not allowed in Multigraph.
● A Pseudograph allows Self Loops as well.
● Following figure represents Pseudograph.
Directed Graph
● A directed graph G is defined as an ordered pair (V,E) ,where V is the
set of vertices and E is the set of edges.
● Each edge or arc ek ={vi,vj} is represented by an arrow ,starting from
initial point vi to the terminal point vj.
Weighted Graph
A graph G is said to be a weighted graph if each edge of
the graph is assigned with some positive real number
(w),called the weight.
Finite and Infinite Graph
● A graph with finite number of edges & vertices is called as Finite Graph.
● A graph with infinite number of edges & vertices is called as Infinite Graph.
Null Graph
If the edge set of any graph G with n vertices is an
empty set then the graph is called a null graph.
Simple Graph
● A simple graph is a graph that does not have more than one edge
between any two vertices and no edge starts and ends at the
same vertex.
● In other words a simple graph is a graph without loops and
multiple edges.
● Total no of edges =At most, n(n-1)/2
Complete Graph
● A Simple graph G is called a complete graph if every vertex
in G is connected with every other vertex.
● Degree of each vertex should be n-1.
● Denoted by Kn
● Total no of edges =Exactly n(n-1)/2
Regular Graph
● If degree of all the vertex of a graph G is same
say ”d” then it is called regular graph.
● Every Complete graph Kn is a regular graph
of degree n-1 but vice versa is not true
Bipartite Graph
● A graph whose vertices can be divided into two disjoint and independent
sets U and V , that is every edge connects a vertex in U to one in V.
Are these Bipartite Graphs?
Yes
Complete Bipartite Graph
● A special kind of bipartite graph where every vertex of the
first set is connected to every vertex of the second set.
● Denoted by Kmn
● Total number of edges =m*n ,
Acyclic ,Trivial Graph
● Acyclic Graph : A graph without cycle is called
acyclic.
● Trivial Graph : A graph with single vertex and no
edges are called trivial graph.
Complement of a subgraph
Complement of a subgraph G’(V’,E’) with
respect to the graph G is another G’’(V’’,E’’)
such that E’’=E-E’ and V’’ contains only those
vertices with which the edges in E’’ are incident.
Subgraph
● If G(V,E) be any graph then a graph
G’(V’,E’) is said to be a subgraph of G if
E’ ⊆ E and V’ ⊆ V.
● Edge disjoint subgraph: No common
edge in two subgraph .
● Vertex disjoint subgraph : No common
vertex in two subgraph.
Spanning Subgraph
Spanning subgraph has all the vertices from
main graph.
Factors of a Graph
● A k-factor of a graph is defined to be a spanning subgraph
of the graph with the degree of each of its vertex being k.
1 factor:
Graph G:
2 Factor:
Isomorphic Graph
● Two graphs are said to be isomorphic if there is one to
one correspondence between their vertices and their
edges such that incidencies & adjacency are preserved.
● Must have condition for isomorphism:
i) Same no. of vertices
ii) Same no. of edges
iii) Same no. of vertices with a given degree.
iv) Adjacency should be preserved.
Example
• f(a) = 1
• f(b) = 6
• f(c) = 8
• f(d) = 3
• f(g) = 5
• f(h) = 2
• f(i) = 4
• f(j) = 7
Example
Q: Find whether K6 & K3,3 are isomorphic or not ?
Operations on Graph
● Union: If G1(V1,E1) and G2(V2,E2) are two graphs then
union G3=G1UG2,whose vertex set is V3= V1UV2 and
edge set E3 = E1UE2.
● Intersection: If G1(V1,E1) and G2(V2,E2) are two graphs
then intersection G3=G1ΠG2,whose vertex set is V3= V1
Π V2 and edge set E3 = E1 Π E2.
● Ring sum: If G1(V1,E1) and G2(V2,E2) are two graphs
then ringsum G3=G1⊕G2,whose vertex set is V3= V1 ⊕
V2 and edge set E3 = E1 ⊕ E2.
Union
Ring Sum
Intersection
Complement of A Graph
● Complement of a graph: Complement of a graph
G, denoted by G’ is the graph whose vertex set
are same as the vertex set of G but two vertex
are adjacent if they are not adjacent in G.
● Complement of a complete graph is always null
graph.
Find Complement of Following Graphs
Self Complementary Graph
● A Graph is said to be self complementary graph
if it is isomorphic to its complement.
G Complement
G
Handshaking Lemma
The sum of the degree of all vertices in a graph
G is twice the number of edges.
Example
Q. How many nodes are necessary to construct a graph with exactly
8 edges in which each node is of degree 2?
Solution:
Given: e=8
d=2
v=?
According to Handshaking Lemma, ∑ d(vi)=2e
v*2=2*8
v=16/2
v=8
Example
Q Find number of edges in a graph with 6 nodes, 2 of degree 4
and 4 of degree 2.
Solution:
Given: e=?
v=2 of degree 4, 4 of degree 2.
According to Handshaking Lemma, ∑ d(vi)=2e
(2*4)+(4*2)=2e
2e=16
e=8
Example
Q State whether it is possible to construct a
simple graph with 7 nodes and 14 edges?
Solution:
● A simple graph with n vertices has at most n(n-1)/2
edges.
● Here n=7 so maximum no of edges are 7*6/2= 21
● So it is possible to draw a graph with given conditions
Example
Q. Show that number of edges in a Complete graph
with n vertices is n(n-1)/2.
Solution:
● According to Handshaking Lemma, ∑ d(vi)=2e
● In a complete graph with n vertices every vertex
has degree (n-1).
● n(n-1)=2e
● e=n(n-1)/2
Planar graph
A Graph G is said to be a planar graph if it can
be drawn on a plane without intersecting the
edges except at the common vertices.
Planar graph..
Yes the Graph is a planner Graph
Planar graph..
No the Graph is not a planner Graph
Euler’s Formula.
For any connected planar graph v-e+r=2
v= no. of vertices.
e= no. of edges.
r= no. of regions.
● Theorem1: If G(V,E) is a simple connected graph
then e ≤ 3v-6
● Theorem2: e ≤ 2v-4
Examples
Are K5 , K6 and K3,3 are planar ?
No
Paths & Circuit
● Path: Let G=(V,E) be any graph and let V0 and Vnbe any two vertices in V.
A path of length n from V0 to Vn is a sequence of vertices & edges of the
form(v0,e1,v1,e2…..envn) where each edge ej is an edge between Vj-1 & vj .The
vertices Vo & Vn are called the end vertices & remaining are called interior
vertices.
● Simple path : No repetition of edges.
● Elementary path: No repetition of vertices .
Paths & Circuit..
● Circuit: A path becomes a circuit if vo=vn
C=(v0 ,e1,v1,…..vn)
● Simple Circuit: No repetition of edges.
● Elementary circuit: No repetition of vertices
Eulerian paths & Ckt.
● A path is called an eulerian path if every edge of the graph G appears
exactly once in the path.
● A circuit which contains every edge of the graph G exactly once is
Eulerian ckt.
No Eulerian Path, No Eulerian Circuit Exists
Theorems
● A graph contains an eulerian path if and only if it is connected and has either
zero or two vertices of odd degree.
● A graph contains an eulerian ckt if and only if it is connected and its all
vertices are of even degree.
● Directed Graph possess an eulerian path, iff the incoming degree of every
vertex is equal to outgoing degree with the possible exception of 2 vertices, for
these two vertices indegree of one is 1 more than its outgoing degree and the
incoming degree of other is one less than its outgoing degree.
● A directed graph contains an eulerian ckt if it is connected and the incoming
degree of every vertex is equal to outgoing degree .
Does Following graph posses an Eulerian Path and Circuit?
Sr Vertex Degree Remark Eulerian Path: Exists
No
DBADCFAGFECB
1 A 4 even
Eulerian Circuit: Does not Exist
2 B 3 odd
3 C 4 even
4 D 3 odd
5 E 2 even
6 F 4 even
7 G 2 even
Does Following graph posses an Eulerian Path and Circuit?
Vertex Degree Remark
Eulerian Path: Exists
1 4 even 261524132
2 4 even
3 2 even
Eulerian Circuit: Exists
4 2 even
261524132
5 2 even
6 2 even
Exercise
Under what condition Kmn(Complete bipartite
graph) will have an eulerian ckt ?
Case1: m=n & both are even.
Case2: m=n & both are odd.
Case3: m≠n & both are even.
Case4: m≠n & both are odd.
Case5: m ≠n & one is even,one is odd.
Hamilton paths & Ckt
● A path in a connected graph G is a hamilton path if it visit every vertex G exactly
once.
● A circuit in a connected graph G is called a hamilton circuit if it visit every vertex of G
exactly once.
● Theorem1: If the sum of the degree for each pair of vertex is ≥ n-1, then there exist a
hamilton path.
● Theorem2: If the degree of each vertex in G ie d(v) ≥ n/2 , then G will contain hamilton
circuit.
● Note: There are no necessary and sufficient conditions for Hamiltonian Path and
Circuit.
Exercise
● Find a hamilton path and a hamilton circuit in
K4,3 .
● It has a hamilton path but not the hamilton ckt.
Nearest Neighbour Method to find Hamiltonian Circuit.
Coloring of a Graph.
One of the main way is to color the vertices of G such
that no two adjacent vertices have the same color.
Chromatic number: The chromatic number of a graph G is
the minimum number of colors required for the proper
coloring of the graph G.
In this case =3
This graph is called 3- chromatic
Null Graph Colouring
Null Graph is 1 Chromatic
Complete Graph Colouring
Complete Graph Kn is n Chromatic
K4 needs 4 colours K3 needs 3 colours
Complete Bipartite Graph Colouring
Complete Bipartite Graph Km,n is 2 Chromatic
Simple Graph with one circuit
n= even, 2 Chromatic
n= odd, 3 Chromatic
Wheel Graph
A wheel graph is a graph formed by connecting a single universal vertex
to all vertices of a cycle.
Wheel Graph with even vertices
1 1
4 5
4
2
2 3
3
n= even, 4 Chromatic n= odd, 3 Chromatic
Shortest path algorithm
Assumptions:
● Let G(V,E) be a simple connected graph .
● Let a and z be two vertices of the graph.
● L(x) denote the label of vertex x which represent the length of the shortest
path from vertex a to vertex x.
● Wij denote the weight of the edge eij=(vi,vj)
Dijkstra’s Algorithm
● Step1: P is the set of those vertices which have the permanent labels, T is total
vertices in a graph, a is starting vertex and z is destination so
P={Φ}
T= { all vertices of graph G}
L(a)=0 ,
L(x) =∞, ∀ x ∈ T and x ≠ a.
● Step 2: Select the vertices v in T which has the smallest labels. This label will be the
permanent label of v.
Set P=PU{v} and T =T-{v}
For the remaining vertices in T find shortest path from a.
If v=z ,then L(z) is the length of the shortest path from the vertex a to z and
stop.
Dijkstra’s Algorithm
● Step3: If v ≠ z,then revise the labels of vertices of T. The new label of a
vertex x in T is given by
L(x) =min{old L(x) , L(v) + w(v,x)}
Where w(v,x) is the weight of the edge joining the vertex v and x.
If no direct edge then w(v,x)= ∞
● Step 4: Repeat step 2 & step 3 until z gets the permanent label.
Example
Find Shortest path from a to z Step:1
P={Φ}
T={a,b,c,d,e,f,z}
L(a)=0
L(x)=∞, ∀ x ∈ T and x ≠ a.
Step:2, v=a , L(a)=0
Find Shortest path from a to z P={a}
T={b,c,d,e,f,z}
L(b)= min{old L(b) , L(a)+w(a,b)} L(b)=min{∞,0+22}= 22 22
L(b)=min{∞,0+22}=
L(c)= min{old L(c) , L(a)+w(a,c)} L(c)=min{∞,0+1}= 1 Min
L(d)= min{old L(d) ,L(a)+w(a,d)} L(d)=min{∞,0+8}= 8
L(e)= min{old L(e) , L(a)+w(a,e)} L(e)=min{∞,0+∞}= ∞
L(f)= min{old L(f) , L(a)+w(a,f)} L(f)=min{∞,0+∞}= ∞
L(z)= min{old L(z) , L(a)+w(a,z)} L(z)=min{∞,0+∞}= ∞
Step:3, v=c , L(c)=1
Find Shortest path from a to z P={a,c}
T={b,d,e,f,z}
L(b)= min{old L(b) ,L(c)+w(c,b)} L(b)=min{22,1+6}= 7
L(d)= min{old L(d) ,L(c)+w(c,d)} L(d)=min{8,1+10}= 8
L(e)= min{old L(e) ,L(c)+w(c,e)} L(e)=min{∞,1+4}= 5
L(f)= min{old L(f) ,L(c)+w(c,f)} L(f)=min{∞,1+3}= 4 Min
L(z)= min{old L(z) ,L(c)+w(c,z)} L(z)=min{∞,1+10}= 11
Step:3, v=f , L(f)=4
Find Shortest path from a to z P={a,c,f}
T={b,d,e,z}
L(b)= min{old L(b) , L(f)+w(f,b)} L(b)=min{7,4+7}= 7
L(d)= min{old L(d) ,L(f)+w(f,d)} L(d)=min{8,4+6}= 8
L(e)= min{old L(e) ,L(f)+w(f,e)} L(e)=min{5,4+∞}= 5 Min
L(z)= min{old L(z) ,L(f)+w(f,z)} L(z)=min{11,4+9}= 11
Step:3, v=e , L(e)=5
Find Shortest path from a to z P={a,c,f,e}
T={b,d,z}
L(b)= min{old L(b) , L(e)+w(e,b)} L(b)=min{7,5+2}= 7 Min
L(d)= min{old L(d) ,L(e)+w(e,d)} L(d)=min{8,5+∞}= 8
L(z)= min{old L(z) ,L(e)+w(e,z)} L(z)=min{11,5+9}= 9
Step:3, v=b , L(b)=7
Find Shortest path from a to z P={a,c,f,e,b}
T={d,z}
L(d)= min{old L(d) ,L(b)+w(b,d)} L(d)=min{8,7+∞}= 8 Min
L(z)= min{old L(z) ,L(b)+w(b,z)} L(z)=min{9,7+2}= 9
Step:3, v=d , L(d)=8
Find Shortest path from a to z P={a,c,f,e,b,d}
T={z}
L(z)= min{old L(z) ,L(d)+w(d,z)} L(z)=min{9,8+∞}= 9 Min
Step:3, v=z , L(z)=9
Find Shortest path from a to z P={a,c,f,e,b,d,z}
T={ }
Shortest Path from a to z is a-c-e-z with
path value=9
Example for Classwork
Find Shortest path from a to z
Shortest Path from a to z is 7
Example for Homework
Find Shortest path from a to z
Shortest Path from a to z is 13
Some observations
✔ A graph which has only isolated vertex has K(G)=1.
✔ A graph with one or more edges (Without a self loop) has a minimum
K(G)=2.
✔ A graph consisting of simply one circuit with n≥3 vertices has K(G)=2 if
n is even and K(G)=3 if n is odd.
✔ Every tree with two or more vertices has K(G)=2.
✔ If d is the maximum degree of the vertices in a graph G,then K(G)≤ d+1
Applications of graph Theory
● Konigsberg Bridge Problem:
Start from any four land area walkover the seven bridges exactly once.
B
B
A D A D
D C
Vertices represent the land area and edges represent the bridge.
Euler prove that solution of this problem does not exist.
Applications of graph Theory
● Utility problem: Three houses H1 ,H2,H3 & three utilities
W ,G & E.Is it possible to provide such a connection
without any crossover.
● This graph can’t be drawn on a plane without crossing
the edges.
Thank You!!