Question
Q: Explain this code package Checkpoint; import java.util.Arrays; import java.util.Random; /** * * The class acts as a driver to test your implemented sorting algorithms
Q: Explain this code
package Checkpoint;
import java.util.Arrays; import java.util.Random;
/** * * The class acts as a driver to test your implemented sorting algorithms */ public class Checkpoint2Driver {
public static void main(String[] args) { efficiencyTesting(generateRandomArray(100000)); efficiencyTesting9(generateRandomArray(100000)); // Test your code here .... }
public static int testingOutcoms (String text, String[] unsorted_test_1, String[] sorted_test_1) {
if(Arrays.equals(unsorted_test_1, sorted_test_1)) {
System.out.println(text + " Test Pass"); return 1; } else { System.out.println(text + " Test Fail"); return 0; } } /** * Generates an array of {@link String}randomly. * @param size - The size of the array to be generated. * * @return A randomly generated array. */ public static String[] generateRandomArray (int size) { Random randomGenerator = new Random(); String [] array = new String [size]; for(int i=0;i array[i] = randomGenerator.nextInt()+""; } return array; } /** * Evaluates the required time to fully execute underlying algorithm. * * @param input - an array of {@link String} to be sorted. * * @return execution time. */ public static double efficiencyTesting (String[] input) { long startTime, endTime; double duration; Sorting sorter = new Sorts(); startTime = System.currentTimeMillis(); sorter.insertionSort(input); endTime = System.currentTimeMillis(); duration = ((double) (endTime - startTime)); System.out.println( duration); return duration; } public static double efficiencyTesting9 (String[] input) { long startTime, endTime; double duration; Sorting sorter = new Sorts(); startTime = System.currentTimeMillis(); sorter.mergeSort(input,0,input.length -1); endTime = System.currentTimeMillis(); duration = ((double) (endTime - startTime)); System.out.println( duration); return duration; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started