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

后端 未结 22 1574
说谎
说谎 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条回答
  •  孤街浪徒
    2020-11-28 01:47

    To put my 2 cents in:

    Sometimes a worse complexity algorithm is selected in place of a better one, when the algorithm runs on a certain hardware environment. Suppose our O(1) algorithm non-sequentially accesses every element of a very big, fixed-size array to solve our problem. Then put that array on a mechanical hard drive, or a magnetic tape.

    In that case, the O(logn) algorithm (suppose it accesses disk sequentially), becomes more favourable.

提交回复
热议问题