Loading
Home › Computer Science Help › Quicksort
Status: Completed

Quicksort

Date Posted: 18/05/2020
Category: Computer Science
Due Date: 20/05/2020
Instruction
2. Quicksort – Optimized version of Quicksort Learning objectives: Show understanding of quicksort, a commonly used sorting algorithm Collect and analyze empirical data about the performance of a program The textbook web site supplies QuickX.java (Links to an external site.), which is an optimized version of the QuickSort algorithm (pages 289-301 of the textbook) for arrays that has the following changes: Pivot: Median-of-three partitioning (see p. 296 of the textbook): Pick the median of a[left], a[center], and a[right] of the subarray to be the pivot (or the median of any three random elements in the subarray). Cutoff to insertion sort (see p. 296 of the textbook) for subarrays with less than M elements. The existing code uses M = 8. In this problem, you will experiment with different values of M. You have two tasks: 1. Random pivot: Change the quicksort algorithm in this class to randomly pick an element in the array to be the pivot. You will do this by changing the partition() method, but be sure to change it in a way that makes it easy to switch back and forth between median-of-three partitioning and random pivot. You need to add the following method: // Returns the index of a pivot in the subarray a[lo..hi]. int randomPivot(Comparable[] a, int lo, int hi) partition() calls getPivot(), which in turn calls randomPivot() if USE_RANDOM_PIVOT is true. Empirically determine which strategy -- random pivot or median-of-3 partitioning -- runs fastest in your environment to sort random arrays of N Doubles, for N = 103, 104, 105, and 106. This means you have to write code to generate those random arrays and to time the results. You can use the Stopwatch class (part of the textbook code) for this. 2. Testing values of M: Empirically determine the value M for which each version of quicksort (each strategy for choosing the pivot) runs fastest in your environment to sort random arrays of N Doubles, for N = 103, 104, 105, and 106. You can do this by changing the value of the INSERTION_SORT_CUTOFF instance variable (since you are testing 30 different values of M, that's a good hint that you should write a loop that tests these different values, rather than changing INSERTION_SORT_CUTOFF by hand). Test values of M between 0 and 30. You can use the Stopwatch class (part of the textbook code) to time your code. For each value of N, plot the average running times for M from 0 to 30 using a scatter plot (use Excel, Google Sheets, or any other software for making charts; don't draw it by hand.) Clarifications added 4/17/2020: No unit tests are necessary for this problem, since you are testing performance and can assume your code is correct. See Using the textbook code as a starting point for how to time your code. Clarification added 4/9/2020: How you export the data into Excel is up to you, but the way I would do it is to have your code print out one line for each value of M, then copy-and-paste the output into a spreadsheet. An example of how your code's output might look: 0 0.1 1 0.0582 2 0.00322 3 0.000345 This means that when M = 0, the running time is 0.1 seconds; when M = 1, the running time is 0.0582 seconds; etc. (These numbers are made up, so don't be alarmed if your running times are very different.) When you copy and paste output that looks like this, you'll get two columns, one for the values of M and one for the values of the running time. That makes it easy to create a chart where the running time is the dependent variable (y value) and the value of M is the independent variable (x value). Getting started: In Eclipse: Right-click on the "Lab2" icon in the left sidebar. Select "Build Path" from the pop-up menu, then select "Add Libraries..." from the second menu that pops up. Make sure "JRE System Library" is selected (highlighted). Click Next. Click Finish. Right-click on the "Lab2Part2" folder underneath the "Lab2" icon. In the menu that pops up, select "Build Path", then select "Use as source folder" from the second menu that pops up. To run the code, right-click on the "QuickSort.java" icon in the sidebar and select "Run As", then "Java application" from the second menu that pops up. You can also go to the Run menu > "Run As" > "Java application". You will see an assertion failure, which is expected. Start editing the code to make the test work! Alternately, or if you're not using Eclipse: https://github.com/catamorphism/cis27/tree/master/Lab2/Part2 (Links to an external site.) and copy/paste the Java file there into your project. You will need to import the textbook code (see Using the textbook code ).
Attached
No File uploaded yet.
Bidders
truewriter 6 years, 4 months ago
Rated 9.26 earned 20430.87 around 562 assignments.
Greetings buddy! I am a professional writer, trainer, programmer and editor with more than five years experience. Have my assurance that this assignment will be delivered EVEN BEFORE THE DUE TIME.NO PLAGIARISM AT ALL. I follow instructions as outlined. I don’t disappoint . You can trust me to deliver a well-researched and scholarly assignment to you
$250.00
  • would you be willing to lower down the price?
    User_28808 | May 18, 2020, 08:20 AM
  • hello, yes am willing friend, to how much please? humble regards
    truewriter | May 18, 2020, 08:22 AM
  • hey friend
    truewriter | May 18, 2020, 08:40 AM
  • how much is your budget for the task?
    truewriter | May 18, 2020, 08:42 AM
  • {$ item.message_content $}
    {$ item.sender_username $} | {$ item.date_entered $}
 
 
vickymi 6 years, 4 months ago
Rated 8.96 earned 6249.41 around 194 assignments.
Please let me work on the order my job will speak for itself, I 0-guarantee perfection!!! NO PLAGIARISM, WELL STRUCTURED PAPER, NO GRAMMATICAL MISTAKES, EASY FLOW OF WORK, ADHERENCE TO ORDER INSTRUCTIONS AND SUBMISSION ON TIME!!!! Thank you
$250.00
  • {$ item.message_content $}
    {$ item.sender_username $} | {$ item.date_entered $}
 
 
Vinniax 6 years, 4 months ago
Rated 9.34 earned 13276.58 around 356 assignments.
I am a guru in computer science and i promise you an A in this work, please award me this bid now.
$230.00
  • {$ item.message_content $}
    {$ item.sender_username $} | {$ item.date_entered $}
 
 
lupita 6 years, 4 months ago
Rated 9.36 earned 11670.86 around 435 assignments.
Hey, allow me to assist you with your assignment. Am an expert and only deliver quality and plagiarism free work within the stipulated time. I have the ability and experience to work on every possible niche. Accord me the chance to help you. Thank you
$200.00
  • Kindly find the attached doc. In case of anything do not hesitate to contact me. I offer long term services to my clients. Feel free to send more work and I will give you 10%. Thank you for allowing me to serve you. Please rate me 10 . Again I say thank you
    User_5369 | May 19, 2020, 03:31 AM
  • Please release funds
    User_5369 | May 19, 2020, 19:05 PM
  • Please release funds
    User_5369 | May 20, 2020, 22:29 PM
  • {$ item.message_content $}
    {$ item.sender_username $} | {$ item.date_entered $}