O(log N) == O(1) - Why not?

后端 未结 23 2022
广开言路
广开言路 2020-12-22 18:17

Whenever I consider algorithms/data structures I tend to replace the log(N) parts by constants. Oh, I know log(N) diverges - but does it matter in real world applications?

23条回答
  •  萌比男神i
    2020-12-22 18:56

    The rules of determining the Big-O notation are simpler when you don't decide that O(log n) = O(1).

    As krzysio said, you may accumulate O(log n)s and then they would make a very noticeable difference. Imagine you do a binary search: O(log n) comparisons, and then imagine that each comparison's complexity O(log n). If you neglect both you get O(1) instead of O(log2n). Similarly you may somehow arrive at O(log10n) and then you'll notice a big difference for not too large "n"s.

提交回复
热议问题