Question: Help coding in Java. Cannot change function types. Here is selection file: public class Selection { public static int select(int[] array, int n, int k)
Help coding in Java. Cannot change function types.
Here is selection file:
public class Selection { public static int select(int[] array, int n, int k)
{ return select(array, 0, n - 1, k); }
private static int select(int[] array, int left, int right, int k) { // complete this function } }
here is MedianOfMedians file:
public class MedianOfMedians { private static void insertionSort(int[] arr, int left, int right)
{ for (int i = left + 1; i
int j = i, temp = arr[j];
while (j > left && temp
{ arr[j] = arr[j - 1];
j--; }
arr[j] = temp;
}
}
public static int select(int[] array, int n, int k) { return select(array, 0, n - 1, k); }
private static int select(int[] array, int left, int right, int k) { // complete this function
} }
here is Partition file needed to code this correctly

public class Partition {
static Random rand = new Random(System.currentTimeMillis());
protected static void swap(int[] array, int x, int y) { int temp = array[x];
array[x] = array[y];
array[y] = temp; }
public static int generateRandomPivot(int[] array, int left, int right)
{ return left + rand.nextInt(right - left + 1); }
public static int generateMedianOf3Pivot(int[] array, int left, int right) {
int mid = left + (right - left) / 2;
if (array[left] > array[mid]) swap(array, left, mid);
if (array[left] > array[right]) swap(array, left, right);
if (array[mid] > array[right]) swap(array, mid, right); return mid; }
public static int[] partition(int[] array, int left, int right, int pivotIndex) { // complete this function } }
1.2 Part 2: Selection Algorithms In the second part, you are going to implement the Selection algorithm for finding the kth smallest number in an array. For the pivot, you are going to use a random one. Your task is to implement the following: Quick-Selection Algorithm (File: Selection) Implement select (int () array, int left, int right, int k). For pivot generation, call the function generateRandom Pivot (int[] array, int left, int right). Since partition returns two indexes, you must the appropriate quick-select algorithm from the notes that utilizes both the indexes. Median of Medians Algorithm (File: MedianOfMedians) Implement select (int () array, int left, int right, int k). Since partition returns two indexes, you must modify the median of medians quick-select algorithm from the notes to utilize both the indexes this modification is simple (essentially copy and paste the final recursive part) if you have completed the randomized quick-select.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
