首页 > 试题广场 >

参考过程MAX-HEAPIFY,写出能够维护相应最小堆的MI

[问答题]
参考过程MAX-HEAPIFY,写出能够维护相应最小堆的MIN-HEAPIFY(A,i)的伪代码,并比较MIN-HEAPIFY与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


这道题你会答吗?花几分钟告诉大家答案吧!