Question: 1. We consider a modification of the QuickSort algorithm presented in class. Normally, we pick a pivot at random and use it as pivot. Say
1. We consider a modification of the QuickSort algorithm presented in class. Normally, we pick a pivot at random and use it as pivot. Say that we instead we insert a step to calculate the median-of-medians (say, using groups of 5) and use that as pivot instead. In other words, ModifiedQuickSort is:
1. Group the n elements in the array in groups of 5. Compute the median for each group (using Selection)
2. Let m be the median-of-medians
3. Partition input array around the median-of-medians. Let i be the position of the median-of-medians in the reordered array
4. Execute ModifiedQuickSort on the two subarrays indicated by Partition (that is, from 0 to i 1 and from i + 1 to n).
(a) After step 3, what are the possible values for i?
(b) Write the recursion for the runtime of the algorithm, incorporating IRVs where needed. Explain briefly why your recursion is correct.
(c) What is the runtime of the algorithm? Note: Doing a precise calculation will be very difficult. Instead, take step back and think: how does the expression look like? Can you give a bound using some other argument? Just justify your answer with a few sentences. Make sure to specify if you mean worst case or expected worst-case.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
