Question: pls write in java. thank you here is heap code: public class Heap { // We will assume a maximum heap dimension // You could

 pls write in java. thank you here is heap code: public

pls write in java. thank you

here is heap code:

public class Heap { // We will assume a maximum heap dimension // You could easily change the code to re-size if the heap gets full // Here, we just throw an exception in this case private static int defaultDim = 1024; HeapNode[] h; int last; public Heap() { h = new HeapNode[defaultDim]; last = -1; } public boolean isEmpty() { return (last last) return; for (int j = 0; j = h.length) throw new HeapFullException(); // Wrap the content in a node h[last] = new HeapNode(o, p); // Bubble up this node if need be int i = last; int parent; for (parent = getParent(i); i > 0 && h[i].key

------------------------------------------------------------------------------------------------------------------------------------------------------------

package Heap;

public class HeapEmptyException extends Exception { public HeapEmptyException() { super("Heap is empty"); } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------

package Heap;

public class HeapEmptyException extends Exception { public HeapEmptyException() { super("Heap is empty"); } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------

package Heap;

public class HeapFullException extends Exception { public HeapFullException() { super("Heap is full"); } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------

package Heap;

public class HeapNode { Object content; int key;

public HeapNode (Object o, int priority) { content = o; key = priority;; } }

a Add to the Heap class (minimum heap) provided to you a method for finding the maximum element from the heap in the most efficient man- ner possible, without changing the fact that each node is smaller than its children Your method should be called: public Object getMax0) throws HeapEmptyException. b What is the big oh of your method? justify your answer c Complete the removeMin method in Heap class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!