Alice thinks of a natural number between 1 and 10,000 (inclusive). Bob must guess it. Each time Bob makes a guess, Alice tells him whether it is too small, too big, or correct. If it is not correct, Bob guesses again.
How many guesses does Bob need in order to correctly identify Alice's number?
Clarification: It is not enough for Bob to figure out Alice's number. He must actually say it. That is, Bob's last guess must be the right answer.
From Guessing games
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Suppose Alice is going to choose a number between ℓ and h (both inclusive), which is a set of h − ℓ + 1 numbers Clearly the number of guesses required when ℓ = h is 1.
Now suppose ℓ < h , and suppose Bob guesses some number k with ℓ ≤ k ≤ h . If k happens to be Alice's number, then Bob is done, but otherwise space of possibilities is divided into two: ℓ to k − 1 and k + 1 to h . In the worst case, Alice's number is in the larger of these two intervals, so that the number of guesses Bob needs is one more than the number of guesses needed for the larger of the two intervals. (One more to account for his first guess which was k ). Clearly this will be minimized if Bob makes the two intervals as close as possible in size. That is, they are either of equal size or their sizes differ by 1.
Thus, if we start with an interval of length N then Bob's best strategy is to have his guess divide the interval into two intervals, one of size ⌊ N / 2 ⌋ and the other either the same size or one less.
Each time the length of the interval is halved, Bob has used one guess. And he needs one guess for an interval of length 1. An easy induction now shows that the number of guesses required for an interval of length N is ⌊ lo g 2 ( N ) ⌋ + 1 . Note that this is both the number of guesses Bob needs in the worst case, as well as a sufficient number in any case, since we have demonstrated a strategy for Bob.
Plugging in N = 1 0 , 0 0 0 , we get ⌊ lo g 2 ( 1 0 , 0 0 0 ) ⌋ + 1 = 1 4