Question
Max Heap Lab Heap data structure called to be a complete binary tree while maintaining the heap property, where given node is always greater
Max Heap Lab Heap data structure called to be a complete binary tree while maintaining the heap property, where given node is always greater than its child node/s and the key of the root node is the largest among all other nodes. This property is also called max heap property. always smaller than the child node/s and the key of the root node is the smallest among all other nodes. This property is also called min heap property. You are given a code with Pseudo code. Knowing the properties from the Chapter, write the logic for following methos- heapify, insert, deleteNode import java.util.ArrayList; public class Heap { void heapify(ArrayList hT, int i) { /Heapify(array, size, i) set i as largest leftChild rightChild 21 + 1 21 + 2 if leftChild > array [largest] set leftChildIndex as largest if rightChild > array [largest] set rightChildIndex as largest swap array[i] and array[largest] To create a Max-Heap: MaxHeap(array, size). loop from the first index of non-leaf node down to zero call heapify } void insert(ArrayList hT, int newNum) { /* If there is no node, create a newNode. else (a node is already present) insert the newNode at the end (last node from left to right.) heapify the array */ } void deleteNode(ArrayList hT, int num) { /* If nodeToBeDeleted is the leafNode remove the node Else swap nodeToBeDeleted with the last LeafNode remove noteToBeDeleted heapify the array */ } void printArray(ArrayList array, int size) { for (Integer i : array) { } } System.out.print(i + " "); System.out.println(); public static void main(String args () ) { ArrayList array = new ArrayList (); int size array.size(); Heap h new Heap(); } h.insert(array, 3); h.insert(array, 4); h.insert(array, 9); h.insert(array, 5); h.insert(array, 2); System.out.println("Max-Heap array: "); h.printArray(array, size); h.deleteNode(array, 4); System.out.println("After deleting an element: "); h.printArray(array, size); Put all your work in ONE Zip file and submit it in Canvas. Zip filename should be in format of FirstLast_Lab6.zip (ex. John Doe_Lab6.zip) Zip file should contain 2 files only: (1) Heap.java (2) Output.docx (screenshot of input and output)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started