Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

Solve the following 1,4 3 2TT 5x- 1+ (15 x) dx 5X

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago