我的教授刚刚告诉我们,任何将输入长度减半的操作都有O(log(n))复杂性,这是一个经验法则。为什么不是O(sqrt(n)),两者不是等价的?
发布于 2017-02-04 09:25:28
假设自然对数(否则只是乘以一个常数),我们就有
lim {n->inf} log n / sqrt(n) = (inf / inf)
= lim {n->inf} 1/n / 1/(2*sqrt(n)) (by L'Hospital)
= lim {n->inf} 2*sqrt(n)/n
= lim {n->inf} 2/sqrt(n)
= 0 < inf参考符号表示法对O(.)的替代定义,因此从上面我们可以说log n = O(sqrt(n)),
另外,比较下面函数的增长,对于所有的log n,log n总是以sqrt(n)为上限。

发布于 2019-11-17 11:31:54
只需比较这两种功能:
sqrt(n) ---------- log(n)
n^(1/2) ---------- log(n)
Plug in Log
log( n^(1/2) ) --- log( log(n) )
(1/2) log(n) ----- log( log(n) )很明显:const .log(n) > log(log(n))
发布于 2017-02-04 09:15:15
不,不是等价物。
@trincot在他的回答中给出了一个很好的解释和例子。我要再加一点。你的教授教你
any operation that halves the length of the input has an O(log(n)) complexity也是真的,
any operation that reduces the length of the input by 2/3rd, has a O(log3(n)) complexity
any operation that reduces the length of the input by 3/4th, has a O(log4(n)) complexity
any operation that reduces the length of the input by 4/5th, has a O(log5(n)) complexity
So on ...即使是(B-1)/Bth.对输入长度的所有缩减,它的复杂性都是O(logB(n))
N:B: O(logB(n))是指基于B的n对数。
https://stackoverflow.com/questions/42038294
复制相似问题