
Int possibleGuesses = highRange + lowRange - 1

# include // Library used for math in this case log() and ciel() * This program was written in the C programing language * This is the number guessing game program */ Hence the worst case running time is log 2(Max - Min + 1). The maximum number of turns it takes to guess a number from 1 to 100 is log 2(100 -1 +1)= log 2(100) = 7. A binary search is a dichotomic divide and conquer search algorithm.

The Number Guessing Game uses binary search to quickly find a solution. The Algorithm will tell you if it is possible to guess player A's number in the given amount of turns x, and will tell the maximum amount of tries or guesses you will need in order to guess there number correctly. Player A will assist player B by telling player B if the number they guessed is higher than or lower than player A's randomly chosen number.

To play the guessing game, a person (player A) will choose a random number from n to m, another person (player B) will have to guess player A's number in "x" turns. Let's look at the guessing game as another example of using a Divide and Conquer Algorithm by halving our possible number of guesses.
