Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

'3']: DeereaseandCenquer Algorithm Maximum Element in Array a]: 1iWrite a recursive decreaseandconquer algorithm to calculate the maximum element in a non empty array of real

 image
'3']: DeereaseandCenquer Algorithm Maximum Element in Array a]: 1iWrite a recursive decreaseandconquer algorithm to calculate the maximum element in a non empty array of real numbers. Your algorithm should work by comparing the last element in the array with the maximum ofthe "remaining front end" ofthe array. For example1 to nd the largest element in the arrayr {5. [31 9. If}? your algorithm should call itself'to find the maximum of, 13, 93' and return either l or the result of the recursive call, whichever is larger. I Do not use Python's builtin max function. I Do not rearrange the elements ofthe array by sorting or partially sorting them. I Do not use any loops. You can assume that the array has at least one element in it. Your function call should should be MaximumIEA, right} where the two input parameters are the array and right index. Will] these input parameters. the function should return the maximum array element from AW] to A[right]. Return the value of the array element. not the index where it occurs in the array. b} Trace your algorithm with A = {11, {$2.49. T3. 2b. 511* c} Write a recurrence relation for the number of comparisons of array elements that are performed for a problem of size n. Then perform asymptotic analysis to determine the BigUh class for this algorithm 8) Divide-and-Conquer Algorithms - Mergesort and Quicksort a) For each of these two sorting algorithms, what is its Big-Oh class in the worst case? b) For each of these two sorting algorithms, what is its Big-Oh class in the average case? c) Trace the mergesort algorithm for the following array of values. A = <127, 48, 62, 51, 198, 17, 52, 209> Rather than keep track of the values of individual variables, follow the "tree format" that was used in the class notes to trace the mergesort algorithm. d) Trace the quicksort algorithm for the same array of values. A = <127, 48, 62, 51, 198, 17, 52, 209> Indicate the pivots in red as was done in the class notes

a) Write a recursive decrease-and-conquer algorithm to calculate the maximum element in a non- empty array of real numbers. Your algorithm should work by comparing the last element in the array with the maximum of the "remaining front end" of the array. For example, to find the largest element in the array your algorithm should call itself to find the maximum of and return either 10 or the result of the recursive call, whichever is larger. Do not use Python's built-in max() function. Do not rearrange the elements of the array by sorting or partially sorting them. Do not use any loops. You can assume that the array has at least one element in it. Your function call should should be Maximum(A, right) where the two input parameters are the array and right index. With these input parameters, the function should return the maximum array element from A[0] to A[right]. Return the value of the array element, not the index where it occurs in the array. b) Trace your algorithm with A= c) Write a recurrence relation for the number of comparisons of array elements that are performed for a problem of size n. Then perform asymptotic analysis to determine the Big-Oh class for this algorithm

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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions

Question

For any events A and B with , show tha .

Answered: 1 week ago