Question: [ 1 5 points ] Consider the following Java code snippet, which for non - negative inputs returns an integer between low and high that,
points
Consider the following Java code snippet, which for nonnegative inputs returns an integer
between low and high that, when squared, is equal to and which returns if no such
integer exists:
public static int sqrtint x int low, int high
if low high x low high
return ;
int p low high low;
if p p x
return p;
else if p p x
return sqrtx low, p ;
else
return sqrtx p high;
a points
In an arbitrary recursive call to sqrt let d equal high low, and let d equal what high
ow will be for the next recursive call, assuming that both d and d are positive. What must
be under these conditions?
Hint: Your answer should simplify to an integer. Think of this ratio as the number of
approximately equalsized partitions into which you're breaking the set of integers between low
and high inclusive for this arbitrary recursive call, where in the next recursive call you're only
considering values in one of these partitions.
b points
Under the same assumptions listed in part a for the initial call to sqrt we can express the
difference high ow the number of integers on which we are initially considering for the
search as approximately equal to where is the number of approximately equalsized
partitions into which we break our consideration set the value you calculated in part a and is
the maximum number of recursive calls to sqrt we can go through depending on before the
desired integer is found or is determined to not exist. Solve the equation high low for
the approximate value of based on the value you calculated for in terms of the arbitrary
initial inputs high and low.
c points
What is the tightest big O or equivalently, just big worstcase running time complexity of
sqrt in terms of the input variables x high, and low assuming they are all positive
Simplify your answer.
d points
What is the tightest big O or equivalently, just big space complexity of extra memory
required when running sqrt original implementation in terms of the input variables x high,
and low assuming they are all positive Simplify your answer.
Hint: Consider memory used on the call stack and space required by any new variables.
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
