问题:
I am learning about Big O Notation running times and amortized times. 我正在学习Big O Notation运行时间和摊销时间。 I understand the notion of O(n) linear time, meaning that the size of the input affects the growth of the algorithm proportionally...and the same goes for, for example, quadratic time O(n 2 ) etc..even algorithms, such as permutation generators, with O(n!) times, that grow by factorials. 我理解O(n)线性时间的概念,意味着输入的大小成比例地影响算法的增长...例如,二次时间O(n 2 )等也是如此。即使算法也是如此。 ,例如置换生成器,具有O(n!)倍,通过阶乘生长。
For example, the following function is O(n) because the algorithm grows in proportion to its input n : 例如,以下函数是O(n),因为算法与其输入n成比例增长:
f(int n) {
int i;
for (i = 0; i < n; ++i)
printf("%d", i);
}
Similarly, if there was a nested loop, the time would be O(n 2 ). 同样,如果有嵌套循环,则时间为O(n 2 )。
But what exactly is O(log n) ? 但究竟什么是O(log n) ? For example, what does it mean to say that the height of a complete binary tree is O(log n) ? 例如,说完整二叉树的高度是O(log n)是什么意思?
I do know (maybe not in great detail) what Logarithm is, in the sense that: log 10 100 = 2, but I cannot understand how to identify a function with a logarithmic time. 我知道(可能不是非常详细)什么是对数,在这个意义上:log 10 100 = 2,但我无法理解如何识别具有对数时间的函数。
解决方案:
参考一: https://stackoom.com/question/9gEF/O-log-n-究竟意味着什么参考二: https://oldbug.net/q/9gEF/What-does-O-log-n-mean-exactly
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/3213659