Problem 28.7 Easy Free

Guessing a Number by Halving

A friend secretly picks an integer uniformly at random from 11 to 10001000. You repeatedly guess integers, and after each guess the friend tells you only whether the true number is higher or lower than your guess (or that you are correct). Find the smallest nn such that you have a strategy guaranteeing you identify the number within nn guesses, no matter which number was chosen.

Work it out, then compare with the answer.

SolutionShow the worked solution

Key idea. Each answer leaves either the guessed number (and you have found it) or one of two smaller sets, so kk guesses can handle at most 2k−12^k-1 candidates.

Let f(k)f(k) be the largest number of candidates for which some strategy is guaranteed to guess the number within kk guesses. Here “identify” means making the correct guess.

Upper bound. Suppose the current candidate set SS can be resolved in kk guesses, and the first guess is gg. The reply “correct” covers at most one candidate. The candidates below gg must then be resolved in k−1k-1 further guesses, and so must those above gg. So each of these two sets has at most f(k−1)f(k-1) elements. Hence

f(k)≤1+2f(k−1),f(0)=0.f(k)\le 1+2f(k-1), \qquad f(0)=0 .

Induction gives f(k)≤2k−1f(k)\le 2^k-1.

Achievability. We show by induction that any block of 2k−12^k-1 consecutive integers can be resolved in kk guesses. For k=0k=0 the block is empty and there is nothing to do. For k≥1k\ge 1, guess the middle element of the block. If the reply is “correct” you are done. Otherwise the remaining candidates form a block of 2k−1−12^{k-1}-1 consecutive integers, which the induction hypothesis resolves in k−1k-1 more guesses. So f(k)=2k−1f(k)=2^k-1.

Applying this to 10001000 numbers.

  • Since 29−1=511<10002^9-1=511<1000, no strategy can guarantee success within 99 guesses.
  • Since 210−1=1023≥10002^{10}-1=1023\ge 1000, ten guesses suffice. Run the halving strategy on {1,…,1023}\{1,\dots,1023\}; the extra numbers 10011001 to 10231023 are simply never the answer. Equivalently, always guess the midpoint of the remaining interval.

The uniform randomness of the choice plays no role, because the guarantee must hold for every number. The tempting count of 2k2^k numbers in kk guesses is slightly off; the correct count is 2k−12^k-1. Here this does not change the answer.

n=10\boxed{n=10}