|
CS 361: Algorithms and Data Structures |
||||||||||||||||
|
Please bring a hardcopy of the written questions to turn in at the beginning of class. This assignment also has a paired programming portion. See below for instructions on how to submit your code. |
||||||||||||||||
Written Assignment [15 points]
|
||||||||||||||||
|
Java Programming Assignment [35 points]
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 expected:
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 Rubric
Your priority queue will be graded based on the following criteria:
|
||||||||||||||||
|
Submission Instructions
Your Java code should be submitted in a zipped directory. The directory should contain the following Java files:
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 documentation provided above. Email me your zipped directory by the beginning of class. Use my PugetSound email address rather than Piazza. |