Education
 

Dijkstra's algorithm

From Mathematics

Dijkstra's algorithm is one of the most widely used methods for finding single-source shortest paths in a simple digraph. In other words, Dijkstra's algorithm determines the shortest paths from a common vertex math to all other vertices in a digraph, if they exist.

Contents

[edit] Algorithm

Let math be a simple digraph with a function math which assigns a weight, a non-negative real number, to each arc in math. Fix a source vertex math in math, from which shortest paths will be found.

Additionally, for the purposes of the search itself, let math denote the length of the shortest path from math to math. Let math denote the set of visited vertices, i.e., those vertices that have already been examined by the algorithm. Given a path math in math determined by the algorithm, let math denote the predecessor of math for any math in math such that math. The meanings of these additions will become clear in the description of the algorithm. The execution proceeds as follows.

[edit] Initial Stage

  1. Let math. [1]
  2. For each vertex math adjacent from math, let math be math, and let math.
  3. For each vertex math such that math and math is not adjacent from math, let math. [2]
  4. Let math. [3]

[edit] Iterative Stage

  1. Determine the vertex math that minimizes math in math, i.e., an unvisited vertex.
  2. For each vertex math adjacent from math, compare the current value math and math. If math is the least of the two, let math, and let math.
  3. Mark math as visited. That is, let math.
  4. If math, all vertices have been visited; halt. Otherwise, return to the first step.

[edit] Additional Details

[edit] Interpretation of Results

When the execution terminates, every vertex math for which math has a shortest path. This shortest path is determined by repeated application of math to math. For instance, a shortest path from math to math, four vertices long, would be described math. For any vertex math where math, there is, of course, no shortest path from math to math.

[edit] Non-negativity Constraint

Because Dijkstra's algorithm is a special case of uniform cost search, where there is no particular goal state, it is essential that math for all arcs in math.

[edit] Dynamic Programming

Dijkstra's algorithm is also an instance of dynamic programming.[4] Let math equal the value of math in the mathth iteration of the algorithm, where math initially and math. Let math denote the weight of the shortest path from math to math, given the knowledge of math. Then

math

Therefore, the purpose of Dijkstra's algorithm is to determine the best policy for transforming the state of the problem (i.e., which vertex to move to next). It does so by refining an approximation of the best shortest-path policy for all vertices with each iteration, until the full solution is realized. The algorithm is efficient in practice because each iteration relies on previously determined information.

[edit] Notes

  1. ...since there is no effort in staying in place.
  2. That is, the distance is unknown and math is assumed to be unreachable until it is proven otherwise.
  3. ...since no paths from math to itself need to be considered.
  4. To preempt any accusations of plagiarism, the description that follows was cribbed by the author from an article he himself wrote on PlanetMath.