Traversing graphs – OCR A Level Computer Science lesson (H446)
Students learn to store a graph as an adjacency list and trace depth-first and breadth-first traversals using a visited list.
Lesson 12 of 15 in unit 12.8 Data Structures, taught in Year 12, Spring 2. It answers one big question: How do we visit every place on a map exactly once?
By the end, students can store a graph as an adjacency list and trace depth-first and breadth-first traversals using a visited list.
- The Build (the main task)
- Write a breadth-first traversal in Python that uses a dictionary adjacency list of Tillbrook's depots, a queue and a visited list, and outputs every depot reachable from the main hub (6 marks).
- Support version
- The adjacency list given as a Python dictionary and the traversal as a Parsons problem, with the OCR pseudocode version alongside.
- Challenge
- Write the depth-first version with a stack, and explain why its output order differs.
- Real-world link
- Checking which depots a van can still reach from the main hub when a road closes.
- Key words
- Adjacency list, Visited list and Explore, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “A graph traversal does not need a visited list”; “An adjacency list is always better than a matrix”.
- OCR H446 specification
- 1.4.2 (b); (c).
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 need computers for the main task.
Also sold in the Data Structures 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 choose a record, tuple, list or array of up to three dimensions for given data, and declare each.
Free sample lessonStudents learn to compare static and dynamic data structures and justify one for a given use.
Students learn to trace push, pop and peek on an array-based stack and write a pop that checks for an empty stack and moves the top pointer before returning.
Written for the specifications named. Not endorsed by or affiliated with any exam board.