Shortest Path Algorithm¶
Definition¶
For nonnegative edge lengths, the course's shortest path algorithm sets and . Repeatedly choose an edge with , minimizing
Set equal to this value, record predecessor , and add to . Stop when the destination is added, or continue to obtain distances to all vertices.
Interpretation¶
Vertices enter the settled set in order of their shortest distance from the origin . A label is final as soon as enters , and the recorded predecessors recover the actual route after the distance has been computed.
The labels give the shortest distance from to each vertex; the vertices are settled in the order , with . The label of is , via , not via the direct edge: once is known, the edge offers . The red edges are the recorded predecessor edges, and following them back from gives the route of the shortest path problem.
The settled order is correct because lengths are nonnegative. Any other route to the newly chosen vertex must leave through some edge, so it already costs at least the smallest candidate value , and further nonnegative edges cannot make it shorter. With a negative length this breaks down: if has length 2, length 3 and length , the algorithm settles with , yet the route has length 1.
The Dijkstra-Prim method for minimum spanning trees grows its set in the same way but compares only the edge length , not . In the figure both rules happen to select the same edges, but in general a shortest-path tree and a minimum spanning tree differ.
Key Results¶
- Compare complete distances from the origin, not just individual edge lengths.
- Ties can be broken arbitrarily when one shortest path is sufficient.
- Backtrack from the destination through predecessors and reverse the sequence.
Examples¶
The figure settles vertices in the order . The recorded predecessor edges form a shortest-path tree rooted at .
- In the course's worked example with origin and destination (a different network from the figure), the labels are , , , , , .
- The predecessor chain recovers the route of length 12.
Prerequisites¶
Related Concepts¶
Sources¶
- OR Modelling · Week 4
Aliases: Dijkstra's shortest path algorithm Symbols: element of
Last updated: 27 October 2026 11:52
Shortest Path AlgorithmShortest Path ProblemDijkstra-Prim MethodMinimum-Weight Perfect Matching