CO-4 Session 26
CO-4 Session 26
CO-4 Session 26
Session-26 (Shortest path Problems- Dijkstra’s Algorithm, Planar graphs, Graph Coloring.)
Instructional Objective:
1. To understand the concepts of shortest path, planar graphs.
2. To understand the concept of graph coloring problems and chromatic number.
Learning Outcomes:
1. Able to apply shortest path problems in real world situations.
2. Able to apply graph coloring concepts in network systems.
Introduction:
Many problems can be modelled using graphs with weights assigned to their edges. As an
illustration, consider how an airplane system can be modelled. We set up the basic graph model
by representing cities by vertices and flights by edges.
Problems involving distances can be modelled by assigning distances between cities to the
edges.
Problems involving flight time can be modelled by assigning flight times to edges.
Problems involving fares can be modelled by assigning fares to the edges.
Graphs that have a number assigned to each edge are called weighted graphs.
Shortest-Path Problems
Definition:
1. Graphs that have a number assigned to each edge are called weighted graphs.
2. The length of a path in a weighted graph is the sum of the weights of the edges of this path.
Example 4
The Traveling Salesman Problem:
A traveling salesman wants to visit each of n cities exactly once and return to his starting point.
In which order should he visit these cities to travel the minimum total distance?
S
113
G 137
147 DTKGS
98 D: 458
142
DTSGKD: 504
167
56 D
135
58 DTSKGD: 540
K 133 T
Example 5: What is the length of a shortest path between a and z in the weighted graph G?
b 3 c
2
4
L=0
z (1)
a 3 a
2 1
d 3 e L=4 b
a
(2) 4
L=2 (3)
2 a
2
d
d
b
4
(4)
a
2 L=5
d 3 e
b
(5) 4 L=6
a z length=6
2 1
d 3 e
We use the notation L0( a) = 0 and L0( v) = ∞ for these labels before any iterations have taken
place( subscript stands for 0th iteration. These labels are the lengths of shortest paths from a to the
vertices, where the paths contain only the vertex a. ( Because no path from a to a vertex different
from a exists, ∞ is the length of a shortest path between a and this vertex.
Let Sk denote this set after k iterations of the labelling procedure. We begin with S0 =Φ. The set Sk
is formed from Sk-1 by adding a vertex u not in Sk-1 with the smallest label. Once u is added to Sk,
we update the labels of all the labels not in Sk, so that Lk (v), the label of the vertex v at the kth
stage is the length of a shortest path from a to v that contains vertices only in Sk ( vertices that
were already in the distinguished set together with u)
Let v be a vertex not in Sk. To update the label of v note that Lk (v) is the length of a shortest path
from a to v containing only vertices in Sk. The updating can be carried out efficiently when this
observation is used: A shortest path from a to v containing only elements of Sk is either a shortest
path from a to v that contains only elements of Sk-1. ( the distinguished vertices not including u), or
it is a shortest path from a to u at the (k-1) st stage with the edge (u,v) added. i.e.,
This procedure is iterated successively , adding vertices to the distinguished set until z is added.
When z is to the distinguished set , its label is the length of a shortest path from a to z.
Procedure Dijkstra(G: weighted connected simple graph, with all weights positive)
{G has vertices a = v , v , …, v = z and weights w(v , v )
0 1 n i j
where w(v , v ) = if {v , v } is not an edge in G}
i j i j
for i := 1 to n
L(v ) :=
i
L(a) := 0
S :=
while z S
begin
u := a vertex not in S with L(u) minimal
S := S ∪ {u}
for all vertices v not in S
if L(u) + w(u, v) < L(v) then L(v) := L(u) + w(u, v)
end {L(z) = length of a shortest path from a to z}
Problem: Use Dijkstra’s algorithm to find the length of a shortest path between the vertices a and
z in the weighted graph displayed in the following figure.
b 5 d
4 6
8
a 1 z
2
2 3
c 10 e
Solution:
b 5 d
4 6
0 8
a 1 z
2
2 3
c 10 e
4(a)
b 5 d
4 6
0 8
a 1 z
2
2 3
c 10 e
2(a)
3(c) 10(c)
b 5 d
4 6
0 8
a 1 z
2
2 3
c 10 e
2(a) 12(c)
3(c) 8(b)
b 5 d
4 6
0 8
a 1 z
2
2 3
c 10 e
2(a) 12(c)
3(c) 8(b)
b 5 d
4 6
0 8
a 1 z 14
2 (d)
2 3
c 10 e
2(a) 10(d)
3(c) 8(b)
b 5 d
4 6
0 8
a 1 z14(d)
2
2 3
c 10 e
2(a) 10(d)
3(c) 8(b)
b 5 d
4 6
0 8
a 1 z13(e)
2
2 3
c 10 e
2(a) 10(d)
3(c) 8(b)
b 5 d
4 6
0 8
a 1 z13(e)
2
2 3
c 10 e
2(a) 10(d)
path: a, c, b, d, e, z length: 13
Note: 1. Dijkstra’s algorithm finds the length of a shortest path between two vertices in a
connected simple undirected weighted graph.
2
2.Dijkstra’s algorithm uses O(n ) 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.
Planar Graphs
Definition:
A graph is called planar if it can be drawn in the plane without any edge crossing. Such a
drawing is called a planar representation of the graph
Example: Is K planar?
4
K
4
There is no edge crossing. K4 is planar
Euler’s Formula
A planar representation of a graph splits the plane into regions, including an unbounded region.
Example : How many regions are there in the following graph?
Total regions : 6
If a connected simple planar graph G has e edges and r regions then r≤ 2e/3
If a connected simple planar graph G has e edges and n(≥3) vertices, then
e ≤ 3n-6.
A complete graph Kn is planar if n< 5.
A complete bipartite graph Km,n is planar if and only if m<3 or n>3.
Remarks:
1. In a planar graph with ‘n’ vertices, sum of degrees of all the vertices is n ∑ deg(Vi) = 2|E|
2. According to Sum of Degrees of Regions Theorem, in a planar graph with ‘n’ regions, Sum of
degrees of regions is n ∑ deg(ri) = 2|E|
Where, |V| is the number of vertices, |E| is the number of edges, and |R| is the number of regions.
Example: Suppose that a connected planar graph has 20 vertices, each of degree 3. Into how
many regions does a representation of this planar graph split the plane?
Sol.
v = 20, 2e = 320 = 60, e = 30
r = e-v+2 = 30-20+2 = 12
Example: A connected planar graph has 10 vertices each of degree 3. Into how many regions does
a representation of this planar graph split the plan.
Solution: Here n= 10, and degree of each vertex is 3. So sum of all degrees of all vertices = 3x
10= 30 = 2e ( by hand shaking rule). So e( number of edges )= 15. Again by euler’s formula we
have n-e + r= 2. Hence 10-15+r =2. Therefore, the number of regions, r = 7.
GRAPH COLORING:
When a map is colored two regions with a common border are assigned different colours. One
way to ensure different that two adjacent regions never have the same colour is to use a different
colour for each region. However, this is inefficient and on maps with many regions it would be
hard to distinguish similar colours. Instead a small number of colours should be used whenever
possible.
Consider the problem of determining the least number of colours that can be used to colour a map
so that adjacent regions never have the same colour.
Definition: A colouring of a simple graph is the assignment of a colour to each vertex of the graph
so that no two adjacent vertices are assigned the same colour.
Definition: the chromatic number of a graph is the least number of colours needed for colouring of
this graph. It is denoted by X(G).
The chromatic number of G is at least three because the vertices a, b, c must be assigned different
colours. To set if G can be coloured with three colours assign red to a, blue to b and green to c.
Then d can be coloured red because it is adjacent to b and c. further e must be coloured green
because it is adjacent only to vertices coloured red and blue. And f must be coloured blue because
it is adjacent to red and green, finally g must be coloured red because it is adjacent to blue and
green. This produces a colouring of G using exactly three colours.
The graph H is made up of G with an edge connecting a and g. Any attempt to colour H using
three colours must follow the same reasoning as that used to colour G, except at the last stage,
when all the vertices other than g have been coloured. Then because g is adjacent to vertices
coloured red , blue and green, a fourth colour say brown needs to be used. Hence H has a
chromatic number 4. A colouring of G and H are as shown below.
Review questions:
1. What is a planar graph?
2. Define Euler’s formula?
3. What is Chromatic number?
Summary:
In this session, it was discussed about Shortest path problems - Dijkstra’s Algorithm,
planar graphs and Graph colouring.
Self-assessment questions:
Answer: b
1. Determine the length of a shortest path between a and z in the given weighted graph.
2. Apply Dijkstra’s Algorithm to find the length of a shortest path between a and z in the
given weighted graph
2. Prove that complete graph K4 is planar whereas complete graph K5 is not planar.
3. Is K3 , 3 is a planar? Justify?
4. Suppose that a connected planar graph has 30 edges. If a planar representation of this graph
divides the plane into 20 regions, how many vertices does this graph have?
TUTORIAL PROBLEMS
1.Solve the traveling salesperson problem for this graph by finding the total weight of all
Hamilton circuits and determining a circuit with minimum total weight.
2.Which of these non-planar graphs have the property that the removal of any vertex and all edges
incident with that vertex produces with planar graph?
a) K6 b) K3, 3
3.Suppose that a connected planar graph has six vertices, each of degree four. Into how many
regions is the plane divided by a planar representation of this graph?
4.Determine whether the given graph is planar. If so, draw it so that no edges cross.
a. b.
5.A connected planar graph has 10 vertices each of degree 3. Into how many regions does a
representation of this planar graph split the plane.
6. Find the chromatic number of the complete bipartite graph Km,n, where m and n are positive
integers?
HOME ASSIGNMENT PROBLEMS
1. Find a route with the least total airfare that visits each of the cities in this graph, where the
weight on an edge is the least price available for a flight between the two cities.
2. Solve the traveling salesperson problem for this graph by finding the total weight of all
Hamilton circuits and determining a circuit with minimum total weight.
3. Which of these non-planar graphs have the property that the removal of any vertex and all
edges incident with that vertex produces with planar graph?
a) K5 b) K3, 4
4. Can five houses be connected to two utilities without connections crossing?
5. Suppose that a planar graph has k connected components, e edges, and v vertices. Also
suppose that the plane is divided into r regions by a planar representation of the graph.
Find a formula for r in terms of e, v and k.
6. Suppose that a connected planar simple graph has 20 vertices, each of degree 3. Into how
many regions does a representation of this planar graph split the plane?