a. Write a java program to implement the Quick Sort algorithm that sorts an array of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a. Write a java program to implement the Quick Sort algorithm that sorts an array of integers. We discussed two pivot picking strategies: specific element (first/middle/last), and median of 3. Implement both these strategies and add a third one that uses a random element as a pivot. You may want to implement a Quick Sort that takes a variable to be used to choose the strategy each time. Note: This is not a multi-pivot Quick Sort, but rather a sort that allows choice of pivot picking strategy. b. Use a set of 24 random integers to test your algorithm. A Boolean method that checks if an array is sorted can be used to avoid printing before and after arrays to the console. is Sorted (int[] array) { boolean for (int i = 0; i < array.length 1; i++) { if (array[i] > array[i + 1]) return false; C. } return true; } Add code to compare the performance of the different pivot picking strategies in part a by timing how long it takes to sort arrays of growing input sizes. For each array of size N, run multiple trials. A table could help document the timing results, for example: Activate Windows Go to Settings to activate Windows. ***Quick Sort BenchMark*** ***Milliseconds*** N 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 First 0.000 0.000 1.001 1.001 1.001 2.001 2.001 3.000 5.998 7.996 13.993 25.988 61.969 131072 118.935 262144 257.857 524288 531.715 1048576 1072.405 2097152 2178.783 4194304 4312.568 8388608 8807.151 Fastest QuickSort on average: First Element Pivot Random 0.000 0.000 0.000 0.999 1.998 1.998 2.998 3.998 9.994 20.987 48.970 104.937 246.856 527.698 1154.347 2545.551 5613.812 12141.153 26428.131 58452.334 Median of 3 0.000 0.998 0.998 0.998 1.997 2.996 3.995 4.996 6.996 10.994 19.989 36.979 68.960 139.920 278.842 584.690 1218.331 2398.666 4898.259 9973.415 And so on... Plot a simple graph comparing the performance of the 3 strategies. What are your observations? 2. MergeSort. a. Write a java program to sort an array of integers using the Merge Sort Algorithm. Use the issorted () method to test with an array of 24 random integers. b. Just like in Q1c, add code to perform a comparison of the performance of MergeSort and QuickSort. For QuickSort, use the pivot picking strategy that performed best in Question 1. When you are done, plot the results in a graph. Are your observations consistent with the theoretical analysis of the running time for these algorithms? 3. Extra Credit Quick Sort is a fast algorithm that generally works well with large amounts of data. However, when lists are smaller, Quick Sort may run slower than other sorting algorithms due to the overhead of recursion. When sorting large lists with Quick Sort, many, many sub lists will have to be sorted and this may slow its overall performance. Implement a smarter Quick Sort algorithm that cuts off when the list size is reduced to a threshold, say, 10, then switches to a different sorting method of your choice. Compare the performance of this smarter Quick Sort to the previous one in Q1. Is there any significant difference for large inputs? a. Write a java program to implement the Quick Sort algorithm that sorts an array of integers. We discussed two pivot picking strategies: specific element (first/middle/last), and median of 3. Implement both these strategies and add a third one that uses a random element as a pivot. You may want to implement a Quick Sort that takes a variable to be used to choose the strategy each time. Note: This is not a multi-pivot Quick Sort, but rather a sort that allows choice of pivot picking strategy. b. Use a set of 24 random integers to test your algorithm. A Boolean method that checks if an array is sorted can be used to avoid printing before and after arrays to the console. is Sorted (int[] array) { boolean for (int i = 0; i < array.length 1; i++) { if (array[i] > array[i + 1]) return false; C. } return true; } Add code to compare the performance of the different pivot picking strategies in part a by timing how long it takes to sort arrays of growing input sizes. For each array of size N, run multiple trials. A table could help document the timing results, for example: Activate Windows Go to Settings to activate Windows. ***Quick Sort BenchMark*** ***Milliseconds*** N 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 First 0.000 0.000 1.001 1.001 1.001 2.001 2.001 3.000 5.998 7.996 13.993 25.988 61.969 131072 118.935 262144 257.857 524288 531.715 1048576 1072.405 2097152 2178.783 4194304 4312.568 8388608 8807.151 Fastest QuickSort on average: First Element Pivot Random 0.000 0.000 0.000 0.999 1.998 1.998 2.998 3.998 9.994 20.987 48.970 104.937 246.856 527.698 1154.347 2545.551 5613.812 12141.153 26428.131 58452.334 Median of 3 0.000 0.998 0.998 0.998 1.997 2.996 3.995 4.996 6.996 10.994 19.989 36.979 68.960 139.920 278.842 584.690 1218.331 2398.666 4898.259 9973.415 And so on... Plot a simple graph comparing the performance of the 3 strategies. What are your observations? 2. MergeSort. a. Write a java program to sort an array of integers using the Merge Sort Algorithm. Use the issorted () method to test with an array of 24 random integers. b. Just like in Q1c, add code to perform a comparison of the performance of MergeSort and QuickSort. For QuickSort, use the pivot picking strategy that performed best in Question 1. When you are done, plot the results in a graph. Are your observations consistent with the theoretical analysis of the running time for these algorithms? 3. Extra Credit Quick Sort is a fast algorithm that generally works well with large amounts of data. However, when lists are smaller, Quick Sort may run slower than other sorting algorithms due to the overhead of recursion. When sorting large lists with Quick Sort, many, many sub lists will have to be sorted and this may slow its overall performance. Implement a smarter Quick Sort algorithm that cuts off when the list size is reduced to a threshold, say, 10, then switches to a different sorting method of your choice. Compare the performance of this smarter Quick Sort to the previous one in Q1. Is there any significant difference for large inputs?
Expert Answer:
Answer rating: 100% (QA)
import javautilArrays import javautilRandom public class SortingComparison Quick Sort w... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Required Information [The following information applies to the questions displayed below.] The first production department of Stone Incorporated reports the following for April. Direct Materials...
-
O 00:29:33 4. Let an be a convergent series and b, be a soquence such that 0 <2+ a, < b Which of the following statements are true? 10 I) The convergence or divergence of cannot be concluded. Im (2+...
-
Using Exhibit 1.3 as a model, describe the source-make-deliver-return relationships in the following systems: a. An airline b. an automobile manufacturer c. A hospital d. An insurance company
-
For each of the following scenarios, determine whether the specified variable would increase, decrease, or remain the same. Explain your choice. 1. If sales and average operating assets for Kayman...
-
A large region of space contains a uniform magnetic field that is increasing with time. You have a piece of wire of length \(\ell\) and want to form a coil from it. What shape should you use for your...
-
The accountant for Ericas Dress Shop prepared the following cash budget. Ericas desires to maintain a cash cushion of $20,000 at the end of each month. Funds are assumed to be borrowed and repaid on...
-
3. A particle of mass m is moving in the xy-plane such that its velocity at a point (x, y) is given as v = a(yx+2xy), where a is a non-zero constant. What is the force F acting on the particle? (A) F...
-
6. You have implemented a butterfly spread whereby the strategy will make money if the stock ends up between $44 and $56 (8 months from now). The stock currently trades at $48, its historical...
-
3. Given F(x, y, z) = y.z+y.x (20 pts.) (as simplified as possible) Draw function F(x, y, z) by using NOR gates Draw function F by using NAND gates only. only. (as simplified as possible) nd the...
-
In not less than 2 0 0 0 words, critically develop and defend a specific project management life cycle for Uganda Global communication Nigeria Limited incorporating a virtual top up technology ( and...
-
Liquid ammoia at -20C is stored in spherical vessel of inner and outer radius 1m and 1.05 m respectively. The inner shell of 3 cm thick is made of nickel steel (k= 19 W/mK) and the outer shell of...
-
Consider this argument: "People have an array of decision-making biases, which can give rise to "bad" decisions. Hence people's welfare can be improved with "nudges"." Are there problems with the...
-
Two friends are walking, having a normal conversation; the sound level of the conversation if 60 db. When they get near a busy street, they have to double the intensity of the sound to be able to...
-
Captain Haddock thinks water is always a worse option than alcohol and prefers drinking whisky at all times. Essentially, Haddock derives 0 utility from water. Water is what is called a "useless...
-
Goodluck Ltd. decides to issue 50,000 shares of N10 each at a Premium of N4 per share payable as: On Application N2 per share On Allotment N6 per Share (including Premium N3) On first and final Call...
-
Outline a general process applicable to most control situations. Using this, explain how you would develop a system to control home delivery staff at a local pizza shop.
-
Show that the function (x) = 2 x is convex.
-
Write pseudocode for MAKE-SET, FIND-SET, and UNION using the linked-list representation and the weighted-union heuristic. Make sure to specify the attributes that you assume for set objects and list...
-
Using Figure 10.2 as a model, illustrate the result of each operation in the sequence ENQUEUE?(Q, 4), ENQUEUE?(Q, 1), ENQUEUE?(Q, 3), DEQUEUE?(Q), ENQUEUE?(Q, 8), and DEQUEUE?(Q)?on an initially...
-
Freelance bookkeeper Elizabeth Mulder perpetrated a nearly five-year fraud against her client, plaintiff Kurtz-Ahlers, LLC. Both Kurtz- Ahlers and Mulder coincidentally had their checking accounts at...
-
We meet Robert Triffin once again. The case concerns a \($301.17\) check dated August 20, 2015, bearing the words NOT VALID AFTER 180 DAYS. The check was drawn against the bank account of TWC...
-
Ranchers Legacy Meat Company (Ranchers Legacy) was engaged in the meat packing and processing industry. The company was founded as the Unger Meat Company (Unger) in 2010 by James Ratcliff (Ratcliff)....
Study smarter with the SolutionInn App