Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In class we implemented a maxheap, with the largest item at the root of the tree

ID: 3736202 • Letter: I

Question

In class we implemented a maxheap, with the largest item at the root of the tree. Write the code for the two helper methods that reorganize the heap after an item is added or removed:
private void siftUp (int i)
private void siftDown (int i)
Then compile and run Heaps.java. The output should look like this:
original array
[8, 5, 3, 9, 2, 7]
after converting to a heap
[9, 8, 7, 5, 2, 3]
removing the largest item
[8, 5, 7, 3, 2]
removing the largest item
[7, 5, 2, 3]
adding 13 to the heap
[13, 7, 2, 3, 5]
adding 1 to the heap
[13, 7, 2, 3, 5, 1]
after removing everything
[ ]

Code

**********************************************************************************************************************************************************************************************************************








Explanation / Answer

Here are the two requred functions

/**

Shift down is actually called max Heapify and it is called to maintain the max heap property when an item is removed.

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote