Download presentation
Presentation is loading. Please wait.
1
Dijkstra Algorithm examples
2
Example 1
3
Walk-Through Initialize array F C A B D H G E K dv pv A F B C D E
2 Initialize array 3 F 5 C K dv pv A F B C D E G H A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
4
Start with G F C A B D H G E K dv pv A B C D E F G T H 2 3 5 10 7 3
H A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
5
Update unselected nodes
2 Update unselected nodes 3 F 5 C K dv pv A B C D 2 G E F T H 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
6
Select minimum distance
2 Select minimum distance 3 F 5 C K dv pv A B C D T 2 G E F H 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
7
Update unselected nodes
2 Update unselected nodes 3 F 5 C K dv pv A B C D T 2 G E 27 F 20 H 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
8
Select minimum distance
2 Select minimum distance 3 F 5 C K dv pv A B C D T 2 G E 27 F 20 H 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
9
Update unselected nodes
2 Update unselected nodes 3 F 5 C K dv pv A 7 H B 12 C D T 2 G E 27 F 20 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
10
Select minimum distance
2 Select minimum distance 3 F 5 C K dv pv A T 7 H B 12 C D 2 G E 27 F 20 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
11
Update unselected nodes
2 Update unselected nodes 3 F 5 C K dv pv A T 7 H B 12 C D 2 G E 27 F 17 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
12
Select minimum distance
2 Select minimum distance 3 F 5 C K dv pv A T 7 H B 12 C D 2 G E 27 F 17 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
13
Update unselected nodes
2 Update unselected nodes 3 F 5 C K dv pv A T 7 H B 12 C 16 D 2 G E 22 F 17 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
14
Select minimum distance
2 Select minimum distance 3 F 5 C K dv pv A T 7 H B 12 C 16 D 2 G E 22 F 17 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
15
Update unselected nodes
2 Update unselected nodes 3 F 5 C K dv pv A T 7 H B 12 C 16 D 2 G E 22 F 17 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
16
Select minimum distance
2 Select minimum distance 3 F 5 C K dv pv A T 7 H B 12 C 16 D 2 G E 22 F 17 3 A 10 7 3 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
17
Update unselected nodes
2 Update unselected nodes 3 F 5 C K dv pv A T 7 H B 12 C 16 D 2 G E 19 F 17 3 A 10 7 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7
18
Select minimum distance
2 Select minimum distance 3 F 5 C K dv pv A T 7 H B 12 C 16 D 2 G E 19 F 17 3 A 10 7 4 8 18 4 B D 9 H 10 9 2 25 3 G E 7 Done
19
Example 2
20
Dijkstra's Shortest Path Algorithm
Find shortest path from s to t. 2 24 3 9 s 18 14 2 6 6 4 30 19 11 15 5 5 6 20 16 t 7 44
21
Dijkstra's Shortest Path Algorithm
PQ = { s, 2, 3, 4, 5, 6, 7, t } 2 24 3 9 s 18 14 2 6 6 4 30 19 11 15 5 5 6 20 16 t 7 44 distance label
22
Dijkstra's Shortest Path Algorithm
PQ = { s, 2, 3, 4, 5, 6, 7, t } delmin 2 24 3 9 s 18 14 2 6 6 30 4 19 11 15 5 5 6 20 16 t 7 44 distance label
23
Dijkstra's Shortest Path Algorithm
PQ = { 2, 3, 4, 5, 6, 7, t } decrease key X 9 2 24 3 9 s 18 14 X 14 2 6 6 4 30 19 11 15 5 5 6 20 16 t 7 44 distance label 15 X
24
Dijkstra's Shortest Path Algorithm
PQ = { 2, 3, 4, 5, 6, 7, t } delmin X 9 2 24 3 9 s 18 14 X 14 2 6 6 4 30 19 11 15 5 5 6 20 16 t 7 44 distance label 15 X
25
Dijkstra's Shortest Path Algorithm
PQ = { 3, 4, 5, 6, 7, t } X 9 2 24 3 9 s 18 14 X 14 2 6 6 30 4 19 11 15 5 5 6 20 16 t 7 44 15 X
26
Dijkstra's Shortest Path Algorithm
PQ = { 3, 4, 5, 6, 7, t } decrease key X 33 X 9 2 24 3 9 s 18 14 X 14 2 6 6 4 30 19 11 15 5 5 6 20 16 t 7 44 15 X
27
Dijkstra's Shortest Path Algorithm
PQ = { 3, 4, 5, 6, 7, t } X 33 X 9 2 24 3 9 delmin s 18 14 X 14 2 6 6 4 30 19 11 15 5 5 6 20 16 t 7 44 15 X
28
Dijkstra's Shortest Path Algorithm
PQ = { 3, 4, 5, 7, t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 44 30 X 4 19 11 15 5 5 6 20 16 t 7 44 15 X
29
Dijkstra's Shortest Path Algorithm
PQ = { 3, 4, 5, 7, t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 44 30 X 4 19 11 15 5 5 6 20 16 t 7 44 15 delmin X
30
Dijkstra's Shortest Path Algorithm
PQ = { 3, 4, 5, t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 44 X 35 X 4 30 19 11 15 5 5 6 20 16 t 7 44 59 15 X X
31
Dijkstra's Shortest Path Algorithm
PQ = { 3, 4, 5, t } delmin 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 44 X 35 4 30 X 19 11 15 5 5 6 20 16 t 7 44 59 15 X X
32
Dijkstra's Shortest Path Algorithm
PQ = { 4, 5, t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 44 X 35 X 34 4 30 X 19 11 15 5 5 6 20 16 t 7 44 51 59 15 X X X
33
Dijkstra's Shortest Path Algorithm
PQ = { 4, 5, t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 44 X 35 X 34 30 X 4 19 11 15 5 5 6 20 delmin 16 t 7 44 51 59 15 X X X
34
Dijkstra's Shortest Path Algorithm
PQ = { 4, t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 45 44 X 35 X 34 X 30 X 4 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59 15 X X X
35
Dijkstra's Shortest Path Algorithm
PQ = { 4, t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 45 44 X 35 X 34 X 30 X 4 19 11 15 5 delmin 5 6 20 16 t 7 44 50 51 X 59 15 X X X
36
Dijkstra's Shortest Path Algorithm
PQ = { t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 45 44 X 35 X 34 X 30 X 4 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59 15 X X X
37
Dijkstra's Shortest Path Algorithm
PQ = { t } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 45 44 X 35 X 34 X 30 X 4 19 11 15 5 5 6 20 16 t 7 44 delmin 50 51 X 59 15 X X X
38
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 45 44 X 35 X 34 X X 4 30 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59 15 X X X
39
Dijkstra's Shortest Path Algorithm
S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { } 32 X 33 X X 9 2 24 3 9 s 18 14 X 14 2 6 6 45 44 X 35 X 34 X X 4 30 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59 15 X X X
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.