Proofs of Algorithm Correctness and Runtime Estimates · Guessing a Number

Lesson 3

Nikolai Chukhin · Alexander S. Kulikov

There is a well-known and intuitive strategy for this task: binary search. Initially, you know that \(0 \le x < 16\). The first question you may want to ask is whether \(x<8\): if the answer is positive, then \(0 \le x < 8\); otherwise, \(8 \le x < 16\). In any case, the current range becomes two times smaller. By proceeding in the same fashion, in four questions, you will arrive at a range of length one meaning that at this point you already know \(x\) for sure.