April 2024
Beginner to intermediate
500 pages
24h 20m
English
Using the binary search method, the computer is able to guess the secret number in just a few attempts. In fact, the maximum number of attempts is related to the range of numbers being searched. The maximum number of attempts to find the secret number in a group of n numbers should be no more than log2(n). So for our range of 100 numbers, calculating log2(100) is 6.6. Rounding off, the maximum number of guesses for 100 numbers is 7. We can verify this by counting the number of guesses the computer makes. To do that, we can use the accumulator pattern.
An important problem-solving technique is the accumulator pattern. Your ability to recognize this commonly occurring pattern and then implement ...
Read now
Unlock full access