This programming assignment is to implement the following three sorting algorithms and to collect time
performance measurements on them.
1. Mergesort,
2. Heapsort,
3. Quicksort.
The running time of cach sorting algorithm must be measured in two ways:
o Count the number of key comparisons, COMPCOUNT. To obtain this count, it is suggeted that
you write a function COMPARE(X,Y), which will perform a comparison between X and Y and
increment COMPCOUNT. Then, wherever you need to perform a key comparison in your algorithms,
you simply make a call to this function.
® Use the actual measured CLOCK time.
You need to ca
y out the experiment in two parts.
1 A small a
ay size, n = 32, to verify co
ectness
Run cach algorithm on three sets of data:
(1) Sorted; (2) Reversely sorted; and (3) Randomly generated.
For simplicity, you may use integers. For each case, make sure the same original data is input to all three
algorithms. Print both the sorted a
ay and measured number of comparisons for cach case to show the
co
ectness of your algorithms.
2 Large a
ay sizes to determine time complexity
Run cach sorting algorithm on the following a
ay sizes:
on=210=1,024
15 32,768
on =220 — 1,048,576
For cach value of n, produce an a
ay of n randomly generated elements only once. (For simplicity, you
may use integers.) Again, make sure you provide the same randomly-generated a
ay of data to all three
sorting algorithms.
Tabulate the performace results, listing both the number of comparisons and the measured clock times.
Use the tabulated number of comparisons to determine the time complexity. For example, does the data
for quicksort verify O(n?) or O(nlogn) time, and what is the constant factor? Note that since you use a
andom sequence to sort, the running times should co
espond to the average-case time complexities.