Draw the state of the heap from the previous question after a
single call to removeMin
.
Repeat the previous exercise for two more calls to removeMin
.
Here is an interface describing a simple Priority Queue ADT:
/* MinQueue interface.*/
public interface MinQueue<P extends Comparable<P>, E> {
/* Enqueue the provided value with the indicated priority. */
void enqueue(P priority, E item);
/* Return and remove the item with the lowest associated priority. */
dequeue();
E
/* Return, but do not remove, the item with the lowest priority. */
peek();
E
/* Return the number of elements in this MinQueue. */
int size();
/* Return a MinQueue built from the provided priorities and items. */
<P, E> buildMinQueue(P[] priorities, E[] items);
MinQueue}
enqueue | dequeue | peek | build | |
---|---|---|---|---|
Sorted array | ||||
BST | ||||
AVL Tree | ||||
Heap |
Pair
class and that we are not counting the space
required for the pairs. You may also assume that all tree nodes
contain two child references, and that AVL trees require a
parent reference.space | |
---|---|
Sorted array | |
BST | |
AVL Tree | |
Heap |