CO-4 Session 26

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Department of Mathematics

Data Structures- 23MT1001


I/IV-B.Tech-(II Sem), Academic Year: 2022-2023

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.

 Weighted Graphs are used to model computer networks.


 Communication costs such as the monthly cost of leasing a telephone line, the response
times over these lines or the distance between computers can all be studied using weighted
graphs.
Determining a path of least length between vertices in a network is one such problem.
Explanation:

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.

Shortest path Problem:


Determining the path of least sum of the weights between two vertices in a weighted graph

Use of the shortest path problems


 In graph theory, the shortest path problem is the problem of finding a path between
two vertices (or nodes) in a graph such that the sum of the weights of its constituent
edges is minimized.
Examples
1. The problem of finding the shortest path between two intersections on a road map may be
modeled as a special case of the shortest path problem in graphs, where the vertices
correspond to intersections and the edges correspond to road segments, each weighted by
the length of the segment.
2. The Stagecoach Shipping Company transports oranges by six trucks from Los Angeles to
six cities in the West and Midwest
3. Smart drives daily to work. Having just completed a course in network analysis, Smart is
able to determine the shortest route to work. Unfortunately, the selected route is heavily
patrolled by police, and with all the fines paid for speeding, the shortest route may not be
the best choice. Smart has thus decided to choose a route that maximizes the probability
of not being stopped by police.
The network in the below figure shows the possible routes between home and work, and the
associated probabilities of not being stopped on each segment. The probability of not
beingstopped on a route is the product of the probabilities associated with its segments. For
example, the probability of not receiving a fine on the route 1 -> 3 -> 5 -> 7
is .9 X .3 X .25 = .0675. Smart's objective is to select the route that maximizes the probability of
not being fined.

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 DTKGS
98 D: 458
142
DTSGKD: 504
167
56 D
135
58 DTSKGD: 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

Dijkstra’s Algorithm (find the length of a shortest path from a to z)

It begins by labeling a with 0 and other vertices with ∞.

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.,

Lk ( a,v)= min{ Lk-1, ( a,v), Lk-1 ( a,u) + w(u,v)}

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

PROPERTIES OF PLANAR GRAPHS:

 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:

In planar graphs, the following properties hold good

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 = 320 = 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).

1) Determine the chromatic numbers of the graphs G and H shown below.

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:

1. Dijkstra’s Algorithm is used to solve _____________ problems.


a) All pair shortest path
b) Single source shortest path
c) Network flow
d) Sorting
Answer: b
2. For a connected planar simple graph G=(V, E) with e=|E|=16 and v=|V|=9, then find the
number of regions that are created when drawing a planar representation of the graph?
a) 321
b) 9
c) 1024
d) 596
Answer: b
3. What is the number of edges of the greatest planar subgraph of K3,2 where m,n≤3?
a) 18
b) 6
c) 128
d) 702
Answer: b
4. A connected planar simple graph G=(V, E) with e=|E|=16 and v=|V|=9, then find the
number of regions that are created when drawing a planar representation of the graph?
a) 21
b) 94
c) 1024
d) 9
Answer: d
5. The chromatic number of a graph is the property of ____________
a) graph coloring
b) graph ordering
c) group ordering
d) group coloring
Answer: a
6. Is K4 is planar?
a) Planar
b) Non planar
c) Disconnected
d) None of these
Answer : a
7. What will be the chromatic number for an bipartite graph having n vertices?
a) 0
b) 1
c) 2
d) n
Answer : C
8. What will be the chromatic number for a complete graph having n vertices?
a) 0
b) 1
c) n
d) n!
Answer: C
9. Dijkstra’s Algorithm cannot be applied on ______________
a) Directed and weighted graphs
b) Graphs having negative weight function
c) Unweighted graphs
d) Undirected and unweighted graphs
Answer: b
10. A non-planar graph can have ____________
a) complete graph
b) subgraph
c) line graph
d) bar graph

Answer: b

CLASSROOM DELIVARY PROBLEMS

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?

5. Draw the given planar graph without any crossings.


a. b.

6. Find the chromatic number of Kn?

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?

You might also like