Study resource
Optimisation algorithms revision notes
Study Optimisation algorithms with curriculum-aligned Revision Notes resources, practice links, and exam-focused support.
At a glance
revision notes
Resource type
Topic
Optimisation algorithms
Revision notes
Dijkstra’s Shortest Path Algorithm
Purpose
Dijkstra’s shortest path algorithm finds the shortest route from a chosen starting vertex to other vertices in a weighted graph. A path’s length is the total of the edge weights along that path, so the algorithm must compare complete routes rather than just individual edges. Applications include finding routes in road or map systems and selecting efficient routes through communication networks.
Tracing the algorithm
During a trace, keep a tentative distance for each vertex. The starting vertex has distance
0; the other distances are initially treated as unknown or infinitely large. The algorithm repeatedly considers the unprocessed vertex with the smallest tentative distance. It then checks routes from that vertex to its neighbours. If travelling through the current vertex gives a smaller distance, the neighbour’s tentative distance is updated. The selected vertex is then treated as having its shortest distance established.Worked example
Consider these weighted connections:
S–A = 4S–B = 1B–A = 2A–C = 1B–C = 5C–D = 3A–D = 7
Start at
S. The initial distances areS = 0,A = ∞,B = ∞,C = ∞, andD = ∞. FromS, updateAto4andBto1. The smallest unprocessed distance isB = 1, so examine routes throughB:B–Agives1 + 2 = 3, improvingAfrom4to3;B–Cgives1 + 5 = 6, soCbecomes6. Next,A = 3is smallest. ThroughA,Cbecomes3 + 1 = 4, andDbecomes3 + 7 = 10. Next,C = 4givesD = 4 + 3 = 7, improving it to7. The resulting shortest route fromStoDisS–B–A–C–D, with total length7.Common errors
- Choosing the edge with the smallest individual weight instead of comparing total route lengths.
- Forgetting to update a neighbour when a shorter route is discovered.
- Treating a tentative distance as final before the algorithm has selected that vertex.
- Adding edge weights incorrectly when tracing a route.
- Reporting only the final distance when the question asks for the actual path.
Related topics
