Binary search – OCR A Level Computer Science lesson (H446)
Students learn to write an iterative binary search and explain why it needs sorted data and how few comparisons it makes.
Lesson 4 of 15 in unit 12.4 Searching, Sorting and Recursion, taught in Year 12, Autumn 2. It answers one big question: Why is binary search so fast, and what does it need?
By the end, students can write an iterative binary search and explain why it needs sorted data and how few comparisons it makes.
- The Build (the main task)
- Write an iterative binary search in Python and OCR pseudocode that finds a track ID in Tidewave Audio's sorted catalogue of 4 000 000 IDs, and state the maximum number of comparisons it makes (6 marks).
- Support version
- Part-filled code: the loop and the comparison are given; students complete the midpoint line and the two lines that move low and high.
- Challenge
- Explain why binary search is suitable for Tidewave Audio's sorted catalogue but not for the unsorted daily uploads, using facts from the scenario (4 marks).
- Real-world link
- Each track in Tidewave Audio's catalogue has a unique ID, stored in ascending order.
- Key words
- Binary search, Sorted data and Halve, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “Binary search works on any list”; “The midpoint is (low + high) / 2, so it can be a decimal such as 3.5”.
- OCR H446 specification
- 2.3.1 (a); (f).
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 Searching, Sorting and Recursion 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 apply problem-solving strategies to unfamiliar Bebras tasks and explain the reasoning behind each answer.
Students learn to sit the UK Bebras Computational Thinking Challenge, managing their time and checking answers against the task's rules.
Students learn to write a linear search as a function in Python and OCR pseudocode, and state its best and worst cases.
Free sample lessonWritten for the specifications named. Not endorsed by or affiliated with any exam board.