Question: SELECT3: Selection algorithm with linear worst-case time, but with a large constant factor. (This algorithm is discussed in class and is also discussed in exercise

SELECT3: Selection algorithm with linear worst-case time, but with a large constant factor. (This algorithm is discussed in class and is also discussed in exercise C-4.24, p. 254, of the textbook.) The algorithm is outlined below. (a) If n < 25, sort the array using insertion sort, and return the kth element. Otherwise, continue. (b) Divide the set of n elements into subsets ("rows") of size 5 each, and find the median of each subset. (If n is not a multiple of 5, the last row will have less than 5 elements.) To find the median of each row of 5, you can simply use bubble-sort or insertion sort. To avoid the need for a second array, you can pack the n/5 row-medians in front of the same array as they are found. (Use swap operations for this packing to preserve all elements.) (c) Make a recursive call to SELECT3 to find the median of the n/5 row-medians. (d) Use this median-of-medians as the pivot V to partition the array of n elements into three sets as before. Then make a recursive call to SELECT3 for either the left or right partition as neede

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 Mathematics Questions!