Binary search

About this lesson: Binary search

In short

In a sorted list, check the middle item. If it's too small, discard the left half; if too big, discard the right half. Repeat. Pick a target and step through.

Binary search

What you'll explore

Halve it: Check the middle
In a sorted list, check the middle item. If it's too small, discard the left half; if too big, discard the right half. Repeat.
How fast?: Linear vs binary
Linear search might check every item. Binary search halves the list each time. Change the list size and compare the worst cases.
Why sorted?: Binary search on a jumbled list
Binary search assumes the list is in order. Try it on an unsorted list where 51 really is present. Step through and see what goes wrong.
Check yourself: Checks
A sorted list has 31 items.

Also in this lesson

  • Common mix-ups
  • Binary search
  • Guess my number

Words to know

binary search
Searching a sorted list by repeatedly checking the middle.
linear search
Checking items one by one.
sorted
In order.
midpoint
The middle position of the current interval.
interval
The part of the list still being searched.

Sources

  • BBC Bitesize KS3 Computer Science
  • Raspberry Pi Foundation, Computing curriculum resources

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 4 short steps and a 6-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 11 November 2026.

← Comparing two algorithms · Test plans and test data →

All lessons in Term 2 · Computing · Age 13