In this lab, you will be modifying code and analyzing its performance over several files. You will hand in a copy of your data collection and your evaluation of what type of operation is the most significant for the Quicksort algorithm.
So, I recommend that you start a spreadsheet and prepare to record for each of the files:
Remember that you need to track this information for each of the three files mentioned in the lab.
For today’s lab, we’ll take Weiss’s implementation of Quicksort as a starting point. It can be found on MathLAN on lines 159–248 of the file
/home/jimenezp/csc207/Lab-Sorting/Sort.java
You might already have this file in another Eclipse project and can copy the appropriate lines.
Quicksorter
class, and copy into the definition of that class the definitions of the methods that make up Weiss’s implementation of quicksort.
Look through Sort.java
and copy the methods that are called for sorting arrays with quicksort. Note that you don’t need to copy the definition of the quickSelect
method, but you should copy the insertionSort
method that is used as a helper method by quicksort.Read through the methods.
quicksort
on the following array {55, 10, 20, 60, 100, 70} (Update the code as needed to trace quicksort
on an array of at least 3 elements).
low
and high
for each recursive call, the pivot value, the array elements after each swap and the array elements returning from each call.CUTOFF
?QuickSorterApp
program. In this file, design and write a static method isCorrectlyOrdered
that takes an array as its argument and determines whether its elements are correctly ordered. The elements of the array must implement the Comparable
interface and in particular must be comparable with one another. You should be able to use your method from the previous lab with little or no modification.isCorrectlyOrdered
are working correctly. Once your testing and quicksort programs seem to work correctly, use quicksort on the eight-cousins file:
Write and execute a program to determine whether Weiss’s quicksort procedure correctly rearranges an array that initially contains strings read in from the file:
/home/jimenezp/csc207/Lab-Sorting/eight-cousins.txt.tokenized
(This file contains the full text of Louisa May Alcott’s novel Eight Cousins, with each word or punctuation mark on a separate line.)
Quicksorter
class a static field called swaps that counts the number of calls to the swapReferences
method. Add a statement at the beginning of the public quicksort
method that initializes swaps to 0 and a statement at the end that prints out a message that includes the value of swaps at the end of the sorting process. Finally, add a statement to the swapReferences
method that increments swaps by 1 each time swapReferences is invoked. Use your “instrumented” version of Weiss’s code to count the swaps that the quicksort method makes in sorting the Alcott data.quicksort
method.quicksort
method.rose-in-bloom.txt.tokenized
and little-men.txt.tokenized
. (These files are in the same resources directory path shown in the QuicksorterApp section.)You can compute log (base 2) in Java or use Excel or similar spreadsheet programs (you should be able to calculate the log (base 2) of a number with the formula LOG(N, 2)
).
[4 points] In your write-up report include the Data Analysis Section and answer to posted questions.
I strongly recommend that each student keep a copy of the lab. Therefore, don’t forget to share the files/folder with your lab partner!
Remember: Do not use magic numbers, write your code anticipating errors and print user-friendly error messages, all your public methods should be well documented (use Javadoc comments). Please include comments or organize your code and report in a way that will help the grader to find the answer to the exercises or posted questions.
From Data Structures & Problem Solving Using Java by Mark Allen Weiss