This preview shows pages 1–3. Sign up to view the full content.
COP 3530
Assignment 9
Due: 30
th
Oct 2008
In this assignment you will modify the heap data structure and algorithms to get an
implementation of a
minmax heap
, which can be used to find the minimum
and
the
maximum in constant time, while still supporting O(log n) insertion and deletion and
linear time initialization.
In a minmax heap one arranges the records so that each node at even depth has key value
greater than that of any of its descendants, and each node at odd depth has key value less
than that of any of its descendants. Note that like min heaps and max heaps, minmax
heaps are always complete trees.
Here the circles are on odd levels, so they will always be smaller than their descendants.
Hence the smallest element in the tree is 2. The nodes shown as a square are on even
levels, so their key values will always be larger than their descendants. For example here
25 is larger than 17,5,21,18 and 6.
1.
Implement the methods getMax() and getMin(). These methods return the
maximum (or minimum for getMin) element, but they don't modify the heap in
any way. You can use the given initialize() methods to create a heap and test your
implementations.
These methods need to run in constant time
.
2.
Implement the method put(Comparable), which adds an element into the minmax
heap.
This methods needs to run in logarithmic time. &ote that if the capacity
gets full, you will have to increase the capacity of the "heap"( i.e. create a
new array then copy all elements into it). The time consumption caused by
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Documentthese capacity modifications should not be taken into account for the running
time requirement.
3.
Implement the methods removeMin() and removeMax(). These methods remove
the maximum (or minimum) elements from the heap and return them.
The
running times for these methods need to be logarithmic.
Notes:
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 Davis
 Algorithms, Data Structures

Click to edit the document details