Guess my number: a search algorithm
Play "too high, too low" against the computer and discover the clever halving trick that search engines and computers use to find things fast.
- Computational thinking
- Critical thinking
- Measuring & data
🔍 How does a computer find things so fast?
Your phone can find one name among thousands of contacts in a blink. It doesn’t check them one by one. It uses a clever plan called an algorithm. Today you’ll discover one of the most famous algorithms by playing a game.
🎮 Try it on the screen
First you guess the computer’s number. Then swap: think of a number and let the computer guess. Watch how few guesses it needs!
Yellow = where the number could still be (100 numbers left)
I am thinking of a number from 1 to 100. Tip: always guess the middle!
🛠️ The family guessing game
- One person thinks of a number from 1 to 100 and writes it down secretly.
- Everyone else takes turns to guess. The answer can only be “too high”, “too low” or “yes!”.
- Count the guesses with tally marks. Play 3 rounds.
- Now try the halving trick: always guess the number in the middle of what’s left. Start with 50. If it’s too high, try 25. If it’s too low, try 75…
- Play 3 more rounds with the trick and compare the tallies. Which way wins?
💡 What happened?
Each halving guess throws away half of the numbers that are left. 100 → 50 → 25 → 13 → 7 → 4 → 2 → 1. So you never need more than 7 guesses for 1 to 100! Computer scientists call this binary search. It only works when things are in order (like numbers, or words in a dictionary). That’s one reason computers keep lists sorted.
Did it work?