What does O(log n) mean exactly?

后端 未结 30 2912
执念已碎
执念已碎 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:00

    You can think of O(log N) intuitively by saying the time is proportional to the number of digits in N.

    If an operation performs constant time work on each digit or bit of an input, the whole operation will take time proportional to the number of digits or bits in the input, not the magnitude of the input; thus, O(log N) rather than O(N).

    If an operation makes a series of constant time decisions each of which halves (reduces by a factor of 3, 4, 5..) the size of the input to be considered, the whole will take time proportional to log base 2 (base 3, base 4, base 5...) of the size N of the input, rather than being O(N).

    And so on.

提交回复
热议问题