Dijkstras Algorithm
Dijkstras Algorithm
The edges can then be assigned weights which may be either the distance between
the two cities connected by the edge or the average time to drive along that section
of highway. A motorist wishing to drive from city A to B would be interested in
answers to the following questions
Is there a path from A to B?
If there is more than one path from A to B, which is the shortest path?
From( j ) i
if i is the predecessor of j along the
shortest path from v0 to j
15 35
10
20 20
30
V2 V3 V5
15 3
v0 v1 v2 v3 v4 v5
45 45
50 10 50 10
V0 V1 V0 V1 V4
V4
15
15 10
20 10 35 35
20 20
20
30 30
V2 V3 V5 V2 V3 V5
15 3 15 3
45 45
50 10 50 10
V0 V1 V4 V0 V1 V4
15
35 15
20 10 35
20 10
20
20 30
30
V2 V3 V5 V2 V3 V5
15 3 15 3
45
45
50 10
50 10 V0 V1
V0 V1 V4 V4
15 15
35 35
20 10 20 10
20 20
30 30
V2 V3 V5 V2 V3 V5
15 3 15 3
v0 v2 v3 v1 45
v0 v2 10
v0 v2 v3 25
v0 v4 45
v0 v5
end;
1
1
10 50 10 50
100 30 30
5 2 100 2
5
20 20
10 5 10 5
4 3 4 3
50 50
1 1
10 50 10 50
100 30 100 30
5 2 5 2
20 20
10 5 10 5
4 3 4 3
50 50
5. Dist (2) = 35, From (2) = 3
Shortest paths
from source 1 1
10 50
132
35 30
100 2
5
13
30 20
10 5
1 5 4
11/28/2024 4 Devi, Department of CS,3GIS, GU
Dr. T. Uma 12
20 50
11/28/2024 Dr. T. Uma Devi, Department of CS, GIS, GU 13
11/28/2024 Dr. T. Uma Devi, Department of CS, GIS, GU 14
11/28/2024 Dr. T. Uma Devi, Department of CS, GIS, GU 15
Dijkstra’s Algorithm