The purpose of the Big-O notation is to find what is the dominant factor in the asymptotic behavior of a function as the value tends towards the infinity.
As we walk through the function domain, some factors become more important than others.
Imagine f(n) = n^3+n^2
. As n
goes to infinity, n^2
becomes less and less relevant when compared with n^3
.
But that's just the intuition behind the definition. In practice we ignore some portions of the function because of the formal definition:
f(x) = O(g(x))
as x->infinity
if and only if there is a positive real M
and a real x_0
such as
|f(x)| <= M|g(x)|
for all x > x_0
.
That's in wikipedia. What that actually means is that there is a point (after x_0
) after which some multiple of g(x)
dominates f(x)
. That definition acts like a loose upper bound on the value of f(x)
.
From that we can derive many other properties, like f(x)+K = O(f(x))
, f(x^n+x^n-1)=O(x^n)
, etc. It's just a matter of using the definition to prove those.
In special, the intuition behind removing the coefficient (K*f(x) = O(f(x))
) lies in what we try to measure with computational complexity. Ultimately it's all about time (or any resource, actually). But it's hard to know how much time each operation take. One algorithm may perform 2n
operations and the other n
, but the latter may have a large constant time associated with it. So, for this purpose, isn't easy to reason about the difference between n
and 2n
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…