What is the difference or separates O(log(n)) and O(n)?
This question already has an answer here:
Lets assume n = 1000
.
How many iteration it'll take until i = 0
?
Each time you divide it by 2. So we'll get the following table:
Iteration | i
----------|--------
0 | 1000
1 | 500
2 | 250
... | ...
... | ...
10 | 0 <-- Here we stop
Does this help you to figure out the complexity? (It should - Hint: What is ~log(1000) and what does O(n) mean?)
链接地址: http://www.djcxy.com/p/40022.html上一篇: 为什么时间复杂度为O(log n)?