D1, L6 3 Dijkstra's Algorithm
D1, L6 3 Dijkstra's Algorithm
Dijkstras Algorithm
finds the shortest path from the start vertex to every other
vertex in the network. We will find the shortest path from A to G
B
7
3
2
G
Dijkstras Algorithm
1.
Label the start vertex with permanent label 0 and order label 1
Select the vertex with the smallest temporary label and make its
label permanent. Add the correct order label.
Select the vertex with the smallest temporary label and make its
label permanent. Add the correct order label.
To find the shortest paths(s), trace back from the end vertex to the
start vertex. Write the route forwards and state the length.
Order in which
vertices are
labelled.
Dijkstras
Algorithm
B
1
A
Label vertex A
1 as it is the first
vertex labelled
Working
Distance from
A to vertex
7
3
2
G
Dijkstras
Algorithm
B
1
7
3
2
G
C
3
Dijkstras
Algorithm
4
B
1
7
3
3
Vertex C is closest
to A so we give it a C
permanent label 3.
2
C is the 2nd vertex to 3
be permanently
labelled.
2
G
5
3
Dijkstras
Algorithm
B
1
6 < 7 so
replace the
t-label here
7 6
7
3
2
G
C
2
3
E
8
Dijkstras
Algorithm
3
4
B
1
7 6
7
3
2
G
C
2
3
E
8
Dijkstras
Algorithm
3
4
B
1
5 < 6 so
replace the
t-label here
7 6 5
7
3
2
G
C
2
3
E
8
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
7
3
2
G
C
2
3
E
8
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
8 7
7 < 8 so
replace the
t-label here
7
3
C
2
3
7 < 8 so
replace the
t-label here
8 7
12
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
8 7
7
3
2
G
C
2
3
E
5
8 7
12
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
8 7
7
3
2
G
C
2
3
E
5
8 7
12 9
9 < 12 so
replace the
t-label here
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
6
7
8 7
7
3
2
G
C
2
3
E
5
8 7
12 9
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
6
7
8 7
7
3
2
G
C
2
3
E
5
8 7
12 9
11 > 9 so do
not replace
the t-label
here
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
6
7
8 7
7
3
2
G
C
2
3
E
5
8 7
7
9
12 9
G is the final vertex
to be permanently
labelled.
Dijkstras
Algorithm
3
4
B
1
4
5
7 6 5
1
7
6
7
8 7
7
3
2
G
C
2
3
E
5
8 7
7
9
12 9