9

I can clearly see than N^2 is bounded by c2^N, but how do i prove it by using formal definition of big-O. I can simply prove it by M.I.

Here is my attempt.. By definition, there for any n>n0, there exist a constant C which f(n) <= Cg(n) where f(n) = n^2 and g(n) = 2^n

Should I take log to both side and solve for C?

and one more question about fibonacci sequence, i wanna solve the recurrence relation.

int fib(int n){
   if(n<=1) return n;
   else return fib(n-1) + fib(n-2);

The equation is..

T(n) = T(n-1)+T(n-2)+C // where c is for the adding operation
so
T(n) = T(n-2) + 2T(n-3) + T(n-4) + 3c 

and one more

T(n) = T(n-3) + 3T(n-4) + 3T(n-5) + T(n-6) + 6c

then i started to get lost to form the general equation i The pattern is somehow like pascal triangle?

 t(n) = t(n-i) + aT(n-i-1) + bT(n-i-2) + ... + kT(n-i-i) + C 
Timothy Leung
  • 1,407
  • 7
  • 22
  • 39

3 Answers3

7

As you point out, to see if f(x) ϵ O(g(x)) you need to find...

  • ...some c > 0 and
  • ...some x0

such that f(x) < c·g(x) for all x > x0.

In this case, you can pick c = 1 and x0 = 2. What you need to prove is that

    x2 < 2x for all x > 2

At this point you can log both sides (since if log(x) > log(y), then x > y.) Assuming you're using base-2 log you get the following

    log(x2) < log(2x)

and by standard laws of logarithms, you get

    2·log(x) < x·log(2)

Since log(2) = 1 this can be written as

    2·log(x) < x

If we set x = 2, we get

    2·log(2) = 2

and since x grows faster than log(x) we know that 2·log(x) < x holds for all x > 2.

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • 1
    Because for *x* = 2 we have 2 * log(2) = 2 ≤ 2 and log(x) grows faster than *x*. – aioobe Aug 31 '13 at 18:56
  • But "log(x) grows faster than x" is the statement we want to prove right? We wanted to prove "2^N grows faster than N^2". – Boyang Sep 01 '13 at 14:19
  • (First of all, sorry that should have been "x grows faster than log(x)" in my last comment.) Anyway, I think you can take that fact for granted. – aioobe Sep 01 '13 at 18:02
2

For the most part, the accepted answer (from aioobe) is correct, but there is an important correction that needs to be made.

Yes, for x=2, 2×log(x) = x or 2×log(2) = 2 is correct, but then he incorrectly implies that 2×log(x) < x is true for ALL x>2, which is not true.

Let's take x=3, so the equation becomes: 2×log(3) < 3 (an invalid equation).

If you calculate this, you get: 2×log(3) ≈ 3,16993 which is greater than 3.

You can clearly see this if you plot f(x) = x2 and g(x) = 2x or if you plot f(x)= 2×log(x) and g(x) = x (if c=1).

f(x)=x2 and g(x) =2n plotted

Between x=2 and x=4, you can see that g(x) will dip below f(x). It is only when x 4, that f(x) will remain c×g(x).

So to get the correct answer, you follow the steps described in aioobe's answer, but you plot the functions to get the last intersection where f(x) = c×g(x). The x at that intersection is your x0 (together with the choosen c) for which the following is true: f(x) c×g(x) for all x x0.

So for c=1 it should be: for all x≥4, or x0=4

Fishezzz
  • 113
  • 1
  • 6
0

To improve upon the accepted answer:

You have to prove that x^2 < 2^x for all x > 2

Taking log on both sides, we have to prove that: 2·log(x) < x for all x > 2

Thus we have to show the function h(x)=x-2·log(x)>0 for all x>2

h(2)=0

Differentiating h(x) with respect to x, we get h'(x)= 1 - 1/(x·ln(2))

For all x>2, h'(x) is always greater than 0, thus h(x) keeps increasing and since h(2)=0, it is hence proved that h(x) > 0 for all x > 2, or x^2 < 2^x for all x > 2

naman
  • 35
  • 4