Lesson AB33 - PriorityQueues |
|
HeapOfTrouble Background: This lab is designed to give you experience in implementing a general comparable heap. The data structure that you use to store the heap must be an
So now the cheesy story for the lab. Recently, Semester grades were given out for the Advanced Placement Computer Science class, George must now meet with the students to discuss their grades and advise them on the best course of action in light of their recent grades. George is swamped with work, so he has given you a list of all of the students and their grades so that you can sort them. Students that do poorly need to meet with George sooner than those that are doing well; if the students have the same grade then they must be ordered according to their Lynbrook id. Assignment: As you have learned, heaps are trees with the following additional constraints: heaps are complete and heaps maintain the heap order property. The heap order property states that the parent of a node will be less than its children if the heap is a min-heap, and the parent will be greater than its children if the heap is a max-heap. Insertion and deletion operations in a heap are O(log n) where n is the number of elements in your heap. Also, since the top element of the heap is the always going to be the smallest or largest element (depending on the type of heap), you can use a heap to sort its data by removing the top element until there are none left. The data in the sequence of removals will then be in increasing (decreasing in case of a max-heap) order. The running time of this sort, if you have n elements in the heap, will be O(n log n) since you will be performing n deletes which makes the cost to sort the heap n*[cost of one delete]. Since the cost of one delete is O(log n), the total cost is O(n log n). For this assignment you will have to make a min-heap of students. A student has a Lynbrook id, first name, last name, and semester grade.
The
As the main objective of the lab is to learn about heaps, it would not be a bad guess that you will have implement one. The heap you are to implement is a min-heap of
In addition to the methods above, you must also print out grades in sorted order. The method you must complete is located in the main driver program ( Everything you need to know about heaps, at least for this assignment, should have been covered in class
and the class notes, however if you need quick refresher, visit
this heap site. Instructions:
|
|