Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions