In this lab you are going to complete the code for binomial queue,
by implementing the isHeap() method in the BinomialHeap and
BinomialQueue classes and the insert() and merge()
methods in the BinomialQueue class.
Please review the lecture notes here before you start.
BinomialQueue.java (Problem 1 and 2) to
link.StudentTest.java (Problem 3) to
link.BinomialHeapThe following is an excerpt from the BinomialHeap class:
class BinomialHeap<K> {
K key;
int height;
PList<BinomialHeap<K>> children;
BiPredicate<K, K> lessEq;
BinomialHeap<K> link(BinomialHeap<K> other) {
// ...
}
boolean isHeap() {
// ...
}
}
link() method takes two trees of the same height and
combines them into a new tree with one greater height.isHeap() method should verify that the tree
rooted at the current instance of BinomialHeap satisfies the
max heap property, that is, that the key of each parent is greater or equal to
the keys of its children.BinomialQueueThe following is an excerpt from the BinomialQueue class:
public class BinomialQueue<K> {
PList<BinomialHeap<K>> forest;
BiPredicate<K, K> lessEq;
public BinomialQueue(BiPredicate<K, K> le) {
// ...
}
public void push(K key) {
// ...
}
public K pop() {
// ...
}
public boolean isHeap() {
// ...
}
static <K> PList<BinomialHeap<K>>
insert(BinomialHeap<K> n, PList<BinomialHeap<K>> ns) {
// ...
}
static <K> PList<BinomialHeap<K>>
merge(PList<BinomialHeap<K>> ns1, PList<BinomialHeap<K>> ns2) {
//...
}
}
isHeap() method verifies that the binomial queue
(which is a forest of binomial trees) satisfies the heap property.[YOUR TASK] The insert() method in BinomialQueue should put the tree n into
the forest ns while maintaining two invariants:
merge() method in BinomialQueue should combine two forests
into a single forest that satisfies the two invariants above.Create tests in StudentTest.java which thoroughly test the public
push and pop methods of the BinomialQueue.