While (k <= number-of-groups) Group k grades problem k.
Our TA, Pavel Laskov, will be out of town Sept 24 to Oct 5. The
first 3 groups must go over the grading process with Pavel in the
next two days, by Thursday, Sept 23.
4. [Individual Problem] Group 4 grades this problem
Consider processing a sequence of max, delete_max, and insert operations
using an array-based implementation of a heap. In the absence of any information
on the maximum number of items that might be present in the heap at any
given time, the best that we can hope for is some sort of heap "growing/shrinking"
scheme. The idea would be to initially allocate an array of small size.
If the heap "outgrows" that array, then a larger array would
be allocated, the elements would be moved from the original array to the
larger array, and then the original array is deallocated. This process
of arrays' "growing" could, of course, repeat, and, likewise,
if an array becomes too sparse, then it would be "shrunk" by
replacing it with a smaller array.
A reasonable requirement for such a scheme is that: There should exist
a constant k, so that at any point in time, if i items are present in the
heap, then the size of the array being used to store those i items is no
more than ki. Of course, the difficulty in implementing such a scheme comes
in limiting the time used to copy elements from one array to another.
a) [2 pts] Considering that it is possible to implement a heap using
pointers, what is the largest value of k that would be acceptable (for
the array growing/shrinking scheme)? Why?
b) [8 pts] Devise such a scheme. Be sure to explain both the scheme
and how the running time is amortized to yield an overall running time
of O(n) for the processing of n operations (be very explicit in how the
running time is accounted for).
In solving this problem you should assume that the system provides
O(1) operations ALLOC(<array name>, <size>) which allocates
an array of the given name and size, and DEALLOC(<array name>) which
deallocates the named array. For instance, ALLOC(B,8) returns an array
B[1..8]. Of course, this is an "empty" array -- it is up to you
to place values into the entries of the array.
Remark: The C++ Standard Template Library provides this type of
growing/shrinking scheme for its vector "container" class.