Single source shortest paths

Consider the problem of finding the shortest paths from a distinguished vertex v0 to all other nodes on a graph where all edge costs are positive.

If P is a shortest path from v0 to w and v is also on that path, that is, P consists of the concatenation of path P1 from v0 to v and path P2 from v to w, then path P1 must also be a shortest path.

We will compute the shorter shortest paths first.   The shortest shortest path will be the one having one edge from v0, of minimum length.   Thereafter, the shortest shortest path will be the one of minimum length of those paths that contain just one more edge beyond a previously computed shortest path.

At each point that we discover a new shortest path, P, we update all other vertices that might have their shortest path being just one edge beyond that path P.

    Dijkstra's algorithm
       forall v in [1...n] do
          D[v] := dist(v0,v)
          prev[v] := v0
          FINAL[v] := False
       FINAL[v0] := True
       while there exists v such that FINAL[v] = False do
          choose w such that FINAL[w] = False and D[w] is minimized
          FINAL[w] := True
          forall v such that FINAL[v] = False do
             if D[w] + dist(w,v) < D[v] then
                D[v] := D[w] + dist(w,v)
                prev[v] := w

The time complexity of this algorithm is O(n2).

If e is o(n2/ log n) then we can get an algorithm of time complexity O(e log n) -- JACM Jan 1977, p.1.


Dan Hirschberg
Last modified: Mar 3, 2005