0% found this document useful (0 votes)
7 views8 pages

Graph Theory III

The document discusses key concepts in graph theory, specifically the distance between vertices and the diameter of a connected graph. It also explains Dijkstra's Algorithm, which is used to find the shortest path between two vertices in a weighted graph, detailing the steps involved in the algorithm. An example illustrates how to apply the algorithm to determine the shortest path and its associated weight.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Graph Theory III

The document discusses key concepts in graph theory, specifically the distance between vertices and the diameter of a connected graph. It also explains Dijkstra's Algorithm, which is used to find the shortest path between two vertices in a weighted graph, detailing the steps involved in the algorithm. An example illustrates how to apply the algorithm to determine the shortest path and its associated weight.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Graph

Theory-III
DR. ASHESH PAUL
 Distance Between Two Vertices:

If 𝐺 be a connected graph then the distance between two vertices 𝑢 and 𝑣 of 𝐺 is


the length of the shortest path between 𝒖 and 𝒗 and is denoted by 𝑑 𝑢, 𝑣 .

 Diameter of a Connected Graph:

If 𝐺 be a connected graph then the diameter of the graph is the length of the
maximum distance between any two vertices 𝒖 and 𝒗 of 𝑮 and is denoted by dim 𝐺 .

𝑣4 Here, the distance between 𝑣1 and


𝑣1 𝑣7
𝑣5 is 𝑑 𝑣1 , 𝑣5 = 2
𝑣4
𝑣2 𝑣6 Whereas, diameter of the graph is
dim 𝐺 = 3.

𝑣3 Note: Diameter of the graph is the


𝑣5
maximum of the set of all distances
𝐺 in the graph.
Dijkstra’s Algorithm

 This algorithm determines the shortest path between two given vertices.

 Dijkstra’s algorithm can be applied only when the graph is weighted.

 Suppose 𝑣𝑖 and 𝑣𝑗 be two vertices which are connected by an edge 𝑒𝑖𝑗 . Then
the weight associated to 𝑒𝑖𝑗 will be denoted by 𝑤𝑖𝑗 .
 The algorithm is an iterative process and involve some steps.
Steps of Dijkstra’s Algorithm

Step – I
If the given graph is not simple, turn it to a simple graph by discarding all the self loops
and parallel edges.
Note: While discarding the parallel edges keep the edge which has the smallest weight.
Let us describe the steps by an example. Suppose we are asked to find the shortest path
between 𝒗𝟐 and 𝒗𝟓 of the following graph 𝑮:

Step - I
Step-II
If we are finding the shortest distance between the two vertices 𝑣𝑖 and 𝑣𝑘 , we start with any one
of 𝑣𝑖 or 𝑣𝑘 . Let we have started with 𝑣𝑖 .
Now assign labels to the vertices by the following rule:
The starting vertex 𝒗𝒊 is permanently labelled as 𝟎.
All other vertices are temporarily labelled as ∞.
The minimum label of this step is 𝒅 = 𝟎

In the given example we start with vertex 𝑣2 . So 𝑣2 is permanently labelled as 0. All other
Vertices are temporarily labelled as ∞.

𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣6 𝑣7
Step 1 ∞ 0 ∞ ∞ ∞ ∞ ∞
Step-III
Find the minimum label
Every vertex 𝒗𝒋 which are not yet permanently labelled gets a new temporary label

𝑳 𝒗𝒋 = 𝐦𝐢𝐧 𝒐𝒍𝒅 𝒍𝒂𝒃𝒆𝒍 𝒐𝒇 𝒗𝒆𝒓𝒕𝒆𝒙 𝒗𝒋 , 𝒘𝒆𝒊𝒈𝒉𝒕 𝒐𝒇 𝒆𝒊𝒋 + 𝒅


