1) How can we delete an arbitrary node from a heap? Sol: given index i, to delete it we will replace it with A[heapsize(A)] and then decrease the heapsize. If the new value is smaller than the old value we will call a Max-Heapify. Otherwise we call the Increase-key method we developed for priority queues. Either way, it takes \Theta(\log n). 2) In class we showed how to build a Max-Heap by calling Max-heapify repeatedly in a bottom up manner. Can we build a heap in a top-down manner? how? Sol: Let A[1..n] be an arbitrary array and we want to turn it into a heap. We can start from A[2] (going to A[n]) and for each one we bubble up the node (just like in Increase-key given for priority queues): New-Build-Max-Heap (A) ** Builds a Max Heap Heapsize(A)<--- Length(A) for i <-- 2 to Heapsize(A) do j <--- i while (i>1 and A[j]>A[parent(j)]) do exchange A[j] <--> A[parent(j)] j <-- parent(j) What is the running time? for each value of i we may have to travel the whole height of the tree. In particular, for the last level of the tree each node may go up all the way to the root. So it will take \Theta(n\log n) which is worse than the Build-Max-heap we saw in class.