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

后端 未结 23 2052
广开言路
广开言路 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:49

    For small enough N, O(N^N) can in practice be replaced with 1. Not O(1) (by definition), but for N=2 you can see it as one operation with 4 parts, or a constant-time operation.

    What if all operations take 1hour? The difference between O(log N) and O(1) is then large, even with small N.

    Or if you need to run the algorithm ten million times? Ok, that took 30minutes, so when I run it on a dataset a hundred times as large it should still take 30minutes because O(logN) is "the same" as O(1).... eh...what?

    Your statement that "I understand O(f(N))" is clearly false.

    Real world applications, oh... I don't know.... EVERY USE OF O()-notation EVER?

    Binary search in sorted list of 10 million items for example. It's the very REASON we use hash tables when the data gets big enough. If you think O(logN) is the same as O(1), then why would you EVER use a hash instead of a binary tree?

提交回复
热议问题