k = n while k > 0 for j=1 to n2 sum += data[j]; k = k / 2
85 21 5 33 2 19 72Then, the output, in sorted order, is:
2 5 19You are to implement three algorithms for the selection problem, two of which are quite straightforward. Each of these must implement the SelectionAlgorithm interface. It will help to examine this interface before continuing.
void recursiveSelect (int[] data, int K, int left, int right)Like the recursive part of quicksort, the input is the data and a range. Here, the number K is also part of the input. Now, use the quicksort partitioning algorithm to find the partition position. If the partition position is K, then we're done, because all elements to the left of that position are less than the element at the partition position. If the partition position is larger than K, then we recurse on the left partition; otherwise, we recurse on the right partition. Finally, when the recursion is completed, the array will have all elements less than the K-th element in the first K-1 places. Then, we will need to create and sort the result array (because the recursive partitioning does not sort).
Submission: