D1 2.2 - Dijkstra's algorithm
Find a shortest route through a weighted network by keeping tentative distances and fixing them in a safe order. You will show Dijkstra's working values, recover the route from the final labels, and interpret changes when a road closes.
Temporary and permanent labels
Can the shortest route begin with an edge that is not the shortest-looking line on the page? The numbers, rather than the drawn lengths, decide. Even the smallest edge from your current position need not lead towards the best overall route.
Dijkstra's algorithm works here on a connected, undirected network with nonnegative edge weights. A label is a distance from the chosen start, not the length of the most recent edge.
Temporary and permanent labels
A temporary label, also called a working value, is the shortest distance to that vertex found so far. It may decrease. A permanent label, or final value, is the established shortest distance from the start. Record its order of labelling separately: order does not mean distance .
Set the start's permanent distance to , with order . Initially other distances are unknown, represented by . From the newly permanent vertex , calculate
Update an unlabelled neighbour only when this improves its temporary value. Then make the smallest temporary value anywhere in the network permanent. If smallest values tie, either tied vertex may be selected next; use distinct order numbers.
[DIAGRAM: asset_name: A shortest-path network; asset_slug: dijkstra-network; caption: A working value measures the whole route from A, not just the last edge.; description: Undirected edges AB 7 AC 3 BC 2 BD 4 CD 8 CE 5 DE 1 DF 6 EF 4 BF 15 on vertices A B C D E F. A separate key shows vertex, order, final value and ordered working values.]

Worked example 1: the first update
On this network, start at .
Plan. Fix at zero and update its two neighbours.
The candidates are at and at . All other vertices remain unknown.
Answer. Temporary values ; select next, with order and final value .
Check. These are the two one-edge routes from , and .
Change only the vertex being processed, from to the newly fixed . This reveals an improvement to an earlier estimate.
Worked example 2: revising a working value
Process , whose final distance is .
Plan. Add each edge from to , ignoring already permanent .
Keep 's working values in the order ; do not erase the earlier . Now compare all temporary values .
Answer. Select next, with order , final value .
Check. The route has length , less than direct .
Why may the smallest temporary label be fixed? Any route through an unfixed vertex must first reach an unfixed vertex at least this far away. Adding nonnegative edge lengths cannot produce a smaller arrival at the chosen vertex. Negative weights would break that argument.
Watch out
Choose the smallest total temporary distance, not the smallest outgoing edge. Keep improving working values in their actual order; a correct final value alone does not show the algorithm.
Apply one update before choosing the next vertex.
Finding a shortest distance
Continue the updates until the destination is permanent; a temporary destination label can still improve.
Use a table to make the trace readable. A dash below means no new improving value, rather than a zero distance. When a candidate is larger than or equal to a current working value, retain that current value; it need not be entered as a new working value.
Worked example 3: a complete trace
Find the shortest distance from to in the pictured network, whose edges are .
Plan. Process each newly permanent vertex and record every improvement before selecting the next minimum.
| Order | Vertex fixed | Final distance | New improving working values |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | None: at | ||
| 6 | Stop |
At order , the candidate at is , equal to its current , so that label stays unchanged.
Answer. The shortest distance is . Ordered working values are .
Check. The final distances satisfy in both directions on every edge. For example and . A route actually attains , confirming the distance.
Change just from to . This delays , so both the order and 's working values change.
Worked example 4: a revised edge
Repeat Dijkstra's algorithm with , all other edges unchanged.
Plan. Recalculate the trace; do not keep the old permanent order automatically.
| Order | Vertex fixed | Final distance | New improving working values |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | Stop |
Answer. The shortest distance is , with 's working values .
Check. The route has length . All revised final labels satisfy the edge inequalities above, so no route can beat them.
Continue this lesson.
You’re previewing NovaLearn without an account. Create a free account to read the rest.
Create free account