Question: We can build a heap by repeatedly calling MAX-HEAP-INSERT to insert the elements into the heap. Consider the following variation on the BUILD-MAX-HEAP procedure: BUILD-MAX-HEAP
We can build a heap by repeatedly calling MAX-HEAP-INSERT to insert the elements into the heap. Consider the following variation on the BUILD-MAX-HEAP procedure:
BUILD-MAX-HEAP′ (A)
1 A.heap-size = 1
2 for i = 2 to A.length
3 MAX-HEAP-INSERT(A, A[i])
a. Do the procedures BUILD-MAX-HEAP and BUILD-MAX-HEAP′ always create the same heap when run on the same input array? Prove that they do, or provide a counterexample.
b. Show that in the worst case, BUILD-MAX-HEAP′ requires Θ(n lg n) time to build an n-element heap.
Step by Step Solution
3.41 Rating (157 Votes )
There are 3 Steps involved in it
a The procedures BUILDMAXHEAP and BUILDMAXHEAP do not always cre... View full answer
Get step-by-step solutions from verified subject matter experts
