next up previous index
Next: Initialisation Up: Shortest Paths in Weighted Previous: Paths and lengths   Index


Dijkstra's algorithm

We wish to find the shortest path from some node $s$ to every other node in the graph which is reachable from $s$. Let $N$ be the set of all nodes in the graph. Our aim is to determine (i) the subset $R
\subseteq N$ consisting of all nodes $v \in N$ which are reachable from $s$ and (ii) the function $d(v)$, defined on $R$, such that, if $v \neq s$, $d(v)$ is the minimum of the lengths of paths from $s$ to $v$, otherwise conventionally we set $d(s)=0$. Initially we know only that $s \in R$ and $d(s)=0$.

The algorithm is iterative. At each stage we maintain two subsets of nodes, $S$ and $S^{\ast}$, satisfying

\begin{displaymath}
s \in S \subseteq S^{\ast} \subseteq R
\end{displaymath}

as pictured in Figure 13.2.

Figure 13.2: Dijkstra's algorithm.

\begin{picture}(120,76)(-10,-8)
\put(-10,-8){\framebox (120,76)}
\put(50,30){\...
... \put(92,52){\makebox(0,0){$R$}}
\put(105,63){\makebox(0,0){$N$}}
\end{picture}

$S^{\ast}$ consists of those nodes which belong to $S$ or are adjacent to some node in $S$. $S$ and $S^{\ast}$ grow as the algorithm proceeds. The algorithm terminates when $S = S^{\ast} = R$.

We assume that a function $D(u)$ is defined for all $u \in S^{\ast}$ satisfying:

A1:
if $u \in S$, then $D(u) = d(u)$;
A2:
if $u \in S^{\ast}-S$, then there is an $S$-path from $s$ to $u$ and $D(u)$ is the minimum length of all such paths
where an $S$-path is defined to be one which only visits nodes in $S$ before finally jumping to $u$. Note that $D$ will change as $S$ grows. A1 asserts that $D$ gives the correct final answer on $S$. The values of $D(u)$ that may change are the provisional ones defined on $S^{\ast}-S$.



Subsections
next up previous index
Next: Initialisation Up: Shortest Paths in Weighted Previous: Paths and lengths   Index
Peter Williams 2005-06-07