Question: 3. Design a recursive algorithm called Extrema(A,p,r) that, given an array A[1...n] finds and returns both the min and max of the subarray Ap...r] as

3. Design a recursive algorithm called Extrema(A,p,r) that, given an array A[1...n] finds and returns both the min and max of the subarray Ap...r] as an ordered pair: (min(Ap...r]), max(Ap...r])). Your algorithm should perform exactly [3n/2] 2 array comparisons on an input array of length n. (Hint: Section 9.1 of the text describes an iterative algorithm that does this.) a. Write your algorithm in pseudo-code. b. Prove the correctness of your algorithm by induction on m = r - p + 1, the length of the subarray Ap - r]. c. Write a recurrence for the number of comparisons performed on A[1...n], and show that T(n) = [3n/2] 2 is its solution. 3. Design a recursive algorithm called Extrema(A,p,r) that, given an array A[1...n] finds and returns both the min and max of the subarray Ap...r] as an ordered pair: (min(Ap...r]), max(Ap...r])). Your algorithm should perform exactly [3n/2] 2 array comparisons on an input array of length n. (Hint: Section 9.1 of the text describes an iterative algorithm that does this.) a. Write your algorithm in pseudo-code. b. Prove the correctness of your algorithm by induction on m = r - p + 1, the length of the subarray Ap - r]. c. Write a recurrence for the number of comparisons performed on A[1...n], and show that T(n) = [3n/2] 2 is its solution
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
