Download presentation
Presentation is loading. Please wait.
1
Implementation of Dijkstra’s Algorithm
2
Dijkstra’s Algorithm
3
Implementations With min-priority queue, Dijkstra algorithm can be
implemented in time With Fibonacci heap, Dijkstra algorithm can be implemented in time With Radix heap, Dijkstra algorithm can be implemented
4
An Example Initialize
4 2 4 2 2 1 2 3 1 1 6 4 2 3 3 5 1 Initialize 2 ∞ 3 ∞ Select the node with the minimum temporary distance label. 4 5 6 ∞ ∞ ∞
5
Update Step 2 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 1 2 ∞ 3 ∞ 4 5 6 ∞ ∞ ∞
6
Update Step 2 Decrease-Key(S,2,2) 4 2 4 2 2 1 2 3 1 6 4 2 3 3
1 2 3 1 6 4 2 3 3 5 1 2 2 3 ∞ Decrease-Key(S,2,2) 4 5 6 ∞ ∞ ∞
7
Update Step 2 4 Decrease-Key(S,2,2) Decrease-Key(S,3,4) 4 2 4
1 2 3 1 6 4 2 3 3 5 1 4 2 2 3 4 Decrease-Key(S,2,2) Decrease-Key(S,3,4) 4 5 6 ∞ ∞ ∞
8
Update Step 2 4 Extract-Min(S) 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 ∞ 6
1 2 3 1 6 4 2 3 3 5 4 ∞ 6 2 2 3 4 Extract-Min(S) 4 5 ∞ ∞
9
Choose Minimum Temporary Label
2 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 4 2 2 6 ∞ 3 4 4 5 ∞ ∞
10
Update Step 6 The predecessor of node 3 is now node 2 2 4 4 3
1 2 3 1 6 4 2 3 3 5 4 2 2 4 3 5 4 3 3 Decrease-Key(S,3,3) Decrease-Key(S,4,6) Decrease-Key(S,5,4) 6 4 ∞ 6
11
Choose Minimum Temporary Label
2 6 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 3 4 6 4 5 4 3 3 Extract-Min(S) 6 ∞
12
Choose Minimum Temporary Label
2 6 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 3 4 3 3 5 4 4 6 Extract-Min(S) 6 ∞
13
Update 2 6 3 4 d(5) is not changed. 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 3
1 2 3 1 6 4 2 3 3 5 3 4 3 3 5 4 4 6 d(5) is not changed. 6 ∞
14
Choose Minimum Temporary Label
2 6 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 3 4 6 ∞ 5 4 4 6 Extract-Min(S)
15
Choose Minimum Temporary Label
2 6 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 3 4 5 4 6 4 6 Extract-Min(S) ∞
16
Update d(4) is not changed 2 6 6 3 4 Decrease-Key(S,6,6) 4 2 4 2 2 1
6 1 2 3 1 6 4 2 3 3 5 3 4 5 4 6 4 6 Decrease-Key(S,6,6) 6
17
Choose Minimum Temporary Label
2 6 4 2 4 2 2 1 2 3 6 1 6 4 2 3 3 5 3 4 4 6 6 6
18
Update 2 6 6 3 4 d(6) is not updated 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 4 6
1 2 3 6 1 6 4 2 3 3 5 3 4 4 6 6 6 d(6) is not updated
19
Choose Minimum Temporary Label
2 6 4 2 4 2 2 1 2 3 6 1 6 4 2 3 3 5 3 4 6 6 There is nothing to update
20
End of Algorithm 2 6 6 3 4 All nodes are now permanent
1 2 3 6 1 6 4 2 3 3 5 3 4 All nodes are now permanent The predecessors form a tree The shortest path from node 1 to node 6 can be found by tracing back predecessors
21
Implementations Decrease-Key(S,x,key): Call at most m times.
Extract-Min(S): Call n times. With min-priority queue, Dijkstra algorithm can be implemented in time
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.