Question: Consider the following algorithm. ALGORITHM: Mystery ( A [ 0 . . n - 1 ] , B [ 0 . . n - 1
Consider the following algorithm.
ALGORITHM: MysteryAn Bnn
Input: Two samesized arrays An Bn of n real numbers, size of A B
a An
b Bn
for i n downto do
if Ai a then
a Ai
if Bib then
b Bi
return ba
a What does this algorithm compute?
b Which of the following statements about the output are true and which are false? Explain your answers by providing an argument for true statements and a counter example for false statements.
i It will be equal to a value in one of the arrays.
ii It can be negative.
iii. It will be between and n
c What is its basic operation?
d Show and simplify a summation for the number of times the basic operation is executed.
e What is the Theta timeefficiency class of this algorithm? Prove your result.
f Suggest an improvement, or a better algorithm altogether, and indicate its efficiency class, or make a convincing argument that no improvement is possible.
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
