简体   繁体   English

为什么不是heapsort lg(n!)?

[英]Why isn't heapsort lg(n!)?

I'm reading CLRS and it says heapsort is 我正在阅读CLRS,它说的是heapsort

HEAPSORT(A):
BUILD-MAX-HEAP(A);
for (i = A.length; i >= 1; i++)
{
    exchange A[1] with A[i];
    A.heap-size = A.heap-size - 1; 
    MAX-HEAPIFY(A,1);
}

MAX_HEAPIFY is O(lg n) . MAX_HEAPIFY是O(lg n) The book says it runs MAX-HEAPIFY n times thus it is O(n lg n) time. 该书说它运行MAX-HEAPIFY n次,因此它是O(n lg n)时间。

But if the heap is shrinking in size by 1 each iteration shouldn't it be O(lg n!) ? 但是如果堆的大小缩小了1,那么每次迭代都不应该是O(lg n!)

It would be lg 1 + lg 2 ... + lg(n-1) + lg (n) = lg(n!) , right ? 它将是lg 1 + lg 2 ... + lg(n-1) + lg (n) = lg(n!) ,对吗?

Actually it's Stirling's Approximation : 实际上这是斯特林的近似值

O( log(n!) ) = O(nlogn) O( log(n!) ) = O(nlogn)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 T(n)= 2T(n / 2)+ n lg lg n的渐近上界和下界是什么? - What are the asymptotic upper and lower bounds for T(n) = 2T(n/2) + n lg lg n? 如何计算T(n)= 3T(n / 3)+ O(lg n) - How to calculate T(n) = 3T(n/3) + O(lg n) 为什么karatsuba O(n ^ 2)不那么复杂? - Why isn't the complexity of karatsuba O(n^2)? 为什么我的合并排序不像O(n * lg n))? - Why is my merge sort not behaving like a O (n * lg n))? 使用主定理方法求解递归 T(n) = T(n / 2) - T(n / 6) + O(lg n)? - Solving the recurrence T(n) = T(n / 2) - T(n / 6) + O(lg n) using the master theorem method? 如何使用大师定理求解此递归T(n)= 5T(n / 2)+ n ^ 2 lg n? - How to solve this recursion T(n) = 5T(n/2) + n^2 lg n using master's theorem? lg(ni) 是 lg(n) 的 Omega? - lg(n-i) is Omega of lg(n)? 为什么归并排序的递归树的总层数是lg n + 1? - Why the total number of levels of the recursion tree of a merge sort is lg n + 1? 如何解决递归T(n)= T(n / 2)+ T(n / 4),T(1)= 0,T(2)= 1是T(n)=Θ(n lgφ),哪里是黄金分割率? - How to solve the recurrence T(n) = T(n/2) + T(n/4), T(1) = 0, T(2) = 1 is T(n) = Θ(n lg φ ), where φ is the golden ratio? 如果n体问题很混乱,为什么不将其用作RNG? - If the n-body problem is chaotic, why isn't it used as a RNG?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM