Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have a class called Sorting. You need to create the two methods MergeSort and QuickSort, as well as two auxiliary methods for testing them:

You have a class called Sorting. You need to create the two methods MergeSort and QuickSort, as well as two auxiliary methods for testing them: fillRandom and verifySorted. The main method generates arrays of increasing size and uses them to test your sorting methods:

private static void fillRandom(int[] A) { // TODO: Fill the given array with random integers between 1 and 1 million } private static void verifySorted(int[] A){ // TODO: Return successfully if the array is sorted property, otherwise throw a runtime exception }
public static void main(String[] args){ int[] sizes = {20_000, 40_000, 60_000, 80_000, 100_000, 120_000, 140_000, 160_000, 180_000, 200_000}; for(int s : sizes){ int[] ints = new int[s]; System.out.println("Testing sorting procedures on an array of lenth " + s + ":"); // Test and time the MergeSort implementation fillRandom(ints); long startMerge = System.currentTimeMillis(); Sorting.MergeSort(ints); long mergeTime = System.currentTimeMillis() - startMerge; System.out.printf(" The MergeSort took %d ms ", mergeTime); verifySorted(ints); // Test and time the QuickSort implementation fillRandom(ints); //TODO: time the QuickSort implementation as above verifySorted(ints); System.out.println(" "); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago