Linear complexity and quadratic complexity

前端 未结 4 1076
攒了一身酷
攒了一身酷 2021-01-14 20:16

I\'m just not sure...

If you have a code that can be executed in either of the following complexities:

  1. A sequence of O(n), like for example: two O(n) i
4条回答
  •  灰色年华
    2021-01-14 20:53

    There is always an implied constant in O notation, so yes, it's possible that for sufficiently small n that O(n^2) may be faster than O(n). This would happen if the constant for O(n) was much smaller than that for O(n^2).

提交回复
热议问题