Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA Hello there, im back again lol, I attempted this assingment and i have pasted what i had, I am pretty confused, can you

IN JAVA

Hello there, im back again lol, I attempted this assingment and i have pasted what i had, I am pretty confused, can you please help! Will give 5 stars!! i appreciate the help!!!!!!!!!!!!!!!

////////////////////////////////////////INSTRUCTIONS//////////////////////////////////////////////////

In the section, implement two methods for quicksort and merge sort respectively in the SimpleArrayList class, and compare their performance on large size sequences.

Completing the following method which re-organizes the current values in the array list in an ascending order using quicksort. Notice that you should only handle the filled cells in the list.

public void quickSort()

{

...

}

If you want to use recursion, please define the auxiliary or help functions as private methods in the class. Only the above method is exposed to users.

Completing the following method which re-organizes the current values in the array list in an ascending order using merge sort. Notice that you should only handle the filled cells in the list.

public void mergeSort()

{

...

}

If you want to use recursion, please define the auxiliary or help functions as private methods in the class. Only the above method is exposed to users.

Please write a testing program for your methods. For each sorting method, you should randomly generate 10 numbers, add them to an empty simple array list, and display the list content before and after sorting.

We compare the performance of quicksort and merge sort on large random arrays. Similar to the previous question, you are required to randomly build a simple array list whose size is close to 231-1 which is the maximum array size allowed in Java. Then you make a copy of the array list, and perform quicksort and merge sort on the original array list and its copy respectively. It ensures that the two sorting methods are applied to the same array content. Perform the above steps on several random large array lists, and show the time cost comparison. (You are required to write these testing programs but please do not display the array content.)

/////////////////////////////////////////////MY CODE////////////////////////////////////////////////////////// import java.util.Random;

public class Test { public static void main(String[] args) { Random random = new Random(); SimpleArrayList list = new SimpleArrayList(); // generate 10 random numbers and add them to the list for (int i = 0; i < 10; i++) { int num = random.nextInt(); list.add(num); System.out.print(num + " "); } System.out.println(" Before sorting:"); list.printList(); // sort the list list.quickSort(); list.mergeSort(); System.out.println(" After sorting:"); list.printList(); // compare performance of quickSort and mergeSort on large arrays int size = (int) Math.pow(2, 31) - 1; SimpleArrayList list1 = new SimpleArrayList();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions