Assignment 5 -- due Thursday, October 10 at the beginning of lab
CS 5521 Fall Semester, 2013
20 Points

Topics: Quicksort, randomized quicksort, and their run times

The assignment: consists of two parts: In the first part, you are asked to implement quicksort, randomized quicksort, and heapsort, and compare their running times with merge sort;. in the second part, you are asked to prove a fact about the run time of quicksort.

Part 1: Comparing the run times of sorting routines (15 points)

Implement the following three sorting routines:
  1. heapsort (page 160) -- actually, you should implement "min-heapsort" that sorts in decreasing order, which is easy to do with the minHeapify() routine of the previous assignment. Rather than implementing accessors and mutators (which is good software engineering), declare the member variables (the array A[], length, and heapSize) to be public so that heapsort is not slowed down by accessor/mutator function calls.
  2. quicksort (page 171), and
  3. randomized-quicksort (page 179).

After you have coded all three of the sort routines, load the array A with the integers 1, 2, ..., n in order, i.e., A[i] = i. This should produce worst-case performance for quicksort; the run times of the other two sorts should by independent of the order of the input.

Make timing runs for each of the sorts for the largest value of n that you used for merge sort in Assignment 2 and record the times for each of the four sorts:

  1. merge sort (from Assignment 2)
  2. heapsort
  3. quicksort
  4. randomized quicksort
Compare the results -- which is fastest? slowest?

Discussion: for randomized-quicksort, you can use the C library routine rand() to get a (pseudo-) random number (int) in the range 0 to RAND_MAX (e.g. RANDOM(p,r) could just return p + rand() % (r - p + 1) -- or, better: change Line 1 of RANDOMIZED-PARTITION() to i = p + rand() % (r - p + 1) ). Note: rand() and RAND_MAX are declared in <stdlib.h>.

What To Hand In: The results of your timing runs and the code for each of your new sort routines.

Part 2: Proving a fact about quicksort's run time (5 points)

Page URL: /~ddunham/cs5521f13/assignments/a5/assignment.html
Page Author: Doug Dunham
Last Modified: Thursday, 03-Oct-2013 21:23:45 CDT
Comments to: