Question: Consider the following algorithm. ALGORITHM: Mystery ( A [ 0 . . n - 1 ] , B [ 0 . . n - 1

Consider the following algorithm.
ALGORITHM: Mystery(A[0..n-1], B[0..n-1],n)
//Input: Two same-sized arrays A[0..n-1], B[0..n-1] of n real numbers, size of A, B
a A[n-1]
b B[n-1]
for i n-2 downto 0 do
if A[i]< a then
a A[i]
if B[i]>b then
b B[i]
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 0 and n-1.
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 time-efficiency 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!