Write a program called insertionsortbenchmark that


Write a program called InsertionSortBenchmark that automatically generates a table of sample run times for the insertion sort algorithm. The program should ask for the smallest and largest value of n and the number of measurements and then execute all sample runs. You should plan to have a method (e.g., "public static int[] generateData(int n)") in your program that generates int arrays of a specific length and populates them with random numbers (use Random's nextInt). This will be needed to run the different tests. To time the running algorithm, you will need to use the StopWatch class (see attached). Also attached is InsertionSorter.java, which contains an implementation of insertion sort. The algorithm is available as a static method directly from that file.

I just need help with the portion in bold. This is the hint from the instructor:

You need to calculate the interval by dividing the largest array size by the number of measurements:
int interval = largest / measurement;

Create a for loop that iterates through the smallest array to the largest array and keep adding the interval.

This is what I have written so far, but I am having issues setting up the loop:

public static int[] generateData(int n)
{
Scanner in = new Scanner(System.in);
int counter = 0;
Random randomNum = new Random();

System.out.print("Smallest array size: ");
int smallest = in.nextInt();
System.out.print("Largest array size: ");
int largest = in.nextInt();
System.out.print("number of measurement: ");
int measurements = in.nextInt();
int [] unsortedArray = new int[smallest];

while (counter < measurements)
{


}

return unsortedArray;

}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a program called insertionsortbenchmark that
Reference No:- TGS02374507

Now Priced at $15 (50% Discount)

Recommended (95%)

Rated (4.7/5)