What does O(log n) mean exactly?

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

    The complete binary example is O(ln n) because the search looks like this:

    1 2 3 4 5 6 7 8 9 10 11 12
    

    Searching for 4 yields 3 hits: 6, 3 then 4. And log2 12 = 3, which is a good apporximate to how many hits where needed.

提交回复
热议问题