COMP 212
Programming Assignment 2
Due April 10, 2000

In class we considered a number of implementations of a priority queue. Which one is the best depends somewhat on the situation. The purpose of this exercise to experiment with sorting a set of random integers using different implementations of a priority queue in order to decide which implementation is best for this problem.

To this end your first task is to implement four versions of a priority queue:

1.
PQ1 - using an unordered array.

2.
PQ2 - using an ordered array.

3.
PQ3 - using a binary heap.

4.
PQ4 - using a ternary (degree 3) heap.

For each version you should supply methods for (i) initializing an empty priority queue (ii) testing if a priority queue is empty (iii) inserting an item into the priority queue and (iv) deleting the maximum item from the queue.

Having implemented (and hopefully tested they are correct!) the above versions you are to compare how well they perform on the sorting problem. In particular, for each of the four PQs and for N = 2i, i = 0, 1, ... , 7, compute how long it takes to sort N randomly generated integers by first inserting them one at at time into the PQ, and then extracting them in order from largest to smallest using the getmax operation.

You should include in your source a commented section containing a table of your results. Also comment on how the results meet with your expectations considering the analysis performed in class.


Some Notes:



 

2000-03-28