Assignment 5 -- due Friday, October 14
CS 4521 Fall Semester, 2005
18 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 facts about the run time of quicksort.

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

Implement the following three sorting routines: heapsort (page 136), quicksort (page 146), and randomized-quicksort (page 154).

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: merge sort (from Assignment 2) and the three new ones. Compare the results -- which is fastest? slowest?

Discussion: for randomized-quicksort, you can use the C library routine rand() to obtain (pseudo-) random number (int) in the range 0 to RAND_MAX (for example, RANDOM(p,r) could simply return   p + rand() % (r - p + 1) -- or, better: replace Line 1 of RANDOMIZED-PARTITION() with   i <- p + rand() % (r - p + 1) ). Note: rand() & 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 facts about quicksort's run time (8 points)

Do the following Exercises from the text, which ask you to prove facts about quicksort's run time.


Page URL: http://www.d.umn.edu /~ddunham/cs4521f05/assignments/a5/assignment.html
Page Author: Doug Dunham
Last Modified: Tuesday, 04-Oct-2005 17:41:39 CDT
Comments to: ddunham@d.umn.edu