Why do we ignore co-efficients in Big O notation?

后端 未结 7 897
孤城傲影
孤城傲影 2020-11-29 08:37

While searching for answers relating to \"Big O\" notation, I have seen many SO answers such as this, this, or this, but still I have not clearly understood some points.

7条回答
  •  有刺的猬
    2020-11-29 09:06

    Big O notation is not an absolute measure of complexity.

    Rather it is a designation of how complexity will change as the variable changes. In other words as N increases the complexity will increase Big O(f(N)).

    To explain why terms are not included we look at how fast the terms increase.

    So, Big O(2n+2) has two terms 2n and 2. Looking at the rate of increase Big O(2) this term will never increase it does not contribute to the rate of increase at all so it goes away. Also since 2n increases faster than 2, the 2 turns into noise as n gets very large.

    Similarly Big O(2n^3 + 99n^2) compares Big O(2n^3) and Big O(99n^2). For small values, say n < 50, the 99n^2 will contribute a larger nominal percentage than 2n^3. However if n gets very large, say 1000000, then 99n^2 although nominally large it is insignificant (close to 1 millionth) compared to the size of 2n^3.

    As a consequence Big O(n^i) < Big O(n^(i+1)).

    Coefficients are removed because of the mathematical definition of Big O.

    To simplify the definition says Big O(f(n)) = Big O(f(cn)) for a constant c. This needs to be taken on faith because the reason for this is purely mathematical, and as such the proof would be too complex and dry to explain in simple terms.

提交回复
热议问题