L37 ShortestPath Dijkstra
L37 ShortestPath Dijkstra
Dijkstra’s Algorithm
S V-S
d[v]=δ (s, v) d[v]>δ (s, v)
MA512: Data Structures and Algorithms
3
Dijkstra’s Algorithm: Data structure
• Vertices in V – S reside in a min-priority queue
▪ Keys in Q are estimates of shortest-path weights d[u]
9 Update Q (DECREASE_KEY)
t x t 1 x
1
8 13
9 8 9
10 9 10 9
2 4 2 3 4 6
s 0 3 6 s 0
7 5 7
5
5 7 5 7
2 2
y z y z
(V)
(V) O(VlgV)
O(lgV)
O(E) times
(total) O(ElgV)
9 Update Q (DECREASE_KEY) O(lgV)
such that