[英]Asymptotic run time complexity of an expression
Can I say that: 我可以这样说吗:
log n + log (n-1) + log (n-2) + .... + log (n - k) = theta(k * log n)? log n + log(n-1)+ log(n-2)+ .... + log(n-k)= theta(k * log n)?
Formal way to write the above: 上面的正式写法:
Sigma (i runs from 0 to k) log (ni) = theta (k* log n)? Sigma(i从0到k)log(ni)= theta(k * log n)?
If the above statement is right, how can I prove it? 如果以上说法正确,我该如何证明?
If it is wrong, how can I express it (the left side of the equation, of course) as an asymptotic run time function of n and k? 如果不正确,如何将其(当然是等式的左侧)表示为n和k的渐近运行时间函数?
Thanks. 谢谢。
Denote: 表示:
LHS = log(n) + log(n-1) + ... + log(nk)
RHS = k * log n
Note that: 注意:
LHS = log(n*(n-1)*...*(nk)) = log(polynomial of (k+1)th order)
It follows that this is equal to: 因此,这等于:
(k+1)*log(n(1 + terms that are 0 in limit))
If we consider a division: 如果我们考虑除法:
(k+1)*log(n(1 + terms that are 0 in limit)) / RHS
we get in limit: 我们受到限制:
(k+1)/k = 1 + 1/k
So if k
is a constant, both terms grow equally fast. 因此,如果k
为常数,则两项均会快速增长。 So LHS = theta(RHS)
. 所以LHS = theta(RHS)
。
Wolfram Alpha seems to agree. Wolfram Alpha似乎同意。
When n
is constant, terms that previously were 0
in limit don't disappear but instead you get: 当n
为常数时,以前限制为0
不会消失,而是得到:
(k+1) * some constant number / k * (some other constant number)
So it's: 所以是:
(1 + 1/k)*(another constant number)
. (1 + 1/k)*(another constant number)
。 So also LHS = theta(RHS)
. 所以LHS = theta(RHS)
。
When proving Θ
, you want to prove O
and Ω
. 证明Θ
,要证明O
和Ω
。
Upper bound is proven easily: 上限很容易证明:
log(n(n-1)...(nk)) ≤ log(n^k) = k log n = O(k log n)
For the lower bound, if k ≥ n/2
, then in the product there is n/2
terms greater than n/2
: 对于下限,如果k ≥ n/2
,则在乘积中有n/2
项大于n/2
:
log(n(n-1)...(nk)) ≥ (n/2)log(n/2) = Ω(n log n) ≥ Ω(k log n)
and if k ≤ n/2
, all terms are greater than n/2
: 如果k ≤ n/2
,则所有项均大于n/2
:
log(n(n-1)...(nk)) ≥ log((n/2)^k) = k log(n/2) = Ω(k log n)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.