algorithmbig-ocomplexity-theoryasymptotic-complexity

What's the upper bound of f(n) = n^4 + 100n^2 + 50?


I'm solving some exercises related to Big-O and I'm stuck on this one:

Exercise - Find upper bound for f(n) = n^4 + 100n^2 + 50

I tried to solve it step by step but something is wrong ...:

1.=> n^4 + 100n^2 + 50 <= O(g(n))
2.=> n^4 + 100n^2 + 50 <= Cn        ** Added -n^4 to both sides
3.=> n^4 + 100n^2 + 50 -n^4 <= Cn -n^4
4.=> 100n^2 + 50 <= Cn - n^4         ** Put n in common
5.=> 100n^2 + 50 <= n(C - n^3)       ** Divided n in the opposite site
6.=> (100n^2 + 50)/n <= C -n^3       ** Assumed 1 for n
7.=> 100 + 50 <= C - 1                      
8.=> 151 <= C

There is something wrong because the answer is c = 2 and n=11. I saw this very same question being asked on stackoverflow but without a step by step solution


Solution

  • It is quite simple to guess that the Upper bound for this function would be O(n^4), because k * n^4 can overpower any multiple of n^3 and other multiples of n lower than 4, after a certain value of n (where k is a multiple).

    Let's take a few sample example:

    1. n^4 < 2*n^4, for all n>1.

    2. n^4 + n^3 < 2*n^4, for all n>2.

    In your case, you need to find the coefficient K which would satisfy your equation, such that n^4 + 100n^2 + 50 <= k * (n^4).

    I'll leave the correct equation to be solved by you, as the one which you've shown is plainly incorrect:

    n^4 + 100n^2 + 50 <= O(g(n))
    n^4 + 100n^2 + 50 <= O(n^4)
    n^4 + 100n^2 + 50 <= k * n^4
    n^4 + 100n^2 + 50 <= n^4 + 100*n^4 + 50*n^4
    n^4 + 100n^2 + 50 <= 151 * (n^4)
    // O(n^4) achieved, for all n >= 1.
    

    You can solve this equation by converting it into a quadratic equation by substituting n^2 by t, and then equation reduces to:

    t^2 + 100t + 50 <= k * t^2
    // left for you to solve this.
    // check for what value of `k` and `t`, this equation gets satisfied.