Question: Please follow the instructions Please and test it first (when I solved the code and run it the code runs but very slowly ) package

Please follow the instructions Please and test it first (when I solved the code and run it the code runs but very slowly )
package sorting;
import java.util.*;
public class Sort {
public static int[] insertion_sort (int[] array) {
/*
* fill in your program
*/
return array;
}
/*
* n: the size of the output array
* k: the maximum value in the array
*/
public static int[] generate_random_array (int n, int k) {
List
int[] array;
Random rnd;
rnd = new Random(System.currentTimeMillis());
list = new ArrayList
for (int i = 1; i
list.add(new Integer(rnd.nextInt(k+1)));
Collections.shuffle(list, rnd);
array = new int[n];
for (int i = 0; i
array[i] = list.get(i).intValue();
return array;
}
/*
* n: the size of the output array
*/
public static int[] generate_random_array (int n) {
List
int[] array;
list = new ArrayList
for (int i = 1; i
list.add(new Integer(i));
Collections.shuffle(list, new
Random(System.currentTimeMillis()));
array = new int[n];
for (int i = 0; i
array[i] = list.get(i).intValue();
return array;
}
/*
* Input: an integer array
* Output: true if the array is acsendingly sorted, otherwise return
false
*/
public static boolean check_sorted (int[] array) {
for (int i = 1; i
if (array[i-1] > array[i])
return false;
}
return true;
}
public static void print_array (int[] array) {
for (int i = 0; i
System.out.print(array[i] + ", ");
System.out.println();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Insertion sort starts ------------------");
for (int n = 100000; n
int[] array = Sort.generate_random_array(n);
long t1 = System.currentTimeMillis();
array = Sort.insertion_sort(array);
long t2 = System.currentTimeMillis();
long t = t2 - t1;
boolean flag = Sort.check_sorted(array);
System.out.println(n + "," + t + "," + flag);
}
System.out.println("Insertion sort ends ------------------");
}
}
1 Problem Description Instructions. You are provided the skeleton code named Sort.java. The source file is available on Canvas in a folder named HW1. Please modify the skeleton code to solve the following tasks. . Task 1 (80 pts). Implement the Insertion Sort algorithm as discussed in Lecture 1. (Hint: use the function checked sorted to check if your output is indeed sorted.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
