Question: For this assignment you will be writing code to generate test data and benchmark sorting algorithms on it (edited from Sedgewick and Wayne: 2.1.36). Already



For this assignment you will be writing code to generate test data and benchmark sorting algorithms on it (edited from Sedgewick and Wayne: 2.1.36). Already provided for you is BaseNonUniform.java which con- tains the existing sorting algorithms. This class extends an interface called SER222_02_01_HW02_Submission which defines all of the methods that you need to create. You may create additional private helper methods. First, write a series of methods to generate test data that is "non-uniform: Implement the method public Integer generate TestDataBinary(int size). Half the data is Os, half ls. For example, an input of length 8 might look like [0, 0, 0, 0, 1, 1, 1, 1]. See the interface. [4 points] Implement the method public Integerll generate TestData Halfs(int size). Half the data is Os, half the remainder is 1s, half the reminder is 2s, half the reminder is 3s, and so forth. For example, an input of length 8 might look like [0, 0, 0, 0, 1, 1, 2, 3). See the interface. [9 points] Implement the method public Integer[] generate TestDataHalfRandom(int size). Half the data is Os, half random int values (use nextInt() from Java's Random package). For example, an input of length 8 might look like [0, 0, 0, 0, 54119567, 4968, -650736346, 138617093]. See the interface. [4 points] /* * Generates an array of integers where half the data is os, half 1s. * @param size number of elements in the array. * @return generated test set. */ public Integer[] generateTestDataBinary(int size); /** * Generates an array of integers where half the data is Os, half the * remainder is 1s, half the reminder is 2s, half the reminder is 3s, and so * forth. * * @param size number of elements in the array. * @return generated test set. */ public Integer[] generateTestDataHalfs(int size); /** * Generates an array of integers where half the data is os, and half random * int values. * @param size * @return */ public Integer[] generateTestDataHalfRandom(int size); public class BaseNonUniform implements SER222_02_01_HW02_Submission { /okokok * START - SORTING UTILITIES, DO NOT MODIFY (FROM SEDGEWICK) public static void insertionSort(Comparable[] a) { int N = a. length; for (int i 1; i 0 && less(alj), alj-1]); j--) exch(a, j, j-1); } public static void shellsort(Comparable[] a) { int N = a. length; int h = 1; while (h = 1) { // h-sort the array. for (int i = h; i = h && less(alj), a[j-h]); j h) exch(a, j, j-h); } h = /3; } private static boolean less (comparable v, Comparable w) { return v.compareTo(w) 0 && less(alj), alj-1]); j--) exch(a, j, j-1); } public static void shellsort(Comparable[] a) { int N = a. length; int h = 1; while (h = 1) { // h-sort the array. for (int i = h; i = h && less(alj), a[j-h]); j h) exch(a, j, j-h); } h = /3; } private static boolean less (comparable v, Comparable w) { return v.compareTo(w)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
