0

I am coming across two slightly different definitions of big-oh and need to prove that they are equivalent to each other:

Definition 1: f(n) = O(g(n)) if there exists constants c and N such that f(n) ≤ c g(n) for all n > N.

Definition 2: f(n) = O(g(n)) if there exists a constant c such f(n) ≤ c g(n) for all n≥1.

Intuitively I know that if we choose c large enough we can get rid of N like in definition 2. But how to prove that if definition 1 implies definition 2, and vice versa.

aky
  • 83
  • 8

2 Answers2

3

They aren't actually equivalent, and (1) is the correct definition.

An example of the difference is that under (1), n = O(n log(n)) but under definition (2) it can't be because at n=1 because for any c, c g(n) = c*1*log(1) = 0 < 1.

The reason why (1) is the correct definition is because the purpose of big-O is to capture behavior "near infinity", and so a finite number of special cases for small n should be ignored.

The reason why you'll see (2) show up is because it is sufficient to establish big-O. It just isn't necessary.

btilly
  • 43,296
  • 3
  • 59
  • 88
  • 1
    OK. But let's also mention that the equivalence holds if `g(n)>0` for all values of `n`. In fact, it would be enough to chose `c'=max(f(1)/g(1), ..., f(N)/g(N), c)`. – Leandro Caniglia Aug 29 '18 at 01:03
1

Let me explain better my comment to @btilly's answer.

When g(n)>0 for all values of n, both definitions are in fact equivalent. Here is why:

Firstly, it is always true that when Definition 2 holds, Definition 1 also holds. In fact, we can choose N=0 in this case.

Assume now that Definition 1 is satisfied for some constant c and some number N. If N=0, we have Definition 2. If N>0, consider the following quantity:

c1 := max{f(1)/g(1), ..., f(N)/g(N)}

the quotients make sense because we are in the case where g(n) is always positive. Besides, since

f(n)/g(n) <= c1        (1<=n<=N)

we get

f(n) <= c1*g(n)        (1<=n<=N)

and since f(n) <= c*g(n) for n>N, it happens that

f(n) <= max(c1,c)*g(n)     for all n

as Definition 2 requires.

Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51