In this lab you will write a program that uses C. A. R. Hoare's recursive quicksort algorithm.
quiktest.java
. Run it on an
apvector of 20 randomly generated integers and quicksort them. To get
a rough idea of the algorithm's running time, modify the program to
declare a variable qcount
that keeps track of how many
times during program execution an array element is compared to the
pivot, splitVal, in calls to Split(..)
. Use proper
labeling to display the array before and after sorting along with
qcount, its running time measure. What did you get for
qcount
?
qcount
, the
quicksort's running time measure defined above, along with
scount
and icount
, the number of comparisons
between array elements in the selection and insertion sort algorithms.
Be sure to comment out the print calls when you change the size of
the arrays. Try each of the three sorts for each of the three
pre-orderings.
For what kinds of data is quicksort really "quicker"? Why?
When is the insertion sort "quicker" Why?
Which pivot value gives the best running time performance over all?
Bonus! Use qsort(..)
, the quicksort function supplied by
the Java compiler. To find out how to access it, type
qsort
, then place the cursor on the word and press
. This accesses the
Continue to: Unit 3
/ Prev
/ Next