Are there any cases where you would prefer a higher big-O time complexity algorithm over the lower one?

后端 未结 22 1497
说谎
说谎 2020-11-28 01:06

Are there are any cases where you would prefer O(log n) time complexity to O(1) time complexity? Or O(n) to O(log n)?

22条回答
  •  -上瘾入骨i
    2020-11-28 01:34

    There is always the hidden constant, which can be lower on the O(log n) algorithm. So it can work faster in practice for real-life data.

    There are also space concerns (e.g. running on a toaster).

    There's also developer time concern - O(log n) may be 1000× easier to implement and verify.

提交回复
热议问题