Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

DESCRIPTION: In this lab you will write a Java class MaxHeap implementing MAX binary heaps, the heapsort algorithm, and a test class TestMaxHeap. The heaps

image text in transcribed

DESCRIPTION: In this lab you will write a Java class MaxHeap implementing MAX binary heaps, the heapsort algorithm, and a test class TestMaxHeap. The heaps wil store objects of type Integer and must be implemented using an array. Each heap may contain items with equal integer value. Then, the value in any tree node must be larger than or equal to the values in any of its descendants SPEciFICATIONS: . Class MaxHeap must contain a field of type Integer], which is a reference to the array which stores the items (references to objects of type Integer). There must be other fields to store the size of the array (the amount of memory allocated) and the size of the heap (number of items stored). All fields must be private. Pay attention to update accordingly these fields when performing the heap operations (when necessary) . Class MaxHeap must contain at least the following constructors . A public constructor which creates an empty heap. The size of the array to be allocated must be passed as a parameter. public MaxHeap (IntegerI someArray) creates a MaxHeap which stores the items from the input array. . Class MaxHeap must contain at least the following public methods 1) public void insert(int n): Inserts the value n in this max heap (inserts an object of type Integer representing n). Duplicates are allowed. If there is no room for the insertion in the current array storing the items, then an array of double size has to be allocated and all items are copied into the new array, after which the insertion is performed 2) private int deleteMaxO: Removes the item with the largest value and re- turns its value. 3) public String toString): Returns a string representing the sequence of integer values stored in the heap, in the order they are stored in the array, i.e., in level order 4) public static void heapsort (Integer[] arrayToSort): Applies heapsort algorithm to sort the input array. You may construct a MaxHeap object storing the items (using the second constructor), apply the delete max repeatedly on this heap, then copy back the items in the array in sorted order. 5) Accessor public methods (get methods) to allow the user to see the values of the fields

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_2

Step: 3

blur-text-image_3

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students explore these related Databases questions