Dijkstra's Shortest Path Algorithm
Aligned to the AQA 7517 specification
- Level
- Advanced
- Reading time
- 7 min
- Published
- 6 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- Dijkstra's algorithm solves the single-source shortest path problem on weighted graphs with non-negative edge weights, finding the shortest path from one source to every other vertex.
- Each step selects the unvisited vertex with the smallest tentative distance, relaxes its unvisited neighbours, then marks it permanently visited so its distance is confirmed.
- The greedy property holds only because edge weights are non-negative: once a vertex is permanently visited, no shorter path to it can be found later.
- The shortest path is reconstructed by working backwards through the predecessor (via) column from the destination to the source.
- Dijkstra works on unweighted graphs but is unnecessarily slow; BFS achieves the same result in O(V + E) time, and negative edge weights require Bellman-Ford, which is not required by AQA 7517.
Studying this for an exam?
Generate a personalised learning path for this subject. Free to get started.
Key terms
- Dijkstra's algorithm
- A greedy algorithm that solves the single-source shortest path problem on weighted graphs with non-negative edge weights.
- Single-source shortest path
- The problem of finding the shortest path from one given source vertex to every other vertex in the graph.
- Tentative distance
- The shortest distance found so far from the source to a vertex; initially zero for the source and infinity for all others.
- Current vertex
- At each step, the unvisited vertex with the smallest tentative distance, whose neighbours are then examined.
- Permanently visited
- A vertex whose recorded shortest distance has been confirmed as the smallest possible and must not be changed again.
- Greedy property
- The principle that once a vertex is permanently visited, no shorter path to it can be discovered later, which holds only for non-negative edge weights.
- Predecessor
- The vertex an update came from, recorded alongside each tentative distance so the shortest path can be reconstructed backwards.
Frequently asked questions
Because the greedy guarantee depends on it: once a vertex is marked permanently visited, no shorter path to it can be discovered later only as long as all edges add further non-negative weight. With a negative edge a confirmed vertex could later be reached more cheaply, breaking the guarantee, so Bellman-Ford is needed instead (not required by AQA 7517).
Work backwards from the destination through the predecessor (via) column, which records which vertex each tentative distance came from, until you reach the source. Tracing forwards from the source often picks up incorrect branches, so always reconstruct backwards.
No. AQA exams do not ask you to recall the steps from memory. You are given a partially completed working table and asked to continue or complete the trace, so the exam tests your understanding of the logic of each step rather than rote recall.
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Sorting Algorithms
Abstraction and Automation
Related lessons
5 min
8 min
8 min