Question: I copied the heap.java and main.java public class Heap { private int currentSize; private int[] heapArray; // Constructors public Heap() { setCurrentSize(0); heapArray = new
I copied the heap.java and main.java 
public class Heap { private int currentSize; private int[] heapArray; // Constructors public Heap() { setCurrentSize(0); heapArray = new int[1]; } public Heap(int capacity) { setCurrentSize(0); heapArray = new int[capacity + 1]; } // Heap Operations public int[] buildHeap(int[] array) { // Builds the heap from an array that you have provided // IMPLEMENT THIS METHOD // ... // percolateDown(hole); } public int deleteMin() { // Deletes the min element of binary min heap // IMPLEMENT THIS METHOD // ... // percolateDown(rootIndex); } private void percolateDown(int hole) { // Organizes the elements of the heap and percolate down the elements for not violating heap properties // IMPLEMENT THIS METHOD // ... } public int getMinValue() { // Returns the min (root) of the binary min heap // IMPLEMENT THIS METHOD // ... } public int getHeight() { // Returns the height of the binary min heap // IMPLEMENT THIS METHOD // ... } public void insert(int value) { // Inserts an integer element to the binary min heap if(currentSize == heapArray.length - 1) enlargeArray(heapArray.length + 1); int hole = ++currentSize; percolateUp(value, hole); } private void percolateUp(int value, int hole) { // Organizes the elements of the heap and percolate up the elements for not violating heap properties for(heapArray[0] = value; Integer.compare(value, heapArray[hole / 2]) public class Main { public static void main(String[] args) { // Instantiate a heap // ... // Build the heap with using insert method for some numbers like 52, 25, 40, 2, 10, etc. // insert(52); // insert(25); // . . // . . // . . // Print the heap that you have created // ... // Get min value of the heap that you have created // ... // Get height of the heap that you have created // ... int[] arrayB = {15, 170, 5, 28, 92, 84, 38, 203, 37, 70, 40}; // Use arrayB[] for building the heap again with buildHeap() method this time and print it // ... // Use deleteMin() method to delete root of the heap and print the new heap // ... } } modify both Heap.java and Main.java files. 1. Instantiate a new Heap object in the main function. 2. Heap class has an insert(int value) method which inserts the given value to the heap. Use that method to build your heap with random numbers. You can use any value to test whether the method works properly or not. 3. Print the elements that you have inserted using the method printHeap (). 4. Implement getMinValue () method which returns the minimum element of the heap. Use it and print the minimum value. 5. Implement getHeight () method which returns the height of the heap. Use it and print the height of the heap. 6. Implement the buildHeap (int value) method this time which builds a binary min heap from the given array arrayB. 6.1. You will need to implement percolateDown(int hole) helper method for buildHeap method to work. It moves down the hole to the correct position without violating the heap order property. 7. Print the heap elements using printHeap () again. 8. Implement a deleteMin() method which deletes the root of the heap and organizes the heap accordingly. Print this new heap after this operation. This method should also use percolateDown(int hole) method to work Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
