Question: Implement algorithm Heapify(A, i, j). Create an array A of size 10 with the following values: 4, 2, 1, 8, 6, 5, 10, 9, 11,

Implement algorithm Heapify(A, i, j). Create an array A of size 10 with the following values: 4, 2, 1, 8, 6, 5, 10, 9, 11, 16. Call Heapify(0, 9). Output the resulting array. Also indicate the time complexity by counting the number of times Heapify is called. (In Java Programming)

Algorithm Heapify(Note: The algorithm in the courseware uses A[1..n]) Input:Indices iand j. An array A[0..n-1] of key values. Output:A[i] sinks to appropriate place in A[i..j] Procedure Heapify(i, j) if (2i+2 <=j) // A[i] has two children Set k=index of max(A[2i+1],A[2i+2]) // kis index of the largest child else if (2i+1 <=j) // A[i] has one child Set k = 2i + 1 // // kis index of the largest (and only) child else // A[i] has no children return if (A[i] < A[k]) Exchange(A[i],A[k]) Heapify(k, j)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the Heapify algorithm in Java and apply it to a given array we need to ensure that the function works correctly by implementing it based ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!