Partial Solution to Part 6 Questions Algorithm outline: 1. Pick a random number in [0,100] as the correct answer. 2. Print out welcoming messages and instructions for the user. 3. Get a number from the user. 4. If the guess is equal to the answer, prints out proper message with the number of guesses made so far and terminate. 5. Compare the guessed number with the answer. Prints out "too high" or "too low" according to the result. 6. If user has made too many guesses so far, prints out proper message with the correct answer and terminate. 7. If not, prompts the user for another guess. 8. Go back to step 3. Analysis: - The number-guessing game involves discrete search. The program picks an integer in [0,100] as an answer. So there are only finite number of possible answers. In other words, 'search space' is finite. What does continuous mean? Imagine if someone picked a number, like 50.0012182. Or, maybe they could have picked 50.01231291, and so on. Between 0 and 100, there an infinite number of numbers. - Search space is initially [0,100]. So guess 50, which is the value in the middle. If the response is 'too low', the answer must be in [51, 100], which is the new search space. if 'too high', new search space is [0, 49]. Again, guess the middle value in the search space. Repeat this until the correct answer is guessed eventually. - A less efficient (but still valid) strategy would be to try each number 1, 2, 3 sequentially. However it does not benefit from the hints given by the program. One could rate various approaches based upon the number of guesses the user has to make in the worst case. Or the average number of guesses could be used. - A sequential search requires at least as many guesses as binary search. - A binary search is more efficient than a sequential search. It fully makes use of the comparison result from the program by halving the search space at each guess, no matter what the answer or guesses are. - A thought question: what if you randomized the initial guess? Or perhaps started with 25 and 75 "some" of the time? How would those strategies improve your chances?