Saint Louis University |
Computer Science 180
|
Dept. of Math & Computer Science |
Topic: Priority Queues
Related Reading: Ch. 7.1-7.3 of the text.
Due:
Friday, 5 May 2006, 1:10pm
Please make sure you adhere to the policies on academic integrity.
Preface: In terms of a programming implementation, it is important to keep in mind that items inserted into a priority queue are represented as a (key,element) pair. For simplicity, this homework will only pay attention to the key.
Assume that we start with an initially empty heap, and that items are inserted with the following sequence of integer keys:
insert(12), insert(7), insert(14), insert(5), insert(20), insert(11), insert(6), insert(18), insert(8), insert(3), insert(17), insert(13), insert(4), insert(9).Using Figure 7.3 as a guide for style, draw the heap which results at the very end of the last operation.
Note: for this problem we are not requiring you to show any of the work along the way, though you may if you wish. Please do be careful to follow the exact sequence given and to double-check your work.
Chapter 6.4.1 of the text discusses a vector-based representation of a binary tree T based on a level numbering of the nodes of T. The use of this representation for heaps is discussed further in Chapter 7.3.2. Please draw the contents of an array which represents the tree T you gave in your answer to Problem A.
Consider the heap given below using the vector-based representation of a binary tree T.
index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Value | 3 | 6 | 9 | 12 | 8 | 18 | 11 | 20 | 13 | 17 | 24 | 23 | 22 | 15 | 26 | 21 | 25 | 27 | 16 |
For this problem, we want you to draw the five heaps which result at the end of each of the following operations. Your answers should also be drawn using the vector-based representation.
removeMin() removeMin() removeMin() removeMin() removeMin()
Note: in your own personal scratchwork, you might convert the heaps to the more natural tree representation, perform the operation, and then convert back to the vector in reporting your answer. However with a bit of practice, you should be able to perform the operations directly on the vector-based representation!
Creativity Exercise C-7.15 of the text.