Binary search: how to explain it to a child
Binary search explained with a number guessing game: why 7 questions are enough for 100 numbers, what the algorithm looks like step by step and which mistakes children make.
Updated:

Binary search is one of the first algorithms where a child sees that a clever method beats patience. The easiest way to start is with a game.
The game: guess the number
Think of a number from 1 to 100. The child guesses, and you answer only “too low”, “too high” or “got it”.
At first children guess blindly or ask in order: 1, 2, 3… That's the moment to ask which number is worth starting with, so that as many numbers as possible are sure to drop out. The answer is the middle: 50.
Why the middle
After asking about 50, half of the numbers are left, whatever the answer. After the next question, a quarter. The range shrinks like this: 100, 50, 25, 13, 7, 4, 2, 1. That's seven questions. For a thousand numbers ten are enough, and for a million, twenty.
Asking in order, you would need a hundred questions in the worst case.
The algorithm step by step
- Remember the two ends of the range:
leftandright. - Work out the middle.
- If the middle is the number you are looking for, stop.
- If it is too low, move
leftto just past the middle. If it is too high, moverightto just before the middle. - Go back to step 2.
It's a loop with a decision inside and two variables that move towards each other.
Where it comes in handy
- Looking up a word in a paper dictionary: you open it in the middle and know which way to go.
- Finding a page in a book.
- Guessing a height, a price, a date.
There is one condition: the data has to be ordered.
Common mistakes
- The range doesn't shrink. If
leftmoves to the middle rather than past the middle, the loop can go round forever. - The data isn't sorted. Then the algorithm rules out a half that might have held the answer.
- The number isn't there. The loop has to end once
leftpassesright.
In Looponi
Binary search is one of the algorithms on the track for grades 7–8. The pupil builds it as a flowchart, guesses how many times the loop will go round, and watches the ends of the range move towards each other with every step.
Frequently asked questions
What is binary search?
It's a way of searching ordered data in which every question rules out half of the possibilities. We check the middle and go left or right.
How many questions does it take to guess a number from 1 to 100?
At most 7. Each question halves the range: 100, 50, 25, 13, 7, 4, 2, 1.
Why does the data have to be ordered?
Because only then does the answer “too low” or “too high” tell you which half can be ruled out. With jumbled data you have to check the items one by one.
At what age can this be taught?
An eight-year-old already understands the number guessing game. The algorithm itself, with variables, is worth introducing at about 12–13.