Question: Can someone translate the function median_of_medians into a C programming code? median_partition is almost the same as the partition algorithm used in Basic Quicksort, except

Can someone translate the function median_of_medians into a C programming code? Can someone translate the function median_of_medians into a C programming code? median_partition

median_partition is almost the same as the partition algorithm used in Basic Quicksort, except that it chooses a good partitioning element, using a median-of-medians method: median_partition (A, p, r) median = median_of_medians (A, p, r) find index ind of median swap Aind) with A[r] x - A[r] i = p - 1 for j = p to r - 1 if A[] = x i = i + 1 exchange A[i] with A[j] exchange Ai + 1] with A[r] return i + 1 The median-of-medians method is proven to get a median in 0(N)O(N) time, and is described as follows (from Cormen et al. Book): 1. Divide the NN elements of the input array into [N/5][N/5] groups of 5 elements (from start index to end index) each and at most one group made up of the remaining N mod 5 elements. 2. Find the median of each of the [N/5][N/51 groups by first insertion-sorting the elements of each group (of which there are at most 5) and then picking the median from the sorted list of group elements. 3. Use QUICK-SELECT recursively to find the median x of the IN/5[N/51 medians found in step 2. (If there are an even number of medians, then by our convention x is the lower median.) For this machine exercise given several unsorted lists of unique integers, use QUICK-SELECT as described above to look for the median of each list

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!