What does O(log n) mean exactly?

后端 未结 30 2431
执念已碎
执念已碎 2020-11-22 01:19

I am learning about Big O Notation running times and amortized times. I understand the notion of O(n) linear time, meaning that the size of the input affects the g

30条回答
  •  太阳男子
    2020-11-22 02:04

    Divide and conquer algorithms usually have a logn component to the running time. This comes from the repeated halving of the input.

    In the case of binary search, every iteration you throw away half of the input. It should be noted that in Big-O notation, log is log base 2.

    Edit: As noted, the log base doesn't matter, but when deriving the Big-O performance of an algorithm, the log factor will come from halving, hence why I think of it as base 2.

提交回复
热议问题