CSCI 1321 (Principles of Algorithm Design II), Fall 2007:
Homework 7

Credit

Design 20 points; code 40 points.

Overview

By now your game should be playable, with all the major functionality implemented. This homework is something of a tangent; the goal is to write a second, more efficient priority queue and compare its performance with your first version. The needed code breaks down into two categories:

First, you are to write a second priority queue class that uses a heap (as discussed briefly in class, and also in the textbook, using an array or Vector to store elements) rather than a sorted linked list.

Second, you are to add code to your game that will allow you to compare the performance of the two implementations as the number of game entities in the queue varies. To do this, you need to do several things: create a ``dummy'' game entity class so you can put arbitrarily many entities in the priority queue, change your main class to accept two command-line arguments that specify which implementation to use and how many of these dummy entities to add, and change your player class to print out some information that will allow you to see how performance varies based on the choice of priority queue implementation and the number of dummy entities.

Once you do these two things, you can run your game with different values of the two command-line arguments and see how performance changes. The final part of this assignment is to do this and plot the results.

Design and Code

You need to do the following:

Once you have written and tested the above code, I want you to collect and plot timing information that shows how, for each version of the priority, performance (time for 100 calls to player's update method) changes as the number of dummy entities increases. You will have to experiment a little to see what number of entities is needed to get meaningful results. Start with a small number (say 10), and then increase it by factors of 2 or 10 until you see performance differences. What you should see is that for $ n$ entities the time for the linked-list version is roughly proportional to $ n^2$ , while for the heap version time is roughly proportional to $ n \log n$ .

Step-by-step instructions

Files and links



Berna Massingill
2008-01-17