2. Draw the state of the heap from the previous question after a
single call to removeMin
.
3. Repeat the previous exercise for two more calls to removeMin
.
Here is an interface describing a simple Priority Queue ADT:
// The Priority Queue Interface.
interface PriorityQueue<V> {
// Reinitialize
void clear();
// Insert a record
// priority: the priority for the record being inserted.
// value: the record being inserted.
void insert(double priority, V value);
// Remove and return a record.
// Remove the record with the minimum priority
V removeMin();
// Return the record with the minimum priority
V min();
// Return the number of records.
int size();
// Build a priority queue from a collection of elements
// priorities: the priorities for the records being inserted.
// values: the records being inserted.
void build(double[] priorities, V[] values);
};
insert | removeMin | min | 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.space | |
---|---|
Sorted array | |
BST | |
AVL Tree | |
Heap |