Single lesson · Written for OCR J277

Coding a search – OCR GCSE Computer Science lesson (J277)

Pupils learn to write a binary search in Python on an ordered 1D array and explain when a linear or a binary search is more efficient.

Also in a bundle Networks and Searching – OCR GCSE Computer Science lessons (J277) 11 lessons for £39 · save 11% on buying separately

Lesson 10 of 11 in unit 10.5 Networks and Searching, taught in Year 10, Summer 1. It answers one big question: Which search should a program use, and why?

By the end, pupils can write a binary search in Python on an ordered 1D array and explain when a linear or a binary search is more efficient.

The Build (the main task)
Write a Python program that uses a binary search to find a book ID in the ordered catalogue array, printing its position or 'Not found', and counts the comparisons it makes.
Support version
Part-filled code: the array, the loop and the output are written; pupils complete the midpoint line and the two lines that move first and last.
Challenge
Add a linear search to the same program and compare the comparison counts for three IDs: the first in the list, one in the middle and one not in the list.
Real-world link
The online catalogue must find a book among 60,000 in a blink – which search should it use?
Key words
Linear search, Binary search and Efficient, each with a definition, an icon and a common mix-up on the key vocabulary slide.
Misconceptions it tackles
“After checking the midpoint you set first = mid or last = mid”; “mid = (first + last) / 2 finds the midpoint in Python”.
OCR J277 specification
2.1.3 (searching algorithms: how linear search and binary search work, the steps of each, and what a binary search needs (an ordered list)); 2.2.3 (additional programming techniques: using 1D arrays (Python lists) as data structures, here to hold the lists that are searched).

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.

Pupils need computers for the main task.

Also sold in the Networks and Searching unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.

What's included

  • Slide deck (PowerPoint)
  • Lesson plan (Word)
  • Worksheet (Word)
  • Support worksheet with scaffolds (Word)
  • Coding a search - Quiz Quiz Trade Cards
  • Single-teacher licence: use and adapt it with your own classes

More for GCSE Computer Science (OCR)

See all

Written for the specifications named. Not endorsed by or affiliated with any exam board.