Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

D U PULLOD) (a) Write a python program that (1) asks the user to think of a number from 1 to infinity and (2) then

image text in transcribed

D U PULLOD) (a) Write a python program that (1) asks the user to think of a number from 1 to infinity and (2) then guesses the number using the efficient algorithm described in class (see slide 15 in 3-Recurrences). Assume the user will respond "low", "high", or "correct" after each computer guess. Start your code like this: # Author: # Purpose: guess the user's number print ("Think of a number between 1 and infinity.") guess = 2 nbrGuesses = 1 response=input("Is it " + str (guess)) while response!= "correct": Page 2 of 3 CSC 375 Homework 2 Spring 2020 if response == "low": # TODO: FILL in this part if response == "high": #TODO: FILL in this part print ("Your number is", guess) print ("It took", nbrGuesses, "guesses") (b) This is a bonus question worth up to 5 bonus points! Explain why in worst case your program will need to guess at most o (log2 G) times where G is the user's number being guessed. Hint: How many guesses will be required until the user says "high"? After a "high" response we know the user's number is between Y/2 and Y, where Y is the last guess. How many guesses will binary search require to find the correct

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago