tags:

views:

312

answers:

5

I'm starting to learn about Big-Oh notation.

What is an easy way for finding C and N0 for a given function?

Say, for example:

(n+1)5, or n5+5n4+10n2+5n+1

I know the formal definition for Big-Oh is:

Let f(n) and g(n) be functions mapping nonnegative integers to real numbers. We say that f(n) is O(g(n)) if there is a real constant c > 0 and an integer constant N0 >= 1 such that f(n) <= cg(n) for every integer N > N0.

My question is, what is a good, sure-fire method for picking values for c and N0?

For the given polynomial above (n+1)5, I have to show that it is O(n5). So, how should I pick my c and N0 so that I can make the above definition true without guessing?

+1  A: 

You can check what the lim abs(f(n)/g(n)) is when n->+infitity and that would give you the constant (g(n) is n^5 in your example, f(n) is (n+1)^5).

Note that the meaning of Big-O for x->+infinity is that if f(x) = O(g(x)), then f(x) "grows no faster than g(x)", so you just need to prove that lim abs(f(x)/g(x)) exists and is less than +infinity.

7macaw
+1  A: 

You can pick a constant c by adding the coefficients of each term in your polynomial. Since

| n5 + 5n4 + 0n3 + 10n2 + 5n1 + 1n0 | <= | n5 + 5n5 + 0n5 + 10n5 + 5n5 + 1n5 |

and you can simplify both sides to get

| n5 + 5n4 + 10n2 + 5n + 1 | <= | 22n5 |

So c = 22, and this will always hold true for any n >= 1.

It's almost always possible to find a lower c by raising N0, but this method works, and you can do it in your head.

Edit: I added absolute value operations around the polynomials to account for negative coefficients.

Bill the Lizard
A: 

It's going to depend greatly on the function you are considering. However, for a given class of functions, you may be able to come up with an algorithm.

For instance, polynomials: if you set C to any value greater than the leading coefficient of the polynomial, then you can solve for N0.

James Rose
A: 

Usually the proof is done without picking concrete C and No. Instead of proving f(n) < C * g(n) you prove that f(n) / g(n) < C.

For example, to prove n3 + n is O(n3) you do the following:

(n3 + n) / n3 = 1 + (n / n3) = 1 + (1 / n2) < 2 for any n >= 1. Here you can pick any C >= 2 with No = 1.

Olexiy
A: 

After you understand the magic there, you should also get that big-O is a notation. It means that you do not have to look for these coefficients in every problem you solve, once you made sure you understood what's going on behind these letters. You should just operate the symbols according to the notaion, according to its rules.

There's no easy generic rule to determine actual values of N and c. You should recall your calculus knowledge to solve it.

The definition to big-O is entangled with definition of the limit. It makes c satisfy:

c > lim |f(n)/g(n)|, given n approaches +infinity.

If the sequence is upper-bounded, it always has a limit. If it's not, well, then f is not O(g). After you have picked concrete c, you will have no problem finding appropriate N.

Pavel Shved