Help coding in Java. Cannot change function types. Here is selection file: public class Selection { public
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)
{ 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 <= right; i++) {
int j = i, temp = arr[j];
while (j > left && temp < arr[j - 1])
{ 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 } }
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba