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, 27 April 2012, 10:00am
Please make sure you adhere to the policies on academic integrity.
For this assignment, you must work individually.
Please make sure you adhere to the policies on academic integrity in this regard.
Preface: Our text describes priority queues as structures with (key,value) pairs as elements. 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 8.3 as a guide for style (but ignoring values), draw the heap that 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 7.3.5 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 8.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-8.13 of the text.