>
CS 1323 Honors, Fall 1996

Individual Project 8

Sort Performance

Due Wednesday, November 20, 4:30pm

What to Hand In

Project Description

There are many processes that can be used to arrange the elements of a sequence in, say, increasing order based on keys within elements. Some of these processes are faster than others.

The functions bubblesort and quicksort in module SortPedagogy ( Supplied Software) specify two different methods with very different performance characteristics.

The equations

bubblesort: t(n) = b n^2
quicksort: t(n) = q n log(n) + p n
model the time required by the bubblesort and quicksort functions (respectively) to operate on a typical sequence of n elements. The constant b in the bubblesort performance model and the constants q and p in the quicksort performance model depend on factors such as the speed of the computing platform (both hardware and software) and the units of measurement (e.g., seconds, minutes, etc.).

The table below records some timing measurements prepared by running the bubblesort and quicksort on sequences of various sizes. This data can be used to estimate the constants b, q, and p in the performance models.

lengthbubblesort (seconds) lengthquicksort (seconds)
100 1.46 2000 4.14
200 4.78 3000 6.53
300 10.77 4000 9.00
400 20.17 5000 11.50

Program 1
Define a function in C that delivers the constant b in the performance model for bubblesort, given a sequence length and the amount of time bubblesort takes to sort a sequence of that length. (To write this function, you first will need to solve, algebraically, the bubblesort time equation for b.) Note that this function will have two parameters: a length and a time.

Using your function that computes b, write a C program that asks the person at the keyboard to enter a sequence length and the corresponding measurement of the bubblesort time for the sequence, then reports the constant b implied by that measurement.

Program 2
Define a function in C that delivers the constant q in the performance model for quicksort, given two entries from the quicksort performance table (that is, a sequence length and the corresponding amount of time quicksort takes to sort a sequence of that length and a second length-time pair of values from the quicksort performance table). Define another function that delivers the constant p, given the same information. (To write these functions, you first will need to solve, algebraically, a pair of quicksort performance equations for q and p - two equations, two unknowns.) Note that these functions will each have four parameters: two length-time pairs.

Using your function that computes q and p, write a C program that asks the person at the keyboard to enter the lengths of two sequences and the corresponding measurements of the quicksort times for the sequences, then reports the constants q and p implied by those measurements.

Program 3
Use programs 1 and 2 to estimate b, q, and p. Then, write a third program that prints a table of sequence lengths and corresponding the bubblesort and quicksort times predicted by the models, using your estimates of the constants involved. This program will contain definitions of functions to compute the times estimated by the models, given a sequence length. It will invoke these functions to get the time estimates for the table. Include only sequences lengths 1,000, 10,000, and 100,000 in the table.

About Models
The performance equations for bubblesort and quicksort are approximations to the actual behavior of those functions. All models reflect certain important aspects of the behavior of the system being modeled, but they do not represent all aspects of the system's behavior. Different performance measurements (such as those in the table) will imply different values for the constants b, q, and p in the models. The values will not vary widely (because the models reflect the dominant aspects of the performance of bubblesort and quicksort), but they will vary to some extent. If you observe a variation of more than 50% between the smallest and largest estimates of any of the constants, you've done something wrong.
Ground Rules