Tracing Dijkstra's algorithm – OCR A Level Computer Science lesson (H446)
Students learn to trace Dijkstra's algorithm with a priority queue, recording each distance and previous node, and read the path back from the goal.
Lesson 2 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 do you show every step of Dijkstra's algorithm?
By the end, students can trace Dijkstra's algorithm with a priority queue, recording each distance and previous node, and read the path back from the goal.
- The Build (the main task)
- Trace Dijkstra's algorithm from G on Harrowgate Fulfilment's warehouse floor graph, showing the priority queue, each node's distance and previous node after every visit, then give the shortest path to P by working back from P.
- Support version
- A trace table with the column headings, the first two rows completed and the order of visits given; students fill in the distances, previous nodes and queue contents.
- Challenge
- Explain the complexity of Dijkstra's algorithm when the unvisited nodes are kept in a list, and why a priority queue held as a heap helps when the warehouse graph has thousands of junctions.
- Real-world link
- Harrowgate Fulfilment's route planner, which works out each robot's path before it leaves Goods-in.
- Key words
- Priority queue, Shortest path and Trace, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “Items leave a priority queue in the order they arrived, like a normal queue”; “A trace can jump straight to the final distances”.
- 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 describe how Dijkstra's algorithm finds the shortest path in a weighted graph and why each step keeps the lowest total.
Free sample lessonStudents 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.