2. Unit IV: Course Content
Graph Terminology and Special Types of Graphs, Representing Graphs and Graph Isomorphism, Connectivity, Euler
and Hamilton Paths, the handshaking lemma, Single source shortest path Dijkstra's Algorithm, Planar Graphs, Graph
Coloring.
#Exemplar/Case Studies: Three utility problem, Web Graph, Google map.
Number of Credit: 03
Number of Lecture Hr: 06
12/8/2021 Dr. Kailash Shaw 2
3. Learning Resources
Text Books:
• 1. C. L. Liu, “Elements of Discrete Mathematics”‖, TMH, ISBN 10:0-07-066913-9.
• 2. N. Biggs, “Discrete Mathematics”, 3rd Ed, Oxford University Press, ISBN 0 –19-850717–8.
Reference Books:
1. Kenneth H. Rosen, “Discrete Mathematics and its Applications”‖, Tata McGraw-Hill, ISBN 978- 0-07-288008
2. Bernard Kolman, Robert C. Busby and Sharon Ross, “Discrete Mathematical Structures”‖, Prentice-Hall of
India /Pearson, ISBN: 0132078457, 9780132078450.
3. Narsingh Deo, “Graph with application to Engineering and Computer Science”, Prentice Hall of India, 1990,
0 – 87692 – 145 – 4.
4. Eric Gossett, “Discrete Mathematical Structures with Proofs”, Wiley India Ltd, ISBN:978-81- 265-2758
5. Sriram P.and Steven S., “Computational Discrete Mathematics”, Cambridge University Press, ISBN 13: 978-0-
521-73311-3.
12/8/2021 Dr. Kailash Shaw 3
4. Resources
12/8/2021 Dr. Kailash Shaw 4
Topic Expected discussed
in Lecture
Self Learning For
Student
Reference Number of
contact Hrs
1 Graph Terminology
and Special Types
of Graphs
Definition
Directed Graph,
Undirected Graph:
Simple Graph, Multi
Graph, Pseudo
Graph, Simple
Directed Graph,
Directed Multigraph,
Mixed Graph
Graph Modals:
Social Network,
Information
Network,
Communication
Network, Software
design Application,
Transportation
Network, Biological
Network,
Tournaments
Kenneth H. Rosen ||
Narsingh Deo
2
5. Resources
12/8/2021 Dr. Kailash Shaw 5
Topic Expected discussed
in Lecture
Self Learning For
Student
Reference Number of
contact Hrs
2 Representing
Graphs and Graph
Isomorphism
Representing
Graph, Adjacency
Matrix, Incidence
matrix, Adjacency
List,
Isomorphism of
graph.
Solve Exercise
Question
Kenneth H. Rosen ||
Narsingh Deo
1
6. Resources
12/8/2021 Dr. Kailash Shaw 6
Topic Expected discussed
in Lecture
Self Learning For
Student
Reference Number of
contact Hrs
3 Connectivity Path, Circuit,
Connectedness in
Undirected and
Directed Graph,
Vertex cut, Edge
Cut,
Counting Paths
Between Vertices
Paths in
Acquaintanceship
Graphs , Paths in
Collaboration
Graphs ,
The Strongly
Connected
Components of
the Web Graph
Kenneth H. Rosen ||
Narsingh Deo
1
7. Resources
12/8/2021 Dr. Kailash Shaw 7
Topic Expected discussed
in Lecture
Self Learning For
Student
Reference Number of
contact Hrs
4 Euler and Hamilton
Paths
Euler Paths and
Circuits,
CONDITIONS FOR
EULER CIRCUITS
AND PATHS,
APPLICATIONS OF
EULER PATHS AND
CIRCUITS,
Hamilton Paths and
Circuits,
CONDITIONS FOR
THE EXISTENCE OF
HAMILTON
CIRCUITS ,
Applications
Multigraph model
Of the town of
Konigsberg,
Solve various
Exercise Question
Kenneth H. Rosen ||
Narsingh Deo
1
8. Resources
12/8/2021 Dr. Kailash Shaw 8
Topic Expected discussed
in Lecture
Self Learning For
Student
Reference Number of
contact Hrs
5 Single source
shortest path
Dijkstra's
Algorithm(DA)
Shortest path
Algorithms,
Single Source
Shortest Path DA,
Travelling sales
Man problem,
Solve Exercise
question on Single
source shortest
path DA.
Kenneth H. Rosen ||
Narsingh Deo
1
9. Resources
12/8/2021 Dr. Kailash Shaw 9
Topic Expected discussed
in Lecture
Self Learning For
Student
Reference Number of
contact Hrs
6 Planar Graph,
Graph Coloring
Definition and
Theorem.
Application of
Graph Coloring
Problem
Formulate
Question that can
be solved using
Graph Coloring.
Kenneth H. Rosen ||
Narsingh Deo
1
10. Resources
12/8/2021 Dr. Kailash Shaw 10
Topic Expected discussed
in Lecture
Self Learning For
Student
Reference Number of
contact Hrs
7 Three utility
problem,
Web Graph,
Google map
Definition and
relate with Subject.
Formulate
Question that can
be related to any
out of these
topics.
Kenneth H. Rosen ||
Narsingh Deo
Extra
11. Graph Terminology and Special Types of Graphs
Definition: Graph G =(V, E)
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.
Undirected Graph
edge(u, v) = edge(v, u)
In figure of undirected graph:
V={1, 2, 3, 4}
E={(1, 2), (1, 3), (2, 1), (2, 3), (3,1), (3, 2),(3, 4), (3,3)}
In a directed graph
Edge<u, v> goes from vertex u to vertex v, notated u -> v
Edge<u, v> Not Equal to Edge <v, u>
V={1, 2, 3, 4}
E={<1, 2>, <1, 3>, <2, 3>, <3, 4>}
1
3
2
4
1
3
2
4
12/8/2021 Dr. Kailash Shaw 11
12. Graph Terminology and Special Types of Graphs
2
4
3
1
5
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.
Example: g is self loop
Parallel edges: If there are more than one edges associated with a given pair of
vertices.
Example: e and f are parallel edges
Isolated Vertex: A vertex is said to be isolated vertex if no edge is incident on it.
Example: Vertex 6 is isolated vertex
Pendant vertex: A vertex with degree 1 is called a Pendant vertex.
Example: Vertex 7 is Pendant
Incident : An edge is said to be incident with the vertices it joins.
Example: a and b are incident on Vertex 1.
Adjacent : Two vertices are said to be adjacent if they are joined by an edge.
Example: Vertex 1 and 2 are adjacent vertex
Degree of Vertices: No. of edges incident on a particular vertex are called degree
of that vertex.
Example: Vertex 4 has degree 4.
a
e
d
c
b
g
f 6
7
12/8/2021 Dr. Kailash Shaw 12
13. Graph Terminology and Special Types of Graphs
Indegree & Outdegree: Number of edges incident on to a vertex & number of vertex incident out of a vertex.
1
2
c
a b
3
Vertex Indegree Outdegree
1 1 1
2 1 2
3 1 0
Let G = (V, E) and v∈V.
The indegree of v is denoted deg−(v) and its outdegree is denoted deg+(v).
A vertex with deg−(v) = 0 is called a source, as it is the origin of each of its
outcoming arrows. Similarly, a vertex with deg+(v) = 0 is called a sink
The degree sum formula states that, for a directed graph.
If for every vertex v∈V, deg+(v). = deg−(v), the graph is called a balanced directed graph.
Sum of degree of all vertex is 𝒗∈𝑽 𝒅𝒆𝒈(𝒗) = 𝟐|𝑬|
𝑣∈𝑉
𝑑𝑒𝑔−
(𝑣) =
𝑣∈𝑉
𝑑𝑒𝑔+
(𝑣) = |𝐸|
12/8/2021 Dr. Kailash Shaw 13
14. Graph Terminology and Special Types of Graphs
1
2
c
a b
3
Path is a sequence of alternating vertex and edges such that each successive vertex is
connected by the edge.
Example: 1-a-2-b-1-d-4 is a path
Cycle is a path that starts and end at the same vertex.
Example: 1a2b1 is a cycle
Simple path is a path with distinct vertices.
Example: 1-a-2-c-3 is a simple path. Note Path 1-a-2-b-1-d-4 is not simple because it
contains vertex twice.
4
d
12/8/2021 Dr. Kailash Shaw 14
15. Graph Terminology and Special Types of Graphs
Weighted Graph If each edge in the graph carries a value, then the graph
is called weighted graph
A weighted graph is a graph G = (V, E, W), where each edge, e ∈ E, E
is assigned a real valued weight, W(e).
2
4
3
1
5
2
3
1
5
4
6
Complete Graph A complete graph is a graph with an edge between
every pair of vertices.
A graph is called complete graph if every vertex is adjacent to
every other vertex.
Denoted by Kn : Total no of edges =n(n-1)/2
Trivial Graph : A graph with single vertex and no edges are called
trivial graph.
2
4
3
1
1 1 2 2 3
1
k1 k2 k3 k4
12/8/2021 Dr. Kailash Shaw 15
16. Graph Terminology and Special Types of Graphs
Regular Graph :If degree of all the vertex of a graph G is same say “d” then it is called regular graph.
4
3
1
2
3
4
2
Graph: S is a Regular Graph
Deg(V1)=Deg(V2)=Deg(V3)=Deg(V4)=2
But it is not Complete Graph because
all vertex are not connected with all other vertex.
Graph: G is a Regular Graph
Deg(V1)=Deg(V2)=Deg(V3)=Deg(V4)=3
Graph G Is also Complete Graph as All Vertex
are connected to all other vertex.
1
Every Complete graph Kn is a regular graph of degree n-1 but vice versa is not true
12/8/2021 Dr. Kailash Shaw 16
17. Graph Terminology and Special Types of Graphs
Multi Graph : In mathematics, and more specifically in graph theory,
a multigraph is a graph which is permitted to have multiple edges (also called
parallel edges), that is, edges that have the same end nodes. Thus two vertices
may be connected by more than one edge
Bipartite Graph : bipartite graph is a graph whose vertices can be
divided into two disjoint and independent sets and such that every
edge connects a vertex in to one in. Vertex sets and are usually called
the parts of the graph.
V={A,B,C,D} can be grouped as V={V1, V2} where V1={A,C} and
V2={B, D}
V1 U V2= V
V1 Π V2= ф
Complete bipartite Graph : if each vertex of V1 is joined to every
vertex of V2 by an unique edge.
Denoted by Kmn
Total number of edges =m*n ,
Regular graph if m=n
12/8/2021 Dr. Kailash Shaw 17
18. Graph Terminology and Special Types of Graphs
Sub Graph :A Subgraph S of a graph G is a graph whose vertex set V(S) is a subset of the vertex set V(G),
that is V(S)⊆V(G), and whose edge set E(S) is a subset of the edge set E(G), that is E(S)⊆E(G)
4
3
1
2 3
1
2
Graph: S is a Sub Graph of G
Graph: G
12/8/2021 Dr. Kailash Shaw 18
19. connected graph: any two vertices are connected by some path
An undirected graph is connected if, for every pair of vertices u and v there is a path from u to v.
Graph Terminology and Special Types of Graphs
3
1
2
5
4
3
1
2
5
4
Not Connected Graph Connected Graph
12/8/2021 Dr. Kailash Shaw 19
20. Strongly Connected Directed Graph is strongly connected if, for every pair of vertices u and v there is
a path from u to v.
A strongly connected digraph is a directed graph in which it is possible to reach any node starting
from any other node by traversing edges in the direction(s) in which they point.
Graph Terminology and Special Types of Graphs
3
1
2
5
4
Strongly Connected Graph
12/8/2021 Dr. Kailash Shaw 20
22. Adjacency Matrix
Let assume a graph having vertex V= {1, 2,…, n}
o An Adjacency matrix “A” represents the graph as a n x n matrix
3
1
2
5
4
1
2
3
4
5
2 1 1 0 0
1
1
0
0
0
1
1
0
1
0
0
1
1
0
0
1
0
1
1
0
1 2 3 4 5
𝐴 𝑖, 𝑗 =
1
0
𝑖𝑓 𝑒𝑑𝑔𝑒 𝑖, 𝑗 ∈ 𝐸(𝑜𝑟 𝑤𝑒𝑖𝑔ℎ𝑡 𝑜𝑓 𝑒𝑑𝑔𝑒)
𝑖𝑓 𝑒𝑑𝑔𝑒 𝑖, 𝑗 ∈ 𝐸
Self loop will be
counted as 2
Undirected Graph
12/8/2021 Dr. Kailash Shaw 22
23. Adjacency Matrix
The adjacency matrix of a directed graph can be asymmetric. One can define the adjacency matrix of a
directed graph either such that
a non-zero element Aij indicates an edge from i to j or
it indicates an edge from j to i.
3
1
2
5
4
1
2
3
4
5
1 1 1 0 0
0
0
0
0
0
0
0
0
1
0
0
1
1
0
0
0
0
0
1
0
1 2 3 4 5
Self loop will be
counted as 1
Directed Graph
12/8/2021 Dr. Kailash Shaw 23
24. Incidence Matrix
The incidence matrix of a graph G is a |V| ×|E| matrix. The element aij= the number of times that vertex
vi is incident with the edge ej.
3
1
2
5
4
1
2
3
4
5
1 1 1 0 0 0 0
0
0
0
0
1
0
0
0
0
1
0
0
1
1
0
0
1 0 0
0 0 1
1 1 0
0 1 1
𝑎 𝑏 𝑐 𝑑 𝑒 𝑓 𝑔
𝐴 𝑖, 𝑗 =
1
0
𝑖𝑓 𝑣𝑖 𝑖𝑠 𝑖𝑛𝑐𝑖𝑑𝑒𝑛𝑡 𝑤𝑖𝑡ℎ 𝑒𝑑𝑔𝑒 𝑒𝑗
𝑖𝑓 𝑒𝑑𝑔𝑒 𝑖, 𝑗 ∈ 𝐸
Undirected Graph
a
c
b
d
f
g
e
12/8/2021 Dr. Kailash Shaw 24
25. Incidence Matrix
The incidence matrix of a graph G is a |V| ×|E| matrix. The element aij= the number of times that vertex
vi is incident with the edge ej.
1
2
3
4
5
0
0
0
0
0
1
−1
0
0
0
1
0
−1
0
0
0
1
−1
0
0
0
1
0
−1
0
0
0
0
1
−1
0
0
−1
0
1
𝑎 𝑏 𝑐 𝑑 𝑒 𝑓 𝑔
𝐴 𝑖, 𝑗 =
1
−1
0
𝑖𝑓 𝑣𝑖 𝑖𝑠 𝑠𝑜𝑢𝑟𝑐𝑒 𝑓𝑜𝑟 𝑒𝑑𝑔𝑒 𝑒𝑗
𝑖𝑓 𝑣𝑖 𝑖𝑠 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛 𝑓𝑜𝑟 𝑒𝑑𝑔𝑒 𝑒𝑗
𝑂𝑡ℎ𝑒𝑟 𝑤𝑖𝑠𝑒
Directed Graph
3
1
2
5
4
a
c
b
d
g
e
f
Self loop will be
counted as 0
12/8/2021 Dr. Kailash Shaw 25
26. Few Question
How much storage does the adjacency matrix require?
Answer: O( IV12 )
O(IVI) time to find vertex degree and/or vertices adjacent to a given vertex
What is the minimum amount of storage needed by an adjacency matrix representation of an undirected
graph with 4 vertices?
Answer: |V| = n than minimum Storage required is n*(n-1)/2 = 6
Note: For Undirected Graph Matrix is symmetric
No Self loop indicates that diagonal is also not required.
The adjacency matrix is a dense representation
Usually too much storage for large graphs
But can be very efficient for small graphs
Most large interesting graphs, are sparse
For this reason the adjacency list is often a more appropriate representation
12/8/2021 Dr. Kailash Shaw 26
27. Adjacency List
Adjacency list: for each vertex v ∈ V, store a list vertices adjacent to v,
Directed Graph
3
1
2
5
4
a
c
b
d
g
e
f
Adjacency Set
Adj[1] = {1,2,3}
Adj[2] = {3,4}
Adj[3] = {∅}
Adj[4] = {5}
Adj[5] = {3}
Null
1
3
5 Null
3 Null
2
4 Null
1
2
3
4
5
3 Null
12/8/2021 Dr. Kailash Shaw 27
28. Adjacency List
How much storage is required?
o The degree of a vertex v = # incident edges
Directed graphs have in-degree, out-degree
o For directed graphs:
Number of items in adjacency lists is 𝑜𝑢𝑡𝑑𝑒𝑔𝑟𝑒𝑒 𝑣 = |𝐸|
Takes ɵ(V + E) storage
o For undirected graphs:
Number of items in adjacency lists is 𝑑𝑒𝑔𝑟𝑒𝑒 𝑣 = 2|𝐸|
Takes ɵ(V + E) storage
o So: Adjacency lists take Q(V + E) storage
12/8/2021 Dr. Kailash Shaw 28
29. Isomorphic Graph
Two graphs are said to be isomorphic if there is one to one correspondence between their vertices and their
edges such that incidences & 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) If a cycle of length k is formed by the vertices { v1 , v2 , ….. , vk } in one graph, then a cycle of same length k
must be formed by the vertices { f(v1) , f(v2) , ….. , f(vk) } in the other graph as well.
Both The graph are Isomorphic
Both The graph are Isomorphic
12/8/2021 Dr. Kailash Shaw 29
30. Isomorphic Graph
Q. Show that two different graphs shown in Figure are actually isomorphic?
Solution : For isomorphism Both graph must satisfy the below 4 condition.
i) Same no. of vertices: |VG| = |VS| = 4
ii) Same no. of edges: |EG| = |ES| = 3
iii) Same no. of vertices with a given degree.
deg(a) = 2, deg (b) = 2, deg(c) = 1, and deg (d) =1
deg(u) = 2, deg (v) = 2, deg(x) = 1, and deg (w) =1
iv) Formally a bijection between vertices is
f(a) = u,
f(b) = v,
f(c) = x
f(d) = w
and between edges is
ab↔uv,
ac↔ux,
bd↔vw
Using this bijection we can successfully `sit' the right graph on top of the left graph so
that edges sit on the top of edges. Hence Both the graph are isomorphism.
Graph G
Graph S
12/8/2021 Dr. Kailash Shaw 30
31. Planar graph
In graph theory, a planar graph is a graph that can be embedded in the plane, i.e., it can be drawn on the plane
in such a way that its edges intersect only at their endpoints. In other words, it can be drawn in such a way that
no edges cross each other.
For example consider the complete graph K4 and its two possible planar representations
Example – Is the hypercube Q3 planar?
12/8/2021 Dr. Kailash Shaw 31
32. Region
Region of a Graph: Consider a planar graph G=(V,E). A region is defined to be an area of the plane that is
bounded by edges and cannot be further subdivided. A planar graph divides the plans into one or more regions.
One of these regions will be infinite.
Finite Region: If the area of the region is finite, then that region is called a
finite region.
Infinite Region: If the area of the region is infinite, that region is called a
infinite region. A planar graph has only one infinite region.
Example: Consider the graph shown in Fig. Determine the number of
regions, finite regions and an infinite region.
Solution:
There are five regions in the above graph, i.e. r1,r2,r3,r4,r5.
There are four finite regions in the graph, i.e., r2,r3,r4,r5.
There is only one infinite region, i.e., r1
12/8/2021 Dr. Kailash Shaw 32
33. Region
Q. Consider the graph shown in Fig. Determine the number of regions, finite regions and an infinite region.
r1
r2
r3
r4
r5
r6
There are a total of 6 regions
Finite Region : 5 bounded regions
Infinite Region : 1 unbounded region .
Theorem – “Let G be a connected simple planar graph with e edges and v vertices.
Then the number of regions r in the graph is equal to:
e – v + ( k + 1 )
Where k is the number of component in the graph.
12/8/2021 Dr. Kailash Shaw 33
34. Euler’s Formula.
Leonhard Euler was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer
who made important and influential discoveries in many branches of mathematics, such as infinitesimal
calculus and graph theory.
Euler's formula for planar graphs
V − e + r = 2
For any planar graph with v vertices, e edges, and r region, we have
Q. What is the number of regions in a connected planar simple graph with 20 vertices each with a
degree of 3?
Sum of degrees of vertices = 20 * 3 = 60,
As 2|E|=60, hence |E|=30,
And by Euler Formula for planar graph, r= e – v + 2 =>30 – 20 + 2 => 12 regions
“If G is a connected planar graph with e edges and v vertices, where v>=3 , then e ≤ 3v − 6.
G can not have vertex of degree exceeding 5”. If the graph is also bipartite, then e ≤ 2v − 4.
12/8/2021 Dr. Kailash Shaw 34
35. Planar
• Is the graph K5 planar?
IF it satisfies Euler's formula: e<=3v-6 than it is planar else it is not.
V= 5
2|E|= sum of deg(v) = 5 * 4 = 20, so |E| = 20/2= 10.
10 <= 3 * 5 – 6 does not satisfies hence K5 is not planar.
12/8/2021 Dr. Kailash Shaw 35
36. Handshaking Lemma
The sum of the degree of all vertices in a graph G is twice the number
of edges.
12/8/2021 Dr. Kailash Shaw 36
37. Connectivity
Connectivity refers to the connection between the vertices, which can
be used in modeling different problem.
Application:
The problem of determining whether a message can be sent
between two computers using intermediate links can be
studied with a graph model.
Problems of efficiently planning routes for mail delivery,
Garbage pickup,
Diagnostics in computer networks
A computer network.
communications network
A module dependency graph.
A precedence graph.
12/8/2021 Dr. Kailash Shaw 37
38. Path & Circuit
Path: Let G=(V,E) be any graph and let V0 and Vn be 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.
Circuit : The path is a circuit if it begins and ends at the same vertex
Example:
a, d, c, f , e is a simple path of length 4, because {a, d}, {d, c}, {c, f }, and {
f, e} are all edges
d, e, c, a is not a path, because {e, c} is not an edge
12/8/2021 Dr. Kailash Shaw 38
39. Connectedness in Undirected Graphs
An undirected graph is called connected if there is a path between every pair of distinct vertices of the graph.
An undirected graph that is not connected is called disconnected. We say that we disconnect a graph when
we remove vertices or edges, or both, to produce a disconnected subgraph.
Example: Thus, any two computers in the network can communicate if
and only if the graph of this network is connected.
Connected Undirected Graph Not Connected Undirected Graph
12/8/2021 Dr. Kailash Shaw 39
40. Vertex and Edge Connectivity
Cut vertices(or articulation points)
Removal from a graph of a vertex and all incident edges
produces a subgraph with more connected components
An edge whose removal produces a graph with more
connected components than in the original graph is called a cut
edge or bridge
Cut edge or bridge
Q. Find the cut vertices and cut edges in the graph G shown in Figure?
Solution:
The cut vertices of G are b, c, and e. The removal of one of these vertices (and its adjacent edges) disconnects
the graph.
The cut edges are {a, b} and {c, e}. Removing either one of these edges disconnects G.
12/8/2021 Dr. Kailash Shaw 40
41. Vertex Connectivity
Vertices Cut: {c}
𝜅(G) = 1
Vertices Cut: {b ,g}
Edge Cut:
𝜅(G) = 2
Vertices Cut: {c, f}
𝜅(G) = 2
Vertices Cut: {b, c, f}
𝜅(G) = 3
𝜅(G) is minimum number of vertices that can be removed from G to either disconnect G or produce a graph
with a single vertex
12/8/2021 Dr. Kailash Shaw 41
42. Edge Connectivity
edge Cut: {ab, ac}
𝜆(G) = 2
edge Cut: {bc ,fg}
𝜆(G) = 2
edge Cut: {bc, fg, af}
𝜆(G) = 3
edge Cut: {ab, ag, ah}
𝜆(G) = 3
The edge connectivity of a graph G, denoted by 𝜆(G), is the minimum number of edges in an edge cut of G
12/8/2021 Dr. Kailash Shaw 42
43. Inequality of Vertex and Edge Connectivity
Relation between vertex and edge 𝜅(G) ≤ 𝜆(G) ≤ minv∈V deg(v).
12/8/2021 Dr. Kailash Shaw 43
44. Euler and Hamilton Paths
An Euler circuit in a graph G is a simple circuit containing every edge of G.
An Euler path in G is a simple path containing every edge of G.
Euler circuit
In the Graph:
Euler Circuit: a, e, c, d, e, b, a (as first and last vertex is same and we have used all edges)
In the Graph: No Euler Circuit
No Euler Path
In the Graph: No Euler Circuit
Euler Path: a, c, d, e, b, d, a, b
12/8/2021 Dr. Kailash Shaw 44
45. Euler circuit in directed graph
Euler Circuit : a, g, c, b, g, e, d, f, a.
Euler Circuit : NO
Path: c, a, b, c, d, b.
12/8/2021 Dr. Kailash Shaw 45
46. Euler circuit
NECESSARY AND SUFFICIENT CONDITIONS FOR EULER CIRCUITS AND PATHS
if a connected graph has an Euler circuit, then every vertex must have even degree
A connected multigraph has an Euler path but not an Euler circuit if and only if it has exactly two vertices of odd degree.
Euler path is b, a, g, f, e, d, c, g, b, c, f, d
12/8/2021 Dr. Kailash Shaw 46
47. Hamilton Paths and Circuits
A simple path in a graph G that passes through every vertex exactly once is called a Hamilton path, and a simple
circuit in a graph G that passes through every vertex exactly once is called a Hamilton circuit. That is, the simple
path x0, x1, … , xn−1, xn in the graph G = (V, E) is a Hamilton path if V = {x0, x1, … , xn−1, xn} and xi ≠ xj for 0 ≤ i < j ≤
n, and the simple circuit x0, x1, … , xn−1, xn, x0 (with n > 0) is a Hamilton circuit if x0, x1, … , xn−1, xn is a Hamilton
path.
Hamilton circuit: a, b, c, d, e, a
Path: e, d, c, a, b
Hamilton circuit: No
Path: a, b, c, d
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 ckt.
12/8/2021 Dr. Kailash Shaw 47
48. Shortest-Path Problem
Shortest path problem is a problem of finding the shortest path(s) between vertices of a given graph.
Shortest path between two vertices is a path that has the least cost as compared to all other existing
paths.
Shortest-Path Problem
Single-pair shortest path Single-source shortest path Single-destination shortest path All pairs shortest path
shortest path between a
given pair of vertices is
computed.
shortest path from a
given source vertex to
all other remaining
vertices is computed
Algorithm:
Dijkstra’s Algorithm
Bellman Ford Algorithm
shortest path from all the
vertices to a single
destination vertex is
computed
Algorithm:
Dijkstra’s Algorithm
shortest path between
every pair of vertices
is computed
Algorithm:
Floyd-Warshall
Algorithm
Johnson’s Algorithm
Algorithm:
AStar Search Algorithm
12/8/2021 Dr. Kailash Shaw 48
49. Shortest-Path Problem
The shortest path problem is about finding a path between 2 vertices in a graph such that the total
sum of the edges weights is minimum.
A
B
C
D
E
4
1
1
1
3
5
Path Cost
ACE 7
ACDE 10
ABDE 7
ABDCE 6 SHOTEST PATH
Let find the shortest path from A to E.
1. Brute Force Approach
We will be evaluating all the path exist in Graph Between A to E
Input is a weighted graph where each edge (vi , vj) has cost ci,j to traverse the edge
Cost of a path v1v2…vN is 𝑖=1
𝑁−1
𝐶𝑖,𝑖+1
Goal: to find a smallest cost path
12/8/2021 Dr. Kailash Shaw 49
50. Single Source Shortest Path: Dijkstra’s Algorithm.
Dijkstra Algorithm is a very famous greedy
algorithm.
It is used for solving the single source
shortest path problem.
It computes the shortest path from one
particular source node to all other
remaining nodes of the graph.
12/8/2021 Dr. Kailash Shaw 50
51. Single Source Shortest Path: Dijkstra’s Algorithm
It is important to note the following points regarding Dijkstra Algorithm-
Dijkstra algorithm works only for connected graphs.
Dijkstra algorithm works only for those graphs that do not contain any negative weight edge.
The actual Dijkstra algorithm does not output the shortest paths.
It only provides the value or cost of the shortest paths.
By making minor modifications in the actual algorithm, the shortest paths can be easily obtained.
Dijkstra algorithm works for directed as well as undirected graphs
12/8/2021 Dr. Kailash Shaw 51
52. Single Source Shortest Path: Dijkstra’s Algorithm
Using Dijkstra’s Algorithm, find the shortest distance from source vertex ‘S’ to remaining vertices in the
following graph
0
Ꚙ
Ꚙ
Ꚙ
Ꚙ
Ꚙ
Step 1
d[S] = 0
d[a] = d[b] = d[c] = d[d] = d[e] = ∞
Π[S] = Π[a] = Π[b] = Π[c] = Π[d] = Π[e] = NIL
12/8/2021 Dr. Kailash Shaw 52
53. Single Source Shortest Path: Dijkstra’s Algorithm
Step 2
0
Ꚙ
Ꚙ
Ꚙ
Ꚙ
Ꚙ
edge relaxation : Outgoing edge of S
•d[S] + 1 = 0 + 1 = 1 < ∞
∴ d[a] = 1 and Π[a] = S
•d[S] + 5 = 0 + 5 = 5 < ∞
∴ d[b] = 5 and Π[b] = S
•Unvisited set : {S, a , b , c , d , e}
•Visited set : {}
12/8/2021 Dr. Kailash Shaw 53
54. Single Source Shortest Path: Dijkstra’s Algorithm
Step 3
0
5
Ꚙ
Ꚙ
Ꚙ
1
Vertex ‘a’ is chosen. This is because shortest path estimate for vertex ‘a’ is
least. The outgoing edges of vertex ‘a’ are relaxed
Π[a] = S
Π[b] = S
•Unvisited set : {a , b , c , d , e}
•Visited set : {S}
d[a] + 2 = 1 + 2 = 3 < ∞
∴ d[c] = 3 and Π[c] = a
d[a] + 1 = 1 + 1 = 2 < ∞
∴ d[d] = 2 and Π[d] = a
d[b] + 2 = 1 + 2 = 3 < 5
∴ d[b] = 3 and Π[b] = a
Before relaxed After relaxed
12/8/2021 Dr. Kailash Shaw 54
55. Single Source Shortest Path: Dijkstra’s Algorithm
Step 4
0
3
3
2
Ꚙ
1
Vertex ‘d’ is chosen. This is because shortest path estimate for vertex ‘d’ is
least. The outgoing edges of vertex ‘d’ are relaxed
Π[a] = S
Π[b] = a
•Unvisited set : {b , c , d , e}
•Visited set : {S, a}
d[d] + 2 = 2 + 2 = 4 < ∞
∴ d[e] = 4 and Π[e] = d
Before relaxed After relaxed
Π[c] = a
Π[d] = a
12/8/2021 Dr. Kailash Shaw 55
56. Single Source Shortest Path: Dijkstra’s Algorithm
Step 5
0
3
3
2
4
1
Vertex ‘b’ is chosen. This is because shortest path estimate for vertex ‘b’ is
least. The outgoing edges of vertex ‘b’ are relaxed
Π[a] = S
Π[b] = a
•Unvisited set : {b , c , e}
•Visited set : {S, a, d}
d[b] + 2 = 3 + 2 = 5 > 2
∴ No change
Before relaxed After relaxed As No Change as Per Step 4
Π[c] = a
Π[d] = a
Π[e] = d
12/8/2021 Dr. Kailash Shaw 56
57. Single Source Shortest Path: Dijkstra’s Algorithm
Step 6
0
3
3
2
4
1
Vertex ‘c’ is chosen. This is because shortest path estimate for vertex ‘c’ is
least. The outgoing edges of vertex ‘c’ are relaxed
Π[a] = S
Π[b] = a
•Unvisited set : {c , e}
•Visited set : {S, a, d, b}
d[c] + 1 = 3 + 1 = 4 = 4
∴ No change
Before relaxed After relaxed As No Change as Per Step 4
Π[c] = a
Π[d] = a
Π[e] = d
12/8/2021 Dr. Kailash Shaw 57
58. Single Source Shortest Path: Dijkstra’s Algorithm
Step 7
0
3
3
2
4
1
Vertex ‘e’ is chosen. This is because shortest path estimate for vertex ‘e’ is
least. The outgoing edges of vertex ‘e’ are relaxed
Π[a] = S
Π[b] = a
•Unvisited set : {e}
•Visited set : {S, a, d, b, c}
There are no outgoing edges for vertex ‘e’.
So, our shortest path tree remains the same as in Step-04
After relaxed As No Change as Per Step 4
Π[c] = a
Π[d] = a
Π[e] = d
12/8/2021 Dr. Kailash Shaw 58
59. Single Source Shortest Path: Dijkstra’s Algorithm
Step 8
0
3
3
2
4
1
All vertices of the graph are processed.
Our final shortest path tree is as shown below.
It represents the shortest path from source vertex ‘S’ to all other
remaining vertices.
Π[a] = S
Π[b] = a
•Unvisited set : {}
•Visited set : {S, a, d, b, c, e}
Shortest path tree
Π[c] = a
Π[d] = a
Π[e] = d
12/8/2021 Dr. Kailash Shaw 59
60. Single Source Shortest Path: Dijkstra’s Algorithm
Theorem 2: Dijkstra’s algorithm uses O(n2) operations (additions and comparisons) to find the length of
a shortest path between two vertices in a connected simple undirected weighted graph with n
vertices.
Theorem 1: Dijkstra’s algorithm finds the length of a shortest path between two vertices in a
connected simple undirected weighted graph.
12/8/2021 Dr. Kailash Shaw 60
61. Coloring of a Graph.
A coloring of a simple graph is the assignment of a color to each vertex of the graph so that
no two adjacent vertices are assigned the same color.
The chromatic number of a graph is the least number of colors needed for a coloring of
this graph. The chromatic number of a graph G is denoted by 𝜒(G). (Here 𝜒 is the Greek
letter chi.)
What are the chromatic numbers of the graphs G and H shown in Figure?
𝜒(G) = 3 𝜒(G) = 4
12/8/2021 Dr. Kailash Shaw 61
62. Coloring of a Graph.
Q. What is the chromatic number of K1, K2, K3…. Kn?
𝜒(G) = 2 𝜒(G) = 3
1 1 2 2 3
1
k1 k2 k3
…..
kn
𝜒(G) = 1 𝜒(G) = n
RED RED BLUE
RED
GREEN BLUE
12/8/2021 Dr. Kailash Shaw 62
63. Coloring of a Graph.
Q. What is the chromatic number of the complete bipartite graph Km,n, where m and n are positive integers?
A coloring of K3,4
𝜒(G) = 2
Similarly It can be shown that all Bipartite will have chromatic =2
12/8/2021 Dr. Kailash Shaw 63
64. Coloring of a Graph.
Q. What is the chromatic number of the graph Cn, where n = 3?
Cn is the cycle with n vertices.
N is even N is Odd
𝜒(G) = 2 𝜒(G) = 3
12/8/2021 Dr. Kailash Shaw 64
65. Applications of Graph Colorings
Scheduling Final Exams
How can the final exams at a university be scheduled so that no student
has two exams at the same time?
This scheduling problem can be solved using a graph model, Suppose there are seven finals to be scheduled
Suppose the courses are numbered 1 through 7.
Suppose that the following pairs of courses have common students:
1 and 2, 1 and 3, 1 and 4, 1 and 7, 2 and 3, 2 and 4, 2 and 5, 2 and 7, 3 and 4, 3 and 6, 3 and 7, 4 and 5,4 and 6, 5 and
6, 5 and 7, 6 and 7
Time Period Courses
I 1, 6
II 2
III 3, 5
IV 4, 7
RED
BLUE
GREEN
BROWN
12/8/2021 Dr. Kailash Shaw 65
66. Three utility problem
The classical mathematical puzzle known as the three utilities problem; the three cottages problem or
sometimes water, gas and electricity can be stated as follows:
Water Gas Electricity
Suppose there are three cottages on a plane (or sphere) and each needs to be connected to the water,
gas, and electricity companies. Without using a third dimension or sending any of the connections through
another company or cottage, is there a way to make all nine connections without any of the lines crossing
each other?
As it is usually presented (on a
flat two-dimensional plane),
the solution to the utility puzzle
is “NO": there is no way to
make all nine connections
without any of the lines
crossing each other
Euler Formula : E = 9, V = 6. Looking to figure it seems their exist 9 faces/region. We can say F≥
𝐸
2
, Substituting it in Euler formula V – e + f = 2, we get E ≤ 2V − 4. As 9 ≤ 2*6 − 4 does not hold,
hence, Utility Problem is Not Planner
12/8/2021 Dr. Kailash Shaw 66
67. Web Graph
The web can be modeled as a directed graph where each web page is represented by a vertex and where
an edge starts at the web page a and ends at the web page b if there is a link on a pointing to b.
Because new web pages are created and others removed somewhere on the web almost every second,
the web graph changes on an almost continual basis. Many people are studying the properties of the
web graph to better understand the nature of the web.
1999 200 million vertices and 1.5 billion edges
2015-20 55.3 billion vertices
https://en.wikipedia.org/wiki/World_Wide_Web#/media/File:WorldWideWebAroundWikipedia.png
https://www.worldwidewebsize.com/
12/8/2021 Dr. Kailash Shaw 67
68. Google map
Google cannot read maps
Google uses algorithms to determine our best
routes.
In order for these algorithms to work properly, they
need the correct form of input.
A network of roads is best displayed in a top-down
view, such as in a satellite image
Google consider the network of roads as a directed
graph
The lines in 2nd Figure represent the edges of the
graph and the circles are the nodes
The task of finding the shortest way from point A to
point B can thereby be reduced to finding the
shortest path on a weighted graph.
There are a lot of different algorithms that can do
this but google usually do it using A* or Dijkstra.
https://mathsection.com/how-google-maps-calculates-the-shortest-route/?cookie-state-change=1594467295336
12/8/2021 Dr. Kailash Shaw 68