Create an array of 50,000 random integers that are in the range from 1 to 10,000. Sort this array using selection sort and insertion sort. Time the execution of both of these sorting methods and...



Create an array of 50,000 random integers that are in the range from 1 to 10,000. Sort this array using selection sort and insertion sort. Time the execution of both of these sorting methods and determine which is more efficient. Write a summary of which algorithm you find to be more efficient and why. To time a section of Java code, you can use the class java.util.Date, which was described. A Date object contains the time at which it was constructed. Its method getTime returns the time as a long integer equal to the number of milliseconds that have passed since 00:00:00.000 GMT on January 1, 1970. By subtracting the starting time in milliseconds from the ending time in milliseconds, you get the run time—in milliseconds—of a section of code.


For example, suppose that thisMethod is the name of a method you wish to time. The following statements will compute the number of milliseconds that thisMethod requires to execute:


Date current = new Date(); // get current time


long startTime = current.getTime();


thisMethod(); // code to be timed


current = new Date(); // get current time


long stopTime = current.getTime();


long elapsedTime = stopTime - startTime; // milliseconds



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here