Linear complexity and quadratic complexity

前端 未结 4 1044
攒了一身酷
攒了一身酷 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 21:08

    C x O(n) < O(n²) is NOT always true, there is a point in n where it reverses the condition.

    When C is large and n is small, then C x O(n) > O(n²). However, C is always constant, hence when n scales to a large number, C x O(n) < O(n²).

    Therefore, when n is large, O(n) is always better than O(n²).

提交回复
热议问题