Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Imagine playing a number guessing game. A side is a number from 0 to N he's holding it, and the other side is trying to

Imagine playing a number guessing game. A side is a number from 0 to N he's holding it, and the other side is trying to find that number by taking turns guessing. Number-holding side estimate he has to offer one of the following three options in response to the party that did it: 1-Your guess is correct, you found the number I kept (Game Over). 2-Your estimate is wrong, but you are closer to the correct estimate than the previous estimate. 3-the wrong estimate and the correct estimate are further away than the previous estimate. To find the estimated number in an environment where all the information is these, a strategy will be followed:

Make a prediction (N/2) from the exact middle of N with 1 Begin: Find out the answer to your guess. [answer=answer_ogren (guess)] If the answer is equal to 1, the game is over, you can leave. If the answer is equal to 2, you are going in the right direction, keep the forecast direction; If you're heading for small numbers, the new N is now N/2. Make a guess from the middle of 1 to N / 2 and go back to the beginning. If you're heading for big numbers, the new 1 is now N/2. Make a guess right in the middle of N / 2 and go back to the beginning. If the answer is equal to 3, you are going in the wrong direction, change the direction of the guess; If you're heading for small numbers, the new 1 is now N/2. Make a guess right in the middle of N / 2 and go back to the beginning. If you're heading for big numbers, the new N is no longer N / 2; Make a guess right in the middle of 1 and N/2 and go back to the beginning.

a. (50 points) write the algorithm that implements the strategy given above as pseudocode in accordance with the signature given below. You can accept that there exists a function called respons_ogren(prediction), in which you can get the opposite party's return as an answer for a specified prediction. Do not write inside this function, you can use this function by calling it in your own algorithm.

Algorithm answer_ogren (prediction) // Input: estimate made by the forecaster // Output: 1, 2 or 3. # This algorithm will not be written. Algorithm prediction (N)): // Input : the upper nerve of the range of the integer held by the opposite side (0..N) // Output: how many estimates are determined by the number held by the opposite side. .

b. (40 points) according to this Algorithm, How would a game scenario have to occur in order for the worst situation to occur in a game played, that is, for the estimator to find the number in the most possible attempts? In this scenario, the estimator would have found the number in approximately how many attempts?

PLEASE WRITE AS PYTHON

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

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions