Question: rite the driver class that has 3 methods that will accept an array of ints to sort using each of these algorithms: insertion, selection, &

rite the driver class that has 3 methods that will accept an array of ints to sort using each of these algorithms: insertion, selection, & bubble. Note: Make sure the sorting is in ASCENDING order! 2.) Write a driver that will do the following:

a.) Create an array of 20,000 ints (generate the numbers randomly in a loop, in the range of 1 - 5000)

b.) Call each of the sorting methods, passing it the array of 20,000 ints (Note: make a copy of the array before sorting the copy).

c.) Calculate the number of nanoseconds taken to sort the same array, using each of the 3 algorithms.

d.) Display the time for each. Say which of the 3 algorithms was fastest (most efficient).

Hint #1: To prove that the algorithm is working, create a small array of 10 randomly generated ints between 1 and 100, and sort them using each of the 3 sorting methods, and print them after each sort. Make a copy of the original array, so that you are re-sorting an unsorted array, instead of the sorted array. This is proof of concept.

Hint #2: Make a copy of the original array, so that you use the unsorted version as input to each method.

Hint #3: Use either System.currentTimeMillis() or System.nanoTime() to get the start and end time assigned to 2 long variables, then subtract, and that is your total time.

Do the same for mergeSort and quickSort.

*****************************************************

public class SortingAlgos {

public static int[] myOriginalUnsortedArray1 = new int[20000]; public static int[] myCopyUnsortedArray2 = new int[20000]; public static long bubbleSortDuration, quickSortDuration, selectionSortDuration, insertionSortDuration, mergeSortDuration; /** * @param args the command line arguments */ public static void main(String[] args) { generateRanNums(); copyRanNums(); quickSort(); //Extra Credit! copyRanNums(); mergeSort(); //Extra Credit! copyRanNums(); selectionSort(); copyRanNums(); insertionSort(); copyRanNums(); bubbleSort(); compareSortTimes(); } }

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!