script

Friday, January 11, 2013

6.2-2


Starting with the procedure MAX-HEAPIFY, write pseudocode for the procedure MIN-HEAPIFYA(i), which performs the corresponding manipulation on a minheap. How does the running time of MIN-HEAPIFY compare to that of MAXHEAPIFY? MIN-HEAPIFY A(i)
l = left(i)
r = right(i)
if l<=A.length and A[l] < A[i] then smallest = l else smallest = i; if r<=A.length and A[r] < A[smallest] then smallest = r if smallest != i then swap a[i] and a[smallest] MIN-HEAPIFY(A,smallest) The running time is same as MAX-HEAPIFY because the max size of substree 2n/3 and $\theta(1)$ to swap A[i] and A[left(i)] and A[right(i)].

No comments:

Post a Comment