Consider the numerical 20 questions game. In this game, player 1 thinks of a number in the range 1 to n. Player 2 has to figure out this number by asking the fewest number of true/false questions.Assume that nobody cheats. i. What is an optimal strategy if n in known? ii. What is a good strategy is n is not known?
1 Answer
Please refer to this wiki: binary search for number guessing game.
If n is known, use binary search algorithm to find it, so asked questions is not more than floor(log2(n)).
If n is unknown, you can first find an upper bound by repeated doubling, then apply binary search. It's clear that asked questions is not more than 2 * floor(log2(k)) + 1, where k is the unknown selected number.
nis known, otherwise the problem becomes more interesting.