Loading...
Find shortest paths from a source in graphs with non-negative edge weights. Greedy picks the closest unvisited node; optimality follows from triangle inequality and non-negative edges.
1procedure DIJKSTRA(G, source)2 for each vertex v do dist[v] ← ∞; dist[source] ← 03 visited ← ∅4 repeat |V| times:5 u ← unvisited vertex with minimum dist6 mark u visited7 for each edge (u, v, w) outgoing from u do8 if dist[u] + w < dist[v] then9 dist[v] ← dist[u] + w10 end if11 end for12 end repeat13end procedure