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

后端 未结 23 2139
广开言路
广开言路 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条回答
  •  清歌不尽
    2020-12-22 18:58

    Equality, the way you're describing it, is a common abuse of notation.

    To clarify: we usually write f(x) = O(logN) to imply "f(x) is O(logN)".

    At any rate, O(1) means a constant number of steps/time (as an upper bound) to perform an action regardless of how large the input set is. But for O(logN), number of steps/time still grows as a function of the input size (the logarithm of it), it just grows very slowly. For most real world applications you may be safe in assuming that this number of steps will not exceed 100, however I'd bet there are multiple examples of datasets large enough to mark your statement both dangerous and void (packet traces, environmental measurements, and many more).

提交回复
热议问题