Question: The following function divides one integer by another by the rather dubious process of making a series of random guesses until it happens to guess
The following function divides one integer by another by the rather dubious process of making a series of random guesses until it happens to guess correctly.
int idivint x int y
Compute x y
if x
return x;
int k rand.nextIntx;
while ky x && ky x
k rand.nextIntx;
return k;
Assume that rand.nextIntn each time that it is called, returns a randomly selected integer in the range n inclusive, with every integer in that range being equally likely to occur on any given call, and that each nextIntn call runs in O time.
What is the averagecase complexity of this function?
Group of answer choices
O
Ox
Oy
On
Ox y
Olog x
Olog y
None of the given answers are correct.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
