Number Hunt

Find it fast — or find it slow?


Year 9 Computer Science — Binary Search

I'm thinking of a number...

1 to 100

Guess it. I'll tell you HIGHER or LOWER.


How many guesses will you need?

Two Strategies

Linear search: Guess 1, then 2, then 3... up to 100. Worst case: 100 guesses.


Binary search: Always guess the MIDDLE of the remaining range. Worst case: 7 guesses.


Binary search is roughly 14× faster for 100 items. For 1,000,000 items: 50,000× faster.

Binary Search: How It Works

1–100
→ guess 50
51–100
→ guess 75
51–74
→ guess 62
63–74
→ guess 68

Each guess halves the remaining range.

Midpoint formula: (low + high) ÷ 2, rounded down.

Round 1 — Linear Search

Teacher thinks of a number 1–100.

Class guesses: 1, 2, 3, 4, 5... raise hands in order.


Count every guess. Record the total.


(This might take a while. That's the point.)

Round 2 — Binary Search

Play in pairs. One thinks, one guesses using binary search.

Always guess the exact midpoint — no intuition!

Play 5 rounds. Record guesses each time.


Complete Part 2 and 3 on your worksheet.

The Numbers

Binary search worst case for various list sizes:

10 items → 4 guesses (log₂ 10 ≈ 3.3)
100 items → 7 guesses
1,000 → 10 guesses
1,000,000 → 20 guesses
1,000,000,000 → 30 guesses

Double the list size → only 1 more guess.

Why Must It Be Sorted?

Binary search only works if you can say "the answer is definitely in the HIGHER half."


If the list isn't sorted, you can't discard any half — you might be wrong.


Unsorted list → must check every item → linear search.

Key Takeaway

Binary search halves the problem with each guess.

For 1 million items: binary finds it in ~20 guesses.
Linear might need 1,000,000.

The list must be sorted. That's the trade-off.
1 / 9