Question: Consider the following function that is intended for a guessing game that attempt to guess a number between 1 and 100, that a user might

 Consider the following function that is intended for a guessing gamethat attempt to guess a number between 1 and 100, that a

Consider the following function that is intended for a guessing game that attempt to guess a number between 1 and 100, that a user might have thought of. 1. Suppose you intend to maintain the following loop invariant: the number to be guessed is somewhere in the interval [lo, hi]. Is this invariant maintained in each iteration of the loop? Explain why or why not 3. Suppose we make two changes in the algorithm: first, initialize hi to 101 ; second, update lo to mid +1 if the user's value is bigger than mid. The modified code maintains a loop invariant that is stronger than the invariant described in part a. Describe the loop invariant in the modified code, and briefly explain your answer 4. Using your updated invariant, give an induction proof that the modified algorithm works correctly

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!