Question: I need to implement insertion, merge, and quick sort as well as track their runtime for 2 0 iterations. I created this in java and

I need to implement insertion, merge, and quick sort as well as track their runtime for20 iterations. I created this in java and have set everything, making sure it follows the examples up but there is an where it runs and gets the arrays size wrong. I have checked everything I could think of but can't find a soulution.
import java.util.Random;
public class Main {
public static void main(String[] args){
long startTime;
long endTime;
int[] array;
for(int i=0; i<20; i++){
array=makeArray();
startTime=System.nanoTime();
insertionSort(array);
endTime=System.nanoTime();
System.out.println(((i+1)+": "+(endTime-startTime)/1000)+"E-3 ms for insertion.");
array=makeArray();
startTime=System.nanoTime();
mergeSort(array,0, array.length);
endTime=System.nanoTime();
System.out.println(((i+1)+": "+(endTime-startTime)/1000)+"E-3 ms for merge.");
array=makeArray();
startTime=System.nanoTime();
quickSort(array,0, array.length);
endTime=System.nanoTime();
System.out.println(((i+1)+": "+(endTime-startTime)/1000)+"E-3 ms for quick.");
}
}
public static int[] insertionSort(int[] iArr){
for(int i=1; i0 && iArr[j]>key){
iArr[j+1]=iArr[j];
j=j-1;
}
iArr[j+1]=key;
}
return iArr;
}
public static void mergeSort(int[] arr, int l, int r){
if(l

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!