Dijkstra's Algorithm

1/0
1.0x

Dijkstra's Algorithm

O((V+E) log V)Space: O(V)

Pseudocode

1procedure Dijkstra(graph, source)
2 dist[source] ← 0
3 for each vertex v: dist[v] ← ∞
4 add all vertices to priority queue Q
5 while Q is not empty do
6 u ← extract-min from Q
7 for each neighbor v of u do
8 alt ← dist[u] + weight(u, v)
9 if alt < dist[v] then
10 dist[v] ← alt
11 decrease-key v in Q
12 return dist