Title: Implementation of Dijkstra
1Implementation of Dijkstras Algorithm
2Dijkstras Algorithm
3Implementations
- 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 - in time
-
4An Example
?
?
4
2
4
2
2
0
2
1
3
?
1
6
4
2
3
3
5
?
?
1
0
Initialize
2
3
8
8
Select the node with the minimum temporary
distance label.
4
5
6
8
8
8
5Update Step
2
?
?
4
2
4
2
2
0
2
1
3
?
6
1
4
2
3
3
5
?
?
1
0
4
2
3
2
4
Decrease-Key(S,2,2) Decrease-Key(S,3,4)
4
5
6
8
8
8
6Update Step
2
?
?
4
2
4
2
2
0
2
1
3
?
6
1
4
2
3
3
5
?
?
8
6
4
2
3
2
4
Extract-Min(S)
4
5
8
8
7Choose Minimum Temporary Label
2
?
4
4
2
2
2
0
2
1
3
?
1
6
4
2
3
3
5
?
4
2
2
6
3
4
8
4
5
8
8
8Update Step
The predecessor of node 3 is now node 2
6
2
?
4
2
4
2
2
0
2
1
3
?
1
6
4
2
3
3
5
?
4
2
2
4
3
5
3
3
4
Decrease-Key(S,3,3) Decrease-Key(S,4,6) Decrease-K
ey(S,5,4)
6
4
8
6
9Choose Minimum Temporary Label
2
6
4
2
4
2
2
0
2
1
3
?
1
6
4
2
3
5
3
3
4
6
4
5
3
3
4
Extract-Min(S)
6
8
10Choose Minimum Temporary Label
2
6
4
2
4
2
2
0
2
1
3
?
1
6
4
2
3
5
3
3
4
3
3
5
4
6
4
Extract-Min(S)
6
8
11Update
2
6
4
2
4
2
2
0
2
1
3
?
1
6
4
2
3
5
3
3
4
3
3
5
4
6
4
d(5) is not changed.
6
8
12Choose Minimum Temporary Label
2
6
4
2
4
2
2
0
2
1
3
?
1
6
4
2
3
3
5
3
4
6
8
5
4
6
4
Extract-Min(S)
13Choose Minimum Temporary Label
2
6
4
2
4
2
2
0
2
1
3
?
1
6
4
2
3
3
5
3
4
5
4
6
4
6
Extract-Min(S)
8
14Update
d(4) is not changed
2
6
4
2
4
2
2
0
6
2
1
3
?
1
6
4
2
3
3
5
3
4
5
4
6
4
6
6
Decrease-Key(S,6,6)
15Choose Minimum Temporary Label
2
6
4
2
4
2
2
0
2
1
3
6
1
6
4
2
3
3
5
3
4
4
6
6
6
16Update
2
6
4
2
4
2
2
0
2
1
3
6
1
6
4
2
3
3
5
3
4
4
6
6
6
d(6) is not updated
17Choose Minimum Temporary Label
2
6
4
2
4
2
2
0
2
1
3
6
1
6
4
2
3
3
5
3
4
6
6
There is nothing to update
18End of Algorithm
2
6
4
2
4
2
2
0
2
1
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
19Implementations
- 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
-
20Compared with Dynamic Programming
- Dijkstras algorithm uses O(n) space.
- Dynamic programming uses O(m) space.