Big-O notation finding c and n0

前端 未结 4 1305
一生所求
一生所求 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 11:22

    If you have f(n) = (3n^3 + 20n^2 + 5) and you want to see if it's O(g(n)) where g(n) = n^3, I believe you can take the limit of f(n)/g(n) as n->infinity.

    Because the limit is 3, you can see that 3n^3 + 20n^2 + 5 only grows as fast as n^3. When you have a polynomial like 3n^3 + 20n^2 + 5, you can tell by inspection that the largest order term will always be the value of O(f(n)).

    It's not a lot of help finding n0 and C, but it's a relatively easy way to determine what the order of something is. As the others have said here, you can just pick n0 and then calculate C.

    If you choose n0 = 1, then you have 3*(1^3) + 20*1^2 + 5 = 28. So if c1^3 <= 28, c must be 28. You've shown there there is a c and n0 that meets this condition, so you've proved f(n) is O(n^3)

提交回复
热议问题