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.
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 allPupils learn to use decomposition, pattern recognition and tracing an algorithm step by step to solve Bebras-style algorithmic puzzles and explain their method.
Free sample lessonPupils learn to complete the 45-minute UK Bebras Challenge (Intermediates) on their own, choosing a strategy for each task.
Free sample lessonPupils learn to carry out a bubble sort by hand, showing the list after each pass, and explain how the algorithm knows the list is sorted.
Written for the specifications named. Not endorsed by or affiliated with any exam board.