Reference no: EM131586084
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;
}
What is the value of chi-square
: What is the value of chi-square? Round to three decimal places.The test evaluates how well the observed frequencies fit the expected frequencies.
|
Write an essay about parkinsons disease or leukemia
: Write an essay about Parkinsons disease or Leukemia. What parts of the world is the disease found? How is it transmitted if it is transmittable?
|
Which potentially metastatic cancer as per lecture
: The stratum spinosum is the location for the cells of which potentially metastatic cancer, as per lecture? The dermis can be best described as a ___________.
|
Discuss the idea that social mobility is on the decline
: Looking at the idea that social mobility is on the decline, what does that make America, in terms of stratification, Is it more akin to a caste system
|
Calculate the interval by dividing the largest array
: Create a for loop that iterates through the smallest array to the largest array and keep adding the interval -
|
Information on the two machines
: Hendricks Pizzeria is considering the purchase of a new Oven to replace a machine that was purchased several years ago.
|
Describe the state space of pulling a mitten from the box
: Problem: In early December 2011, the Yarn Harlot felt "a mitten thing coming on" and, with eight colors of yarn-orange, red, yellow, lime green, forest green.
|
What alternative investment has the lowest possible
: What alternative investment has the lowest possible volatility while having the same expected return as? Microsoft? What is the volatility of this? investment?
|
State a version of pie for the probabilities of three events
: The Minbari have three castes (worker, religious, and warrior), and some Minbari enjoy eating the ceremonial food flarn whereas others do not.
|