Question: Problem 5 (2+5+3 points) The following two functions both take as arguments two n-element arrays A and B: MAGIC-1(A, B, n) For i =1 to

 Problem 5 (2+5+3 points) The following two functions both take as

Problem 5 (2+5+3 points) The following two functions both take as arguments two n-element arrays A and B: MAGIC-1(A, B, n) For i =1 to n For j=1 to n If A[i]> B[j] Return FALSE Return TRUE MAGIC-2(A, B, n) temp := A[1] For i = 2 ton If A[i] > temp Then temp := A[i] For j =1 to n If temp > B[j] Return FALSE Return TRUE (a) It turns out both of these procedures return TRUE if and only if the same special condition regarding the arrays A and B holds. Describe this special condition in English. (b) Analyze the worst-case running time for both algorithms in the O-notation. Which algorithm would you chose? Is it the one with the shortest code (number of lines)? (c) Does the situation change if we consider the best-case running time for both algorithms

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!