asg9 - COP 3530 Assignment 9 Due: 30th Oct 2008 In this...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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 min-max 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 min-max 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, min-max 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 min-max 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
these 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:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

asg9 - COP 3530 Assignment 9 Due: 30th Oct 2008 In this...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online