What does O(log n) mean exactly?

后端 未结 30 2398
执念已碎
执念已碎 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 01:50

    If you had a function that takes:

    1 millisecond to complete if you have 2 elements.
    2 milliseconds to complete if you have 4 elements.
    3 milliseconds to complete if you have 8 elements.
    4 milliseconds to complete if you have 16 elements.
    ...
    n milliseconds to complete if you have 2^n elements.
    

    Then it takes log2(n) time. The Big O notation, loosely speaking, means that the relationship only needs to be true for large n, and that constant factors and smaller terms can be ignored.

提交回复
热议问题