CS 361: Algorithms and Data Structures |
Priority Queue Programming Assignment
This homework assignment is entirely a programming assignment. It is required that you work with a partner. In this assignment, you will create a max priority queue that stores pairs (p, e) which consist of a priority and an element. The element is to be stored in the priority queue with the associated priority. To simplify this assignment, all priorities and elements will be integers. Your priority queue will be implemented using a max heap which (as we discussed in class) is itself implemented using an array. Your priority queue should support the basic methods:
Notice that these three additional methods require you to be able to find an arbitrary element in the heap (i.e. in the array). One way to accomplish this is to do a linear search through the array every time one of these methods is called. However, that requires O(n) work where n is the number of elements in the array. A more efficient approach is to keep track of the index into the array for every element using a map data structure. The input to the map would be the element and the output would be the index of that element in the heap array. You will use Java's HashMap class for this map data structure. According to the Java documentation for the HashMap class, "This implementation provides constant-time performance for the basic operations (get and put)". Consider the following example below which shows the state of the heap and the map after pushing the following pairs: (priority=10, element=1), (priority=0, element=2), (priority=1000, element=3), (priority=47, element=4) The starter code for this assignment can be downloaded here. In addition, complete Java documentation for the priority queue class can be found here. Here are some final comments that you should read before getting started:
|
Grading
Your code will be graded on the following:
|
Submission Instructions Your Java code should be submitted in a zipped directory. You and your partner only need to submit one directory. Please make sure that you put both of your names in the class comment for PriorityQueue.java so I know who you worked with. Your code should compile with no errors and it should obey the Java API provided above. Please upload your zipped directory to Moodle |