证明:对一个大小为n的堆,MAX-HEAPIFY的最坏情况运行时间为
。(提示:对于n个节点的堆,可以通过对每个节点设定恰当的值,使得从根节点到叶节点路径上的每个节点都会递归调用MAX-HEAPIFY)
Max_Heapify(A,idx,max) left = 2*idx right = 2*idx if(left<max and A[left]>A[idx]) then largest = left else largest = idx if(right < max and A[right]>A[largest]) then largest = ritht if(largest != idx) then exchange A[largest] with A[idx] Max_Heapify(A,largest,max) end