Worst-case Analysis for Max-Heapify 过程Max-Heapify中不包含循环,所以,如果不递归,其 代价是O(1)。 口如果考虑比较运算的次数,每“下沉”一层,执行2次比较。 ·递归:T(m)≤T(2n/3)+Θ(1) 问题5: 为什么? The solution to this recurrence,by case 2 of the master theorem (Theorem 4.1). is T(n)=0(lg n).Altematively,we can characterize the running time of MAX- HEAPIFY on a node of height h as O(h)
Worst-case Analysis for Max-Heapify 过程Max-Heapify中不包含循环,所以,如果不递归,其 代价是O(1)。 如果考虑比较运算的次数,每“下沉”一层,执行2次比较。 递归:
造“堆”:自底向上 413269 101487 分界线 A.length/2] 3 6 2 16 9 10 14 8 这5个子树已经是”堆”了
这5个子树已经是”堆”了。 分界线 造“堆”:自底向上