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

The contents of the array immediately after returning from the call to build-max

ID: 3835677 • Letter: T

Question

The contents of the array immediately after returning from the call to build-max-heap is

17, 12, 16, 3, 6, 7, 9

That much I understand, but I do not understand what this question above is asking me and how to get the result.

12, 7, 9, 3, 6, 16, 17 <--- This is the correct answer to the question

How did they come to this solution?

01 HEAP SORT (A) 02 BUILD-MAX-HEAP (A) 03 for i A. length down to 2 04 exchange A [1] and Ali 05 A heapsize A heapsize 1. 06 MAX-HEAPIFY (A, 1) 08 A. heapsize A length 09 for i floor (A. length/2) down to 1 10 MAX-HEAPIEY (A, i)

Explanation / Answer

This question is asking to see the content of array afetr runing build max heap

and then you have a loop which is going from 7 to 1, this question is asking to stop at i = 5 and display content before exchange step

so as max heap is 17 12 16 3 6 7 9

so when you have i = 7 and you perform max heapify and decreasing size of heap by 1 (after exchanging last element in heap with root)

you will get

16 12 9 3 6 7 17

Now one more round i = 6 will give

12 7 9 3 6 16 17

and i will be now 5 and here the question want us to stop.

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