Is there a way to tell whether a subroutine has runtime log(n)?
This question already has an answer here:
When in each iteration we reduce the problem size be a factor of X , we can say that the problem is O(log n)
Eg - Binary Search: in each iteration we reduce the problem size by factor of 2
You can take as first example binary search. A explanation of the complexity of this algorithm can be taken from a related question how to calculate binary search complexity. It shown that the calculation of this type of complexity can be obtain from the recurrence.
链接地址: http://www.djcxy.com/p/40026.html上一篇: 如何计算二进制搜索的复杂性