Physics I / Searching and sorting ideas
Practice question · Multiple choice

You guess a number between 1 and 1000; after each guess you learn "higher" or "lower". A smart player needs at most 10 guesses. What strategy achieves this?

Hints
  1. What single guess guarantees you eliminate half the possibilities, whatever the answer?
  2. 1000 → 500 → 250 → … how many halvings until one candidate remains? (210=10242^{10} = 1024.)
Show the answer

C. Always guess the middle of the range

Why

Binary search: each middle guess halves the search space, so 1000 candidates fall in log2100010\log_2 1000 \approx 10 steps. The same idea finds words in dictionaries, entries in databases, and bugs in version history (git bisect), provided the data is sorted.

Read the lesson: Searching and sorting ideas →

Practise Searching and sorting ideas

The app has 8 more questions on this lesson, and keeps your place in the course. Physics I is free to start.

More questions on Searching and sorting ideas