Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The original code at below Here is the code for modify plz make sure the output is same as the results or similar import java.util.Scanner;

image text in transcribed

The original code at below

image text in transcribed

image text in transcribed

image text in transcribed

Here is the code for modify

 plz make sure the output is same as the results or similar import java.util.Scanner; import java.util.ArrayList; public class QuickSort { public static > void quickSort(ArrayList list, int from, int to) { int index = partition(list, from, to); if (from> int partition(ArrayList list, int left, int right) { int i=left, j=right; T tmp; T pivot=list.get(i); //pivot is the first element of the sub-array while(i0) j--; if (i ArrayList quickSort(ArrayList list) { quickSort(list, 0, list.size()-1); return list; } public static void main(String[] args) { ArrayList list = new ArrayList(); Scanner keyboard = new Scanner(System.in); System.out.print("Enter a list of positive integers, ending with -1:"); int num = keyboard.nextInt(); while (num!=-1) { list.add(num); num = keyboard.nextInt(); } System.out.println(quickSort(list)); } } 
This is java program Exercise 1: In this exercise, you will experiment with the Quick Sort algorithm. The code for the QuickSort algorithm QuickSort java) s given alongside the lab link. Download it, check it out by running it, and then modify the code for this exercise Modify the code to generate 20,000 random positive integers. It is OK if there are duplicates Quick Sort the integers and determine the time taken. (No need to display the sorted numbers!) Repeat the experiment for 40000, 80000, 160000 and 320000 random positive integers and record the time taken The time complexity of the quicksort algorithm can vary widely depending upon the choice of the pivot. The above code always picks the first element of the sub-array as the pivot. Modify the code so that a random pivot is chosen and re-run the above experiments. (Use the same set of random numbers to determine the time to sort for the two pivot selections Here is the table for recording the results of your experiments Experimental analvsis of QuickSort Number of keys Sorting time (Pivot - first element of sub- array) Sorting time (Pivot- random element in the sub-array) 20000 40000 80000 160000 320000 Exercise 2: In this exercise, you will modify the Quick Sort algorithm further to use it in conjunction with Bucket Sort. Generate 20,000 random positive integers (duplicates are allowed). Divide them into four ArrayLists A, B, C and D as follows: If the integer is between 0 and 5000 put it in A; if it is between 5001 and 10000, put it in B if it is between10001 and 15000, put it in C and if it is in the range 150001 and 20000, put it in D. Now sort each ArrayList separately using QuickSort. Use the first item of each sub-array as the pivot. Next scan the sorted ArrayLists A, B, C and D, and put all the items in order into one big ArrayList. Record the total time taken for the above process Re-run the experiment with the same set of random integers, but with a random element in each sub-array as the pivot. Repeat the above experiment for 40000, 80000, 160000 and 320000 random positive integers. For 40000, you would put the keys in 8 ArrayLists in the range 0-5000, 5001-10000, 35001-40000. For 80000, you would put the keys in 16 ArrayLists, and so on. Record your times in the table below: Experimental analysis of Bucket Sort (with QuickSort) Number of keys Sorting time Pivot first element of sub array) Sorting time Pivot random element in the sub-array) 20000 40000 80000 160000 320000 This is java program Exercise 1: In this exercise, you will experiment with the Quick Sort algorithm. The code for the QuickSort algorithm QuickSort java) s given alongside the lab link. Download it, check it out by running it, and then modify the code for this exercise Modify the code to generate 20,000 random positive integers. It is OK if there are duplicates Quick Sort the integers and determine the time taken. (No need to display the sorted numbers!) Repeat the experiment for 40000, 80000, 160000 and 320000 random positive integers and record the time taken The time complexity of the quicksort algorithm can vary widely depending upon the choice of the pivot. The above code always picks the first element of the sub-array as the pivot. Modify the code so that a random pivot is chosen and re-run the above experiments. (Use the same set of random numbers to determine the time to sort for the two pivot selections Here is the table for recording the results of your experiments Experimental analvsis of QuickSort Number of keys Sorting time (Pivot - first element of sub- array) Sorting time (Pivot- random element in the sub-array) 20000 40000 80000 160000 320000 Exercise 2: In this exercise, you will modify the Quick Sort algorithm further to use it in conjunction with Bucket Sort. Generate 20,000 random positive integers (duplicates are allowed). Divide them into four ArrayLists A, B, C and D as follows: If the integer is between 0 and 5000 put it in A; if it is between 5001 and 10000, put it in B if it is between10001 and 15000, put it in C and if it is in the range 150001 and 20000, put it in D. Now sort each ArrayList separately using QuickSort. Use the first item of each sub-array as the pivot. Next scan the sorted ArrayLists A, B, C and D, and put all the items in order into one big ArrayList. Record the total time taken for the above process Re-run the experiment with the same set of random integers, but with a random element in each sub-array as the pivot. Repeat the above experiment for 40000, 80000, 160000 and 320000 random positive integers. For 40000, you would put the keys in 8 ArrayLists in the range 0-5000, 5001-10000, 35001-40000. For 80000, you would put the keys in 16 ArrayLists, and so on. Record your times in the table below: Experimental analysis of Bucket Sort (with QuickSort) Number of keys Sorting time Pivot first element of sub array) Sorting time Pivot random element in the sub-array) 20000 40000 80000 160000 320000

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_2

Step: 3

blur-text-image_3

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

5. If yes, then why?

Answered: 1 week ago