Single lesson · Key Stage 3

Linear and binary search – Year 9 Computing lesson

Pupils learn to trace a linear search and a binary search, explain why binary search needs an ordered list, and write a linear search function in Python.

Also in a bundle Searching and Sorting – Year 9 Computing lessons 6 lessons for £20 · save 16% on buying separately

Lesson 3 of 6 in unit 9.2 Searching and Sorting, taught in Year 9, Autumn 2. It answers one big question: How can a computer find one item in a huge list?

By the end, pupils can trace a linear search and a binary search, explain why binary search needs an ordered list, and write a linear search function in Python.

The Build (the main task)
Write a Python function linear_search(books, target) that returns the index of the target title, or -1 if it is not in the list, and test it with one title that is in the list and one that is not.
Support version
Parsons problem: the function's lines are jumbled with one extra line that returns too early; pupils number them in order and cross out the extra line.
Challenge
Trace a binary search for a title in an ordered list of 15 books, then state the most checks each search needs for 1,000 books.
Real-world link
The library catalogue holds thousands of titles: pupils compare checking every book in turn with jumping to the middle of an A–Z list.
Key words
Linear search, Binary search and Ordered, 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, sorted or not”; “A linear search always checks every item, even after it has found the target”.
National Curriculum
NC2 (key algorithms (e.g. searching and sorting); compare alternative algorithms); NC3 (two or more languages, at least one textual; data structures; modular programs with procedures or functions).

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.

Also sold in the Searching and Sorting 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)
  • Single-teacher licence: use and adapt it with your own classes

More for KS3 Computing

See all

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