Big-O notation finding c and n0

前端 未结 4 1322
一生所求
一生所求 2021-02-13 10:21

I\'ve just been introduced to Big-O notation and I\'ve been given some questions. However I\'m confused as to how to determine the value of n0. I have to show that

4条回答
  •  一个人的身影
    2021-02-13 10:58

    3n^3 + 20n^2 + 5 <= cn^3
    => 20n^2 + 5 <= cn^3 - 3n^3
    => 20n^2 + 5 <= n^3(c - 3)
    => 20n^2/n^3 + 5/n^3 <= n^3(c - 3)/n^3
    => 20/n + 5/n^3 <= c - 3
    => c >= 20/n + 5/n^3 + 3
    

    Depending on where you want the greater than condition to begin, you can now choose n0 and find the value.

    For example, for n0 = 1:

    c >= 20/1 + 5/1 + 3 which yields c >= 28
    

    It's worth noting that by the definition of Big-O notation, it's not required that the bound actually be this tight. Since this is a simple function, you could just guess-and-check it (for example, pick 100 for c and note that the condition is indeed true asymptotically).

    For example:

    3n^3 + 20n^2 + 5 <= (5 * 10^40) * n^3 for all n >= 1
    

    That inequality holding true is enough to prove that f(n) is O(n^3).


    To offer a better proof, it actually needs to be shown that two constants, c and n0 exist such that f(n) <= cg(n) for all n > n0.

    Using our c = 28, this is very easy to do:

    3n^3 + 20n^2 + 5 <= 28n^3
    20n^2 + 5 <= 28n^3 - 3n^3
    20n^2 + 5 <= 25n^3
    20/n + 5/n^3 <= 25
    
    When n = 1: 20 + 5 <= 25 or 25 <= 25
    For any n > 1, 20/n + 5/n^3 < 25, thus for all n > 1 this holds true.
    
    Thus 3n^3 + 20n^2 + 5 <= 28n^3 is true for all n >= 1
    

    (That's a pretty badly done 'proof' but hopefully the idea shows.)

提交回复
热议问题