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
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