Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I copied the heap.java and main.java . public class Heap { private int currentSize; private int[] heapArray; // Constructors public Heap() { setCurrentSize(0); heapArray =

I copied the heap.java and main.java .

image text in transcribed

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 currentSize = array.length; heapArray = new int[(currentSize + 1)]; for (int i = 0; i  0; i--) { percolateDown(i); } return heapArray; } private void percolateDown(int hole) { // Organizes the elements of the heap and percolate down the elements for not violating heap properties int child; int tmp = heapArray[hole]; for( ; hole * 2  

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

public class Main { public static void main(String[] args) { int[] arrayA = {25, 35, 10, 15, 150, 64, 48, 105, 149, 148, 130, 22, 67, 56, 43}; // Instantiate a heap // ... // Build the heap from given array arrayA[] with buildHeap() method and print it // ... // Get min value of the heap // ... // Get height of the heap // ... // Insert random numbers one by one to test whether the insert() method works or not // ... // insert(52); // Search a number for if the heap includes it or not // ... // search(52); } }
In this assignment you are already given an array implementation of a Heap. You need to modify both Heap.java and Main.java files. 1. Instantiate a new Heap object in the main function. [5 pts] 2. Heap class has a buildHeap (int[] array) method which builds a binary min heap from the given array arrayA[]. Use that method to build your heap. (10 pts) 3. Print the elements using the method printHeap (). (5 pts] 4. Implement getMinValue () method which returns the minimum element of the heap. Use it and print the minimum value. (10 pts] 5. Implement getHeight () method which returns the height of the heap. Use it and print the height of the heap. [10 pts] 6. Implement the insert(int value) method in Heap class which inserts the given value to the heap. You can use any value to test whether the method works properly or not. (20 pts) 6.1. You will need to implement percolateUp (int value, int hole) helper method for insert method to work. It moves up the hole into the correct position without violating the heap order property. [25 pts) 7. Print the heap elements using printHeap () again. [5 pts] 8. Implement a search(int value) method which searches the given element and returns TRUE if the element is found in the heap, FALSE otherwise. Your method should use heap properties for its benefit. [10 pts]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

18. Explain the concept behind instruction pipelining.

Answered: 1 week ago

Question

Timeline for progress report

Answered: 1 week ago