Linear complexity and quadratic complexity

I'm just not sure ...

If you have code that can be executed in any of the following difficulties:

  • The sequence O (n), such as, for example, two O (n) in the sequence
  • O (n & sup2;)

The preferred version will be one that can be executed in linear time. Would it be time that the sequence O (n) would be too large and that O (n & sup2;) would be preferable? In other words, the statement C x O (n) O (n & sup2;) is always true for any constant C?

Why or why not? What are the factors that would influence the condition, so it would be better to choose the complexity O (n & sup2;)?

+3
source share
4

, ; -, , , .

  • big O n → , O, O (n) O (n ^ 2) - .

  • , - , n, , c * n > n ^ 2, .. c > n, , , O

+9

C n, O (n²) .

+2

O , , , n, O (n ^ 2) O (n). , O (n) , O (n ^ 2).

+1

C x O (n) O (n²) , n, .

C n , C x O (n) > O (n²). C , , n , C x O (n) O (N²).

, n , O (n) O (n²).

0

Source: https://habr.com/ru/post/1744117/


All Articles