Question: (Sort) (a) Write an algorithm to sort an array of numbers. You have to use the following decomposition: let the first number of the array

 (Sort) (a) Write an algorithm to sort an array of numbers.

You have to use the following decomposition: let the first number of

the array be x, (in a new array), put all numbers less

(Sort) (a) Write an algorithm to sort an array of numbers. You have to use the following decomposition: let the first number of the array be x, (in a new array), put all numbers less than or equal to x to the left side (i.e., smaller index than that of x) of r and the rest of the numbers to the right side of x. Sort the array to the left side of x, and sort the array to the right side. The format of your algorithm should follow the one used in class. To design the algorithm, you must use the problem decomposition method discussed during class. You only need to present the final version of your algorithm. (b) What is the best asymptotic upper bound for the worst case running time of the algorithm? List your reasoning steps. Algorithm (Function) Name: mSort Input a: given array of integers bottom: a number top: a number Output NA Side effects Array at segment bottom to top is sorted. Plan % when problem is not decomposable if bottom >= top do nothing else % problem is decomposable % sort the first half of a from bottom to bottom+(top-bottom)/2 mSort(a, bottom, bottom+(top-bottom)/2) % sort the second half of the array bottom+(top-bottom)/2+1 to top mSort(a, bottom+(top-bottom)/2+1, top) % merge the two sorted parts of a from bottom to top merge(a, bottom, top) End of algorithm

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!