Dijkstra's shortest path algorithm – OCR A Level Computer Science lesson (H446)
Students learn to describe how Dijkstra's algorithm finds the shortest path in a weighted graph and why each step keeps the lowest total.
Lesson 1 of 17 in unit 13.4 Path-finding, Computational Methods and Project Development, taught in Year 13, Autumn 2. It answers one big question: How does a robot find the shortest route across the warehouse?
By the end, students can describe how Dijkstra's algorithm finds the shortest path in a weighted graph and why each step keeps the lowest total.
- The Build (the main task)
- Describe how Dijkstra's algorithm finds the shortest route for a Harrowgate Fulfilment picking robot from Goods-in to Packing on the warehouse floor graph: Goods-in G to Packing P, with edges G–A 4, G–B 2, A–B 1, A–C 5, B–C 8, B–D 10, C–D 3, C–P 7, D–P 2, A–E 9 and E–P 4 (metres), and state the route and its length.
- Support version
- The graph printed with a part-filled table of nodes, distances and previous nodes, and a step card: choose the unvisited node with the lowest distance, update its neighbours only if the new total is lower, mark it visited.
- Challenge
- Explain why the route with the fewest edges (G–B–D–P, 14 m) is not the shortest, and how Dijkstra's algorithm avoids choosing it.
- Real-world link
- Harrowgate Fulfilment, a fictional online-order warehouse, sends picking robots between the goods-in bay, aisle junctions and the packing benches.
- Key words
- Dijkstra's shortest path algorithm, Weighted graph and Optimal, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “A node's distance is replaced whenever a new route to it is found, even if the new route is longer”; “The shortest route is the one with the fewest edges”.
- OCR H446 specification
- 2.3.1 (f) (standard algorithms: here Dijkstra's shortest path algorithm and the A* algorithm, traced on weighted graphs and compared (the searching and sorting algorithms in this point were taught in 12.4)).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Students can do it all on paper.
Also sold in the Path-finding, Computational Methods and Project Development unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
An independent resource written for OCR A Level Computer Science (H446). It is not endorsed by OCR or Cambridge University Press & Assessment. Programming project (NEA) lessons teach general skills on a made-up example project and give supervised time, within JCQ's rules on the help a centre may give.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for A Level Computer Science
See allStudents learn to trace Dijkstra's algorithm with a priority queue, recording each distance and previous node, and read the path back from the goal.
Students learn to plan sprint 2 from their design and review of sprint 1, and write modular, annotated code with dated journal entries.
Students learn to describe how A* uses f = g + h to choose nodes, and explain what its heuristic estimates and why it reduces the nodes searched.
Written for the specifications named. Not endorsed by or affiliated with any exam board.