Algorithm 6.3.1. Dijkstra’s Shortest Path Algorithm.
Let \(\Gamma=(V,E)\) be a graph, and let \(x\) be a particular vertex in \(V\text{.}\) We will define \(\dist{\Gamma}{x}{v}\) to be the currently known distance from \(x\) to \(v\text{,}\) and \(V'=\set{}\) to be an initially empty set. For each \(v\in V\setminus\set{x}\text{,}\) we define \(p(v)\) to be the predecessor of \(v\) in a shortest path from \(x\text{.}\)
- Mark \(\dist{\Gamma}{x}{x}=0\) and \(\dist{\Gamma}{x}{v}=\infty\) for every \(v\in V\setminus\set{x}\text{.}\)
- While \(V\neq V'\text{,}\) do the following:
- Let \(u\) be any vertex in\begin{equation*} \set{u\in V\setminus V': \dist(u)=\min\set{\dist{\Gamma}{x}{v}:v\in V\setminus V'}}\text{.} \end{equation*}
- Add \(u\) to \(V'\text{.}\)
- For each neighbor \(v\) of \(u\text{,}\) if \(\dist{\Gamma}{x}{v}>\dist(u)+1\text{,}\) set \(\dist{\Gamma}{x}{v}=\dist(u)+1\text{,}\) and set \(p(v)=u\text{.}\)
- Return the triple \((v,\dist{\Gamma}{x}{v}, p(v))\) for each \(v\in V\text{.}\)