Please make sure you adhere to the policies on academic honesty.
Please see the general programming webpage for details about the programming environment for this course, and specifically for directions in how to submit your programming assignment electronically.
The files you need for this assignment can be downloaded here.
This assignment will also make use of the Composition and Comparator design patterns discussed in Section 7.1.4. We review those concepts here:
Now we are ready to describe your two tasks.
The first task is to try to get a simple (but correct) implementation of a priority queue, even if it is not very efficient. Specifically, we want you to implement the priority queue using an array of Item's, where items are kept in an arbitrary order. To simplify matters, the priority queue constructor will be sent a parameter cap which is a predefined maximum capacity (thus allowing you to initialize your array).
Conceptually, this should be very easy. Our purpose for having you do this implementation is more for the challenge of using the required syntax. Also, we will then be able to use this for comparison of efficiency with our second implementation.
We have started your work by providing two files SlowPQ.h and SlowPQ.tcc which form the outline of your implementation. As you find need for additional member variables for your class, you must add those variables to the header file SlowPQ.h. For all of the required methods, you must provide an implementation in SlowPQ.tcc. If you find need to introduce additional methods for your own use, you will need to declare such a method initially within SlowPQ.h and then implement the method in SlowPQ.tcc.
The second implementation, titled FastPQ, will be based on a heap as specified in Section 7.3.2. Although we intuitively think of a heap as a binary tree, we will ask you to design your implementation based on the array representation of a heap (equivalently the "vector" representation as discussed on page 305 of the text). Again, you will use an array of Item's, but rather than keep them unordered, you will partially order them based on the heap property. Section 7.3.3 of the text gives an implementation of a priority queue with a heap, based on using the BinaryTree interface. Though this is different syntactically than what you must do, you may choose to look closely in understanding the algorithmic process.
Again, we have started you out with files FastPQ.h and FastPQ.tcc which you should adapt.
After you have both of your implementations working (hooray!), we want you to perform some experiments which will be reported in your 'readme' file. This will allow you to compare the efficiency of the two priority queue implementations. Your timing information will be gathered using a driver PQTimer, described in more detail later.
Report the running times of PQTimer, using the SlowPQ, on values of N as large as your program can handle in a reasonable time limit. Start with N=100, 1000, 10000, 100000, 1000000, 10000000, continuing until the time becomes unreasonable. Record the running times in your readme file.
Now, repeat these experiments using the FastPQ implementation, again using values of N as large as the program can handle. Record these running times as well.
(Note: we are not asking you to submit an inputfile for this assignment)
To run this driver, you should specify two additional command line arguements, as ./PQTimer [pqimplementation] [N], where [pqimplmentation] is either S for SlowPQ or F for FastPQ, and [N] is a positive integer.
The driver performs two experiments. In the first, it will insert N items, with randomly chosen keys, after which it will call removeMin() N times. In the second experiment, it will start over with an empty queue, then insert N items, then perform an additional N operations which will be a random mix of insertions and removals.