Here 𝒆𝒊𝒋 is the edge joining 𝒗𝒊 and 𝒗𝒋 .
𝒅 the minimum label from the previous step.
If there is no edge between 𝒗𝒊 and 𝒗𝒋 then weight of 𝒆𝒊𝒋 = ∞
Here 𝒗𝟐 is permanently labelled.
For 𝒗𝟏 vertex we consider the edge 𝒆𝟏𝟐 ,i.e., the edge incident to 𝒗𝟏 and 𝒗𝟐 .
For 𝒗𝟑 vertex we consider the edge 𝒆𝟑𝟐 ,i.e., the edge incident to 𝒗𝟑 and 𝒗𝟐 𝐚𝐧𝐝 𝐬𝐨 𝐨𝐧.
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣6 𝑣7
Row 1 ∞ 0 ∞ ∞ ∞ ∞ ∞
Row 2 min ∞, 1 + 0 × min ∞, 7 + 0 min ∞, ∞ + 0 min ∞, ∞ + 0 min ∞, ∞ + 0 min ∞, ∞ + 0
=1 =7 =∞ =∞ =∞ =∞

Now 𝒗𝟐 is permanently labelled as 𝟏 as it is the minimum label in the row.


Step-III
The minimum value of previous step is 1 which corresponds to vertex 𝑣1 .
Proceed as before with 𝒅 = 𝟏 and 𝒗𝒋 = 𝒗𝟏 .
Next minimum value is 𝟒 corresponds to 𝒗𝟑 and 𝒗𝟒 . Choose any one of them.
We choose 𝒗𝟑 as permanently labelled and proceed with 𝒅 = 𝟒.
Repeat the process until the terminal vertex (here 𝒗𝟓 ) is permanently labelled.

𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣6 𝑣7
Row 1 ∞ 0 ∞ ∞ ∞ ∞ ∞
Row 2 min ∞, 1 + 0 × min ∞, 7 + 0 min ∞, ∞ + 0 min ∞, ∞ + 0 min ∞, ∞ + 0 min ∞, ∞ + 0
=1 =7 =∞ =∞ =∞ =∞
Row 3 × × min 7, 3 + 1 min ∞, ∞ + 1 min ∞, ∞ + 1 min ∞, 3 + 1 min ∞, 4 + 1
=4 =∞ =∞ =4 =5
Row 4 × × × min ∞, 8 + 4 min ∞, ∞ + 4 min 4, ∞ + 4 min 5, ∞ + 4
= 12 =∞ =4 =5
Row 5 × × × min 12, ∞ + 4 min ∞, 7 + 4 × min 5, 4 + 4
= 12 = 11 =5
Row 6 × × × min 12, 3 + 5 min 11, 2 + 5 × ×
=8 =7
Step-IV
As 𝑣5 is permanently labelled now look straight along the column of 𝑣5 .
Search where the value got changed. Here the value changed immediately in
the previous row, i.e., in row 𝟓.
Now, look for the vertex in this row which is permanently labelled. Here it is 𝒗𝟕 .
Next look upwards through this column and repeat the process until you reach the
initial vertex 𝒗𝟐 .
Thus we get the desired shortest path as 𝒗𝟓 → 𝒗𝟕 → 𝒗𝟏 → 𝒗𝟐
Weight for this path is 2+4+1=7

𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣6 𝑣7
Row 1 ∞ 0 ∞ ∞ ∞ ∞ ∞
Row 2 min ∞, 1 + 0 × min ∞, 7 + 0 min ∞, ∞ + 0 min ∞, ∞ + 0 min ∞, ∞ + 0 min ∞, ∞ + 0
=1 =7 =∞ =∞ =∞ =∞
Row 3 × × min 7, 3 + 1 min ∞, ∞ + 1 min ∞, ∞ + 1 min ∞, 3 + 1 min ∞, 4 + 1
=4 =∞ =∞ =4 =5
Row 4 × × × min ∞, 8 + 4 min ∞, ∞ + 4 min 4, ∞ + 4 min 5, ∞ + 4
= 12 =∞ =4 =5
Row 5 × × × min 12, ∞ + 4 min ∞, 7 + 4 × min 5, 4 + 4
= 12 = 11 =5
Row 6 × × × min 12, 3 + 5 min 11, 2 + 5 × ×
=8 =7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy