1

Some standard books on Algorithms produce this:

0 ≤ f(n) ≤ c⋅g(n) for all n > n0

While defining big-O, can anyone explain to me what this means, using a strong example which can help me to visualize and understand big-O more precisely?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
zukes
  • 381
  • 2
  • 7
  • 16
  • Did you try Googling? E.g. [Wikipedia](http://en.wikipedia.org/wiki/Big_O_notation). – Thomas Jan 09 '13 at 17:47
  • 1
    For a record, you can consider including the complete definition of big Oh in your question "A function f(n) is of order at most g(n) - that is, f(n) = O(g(n)) - if a positive real number c and positive integer N exist such that f(n) <= c g(n) for all n >= N. That is, c g(n) is an upper bound on f(n) when n is sufficiently large." – sr01853 Jan 09 '13 at 17:48
  • This has a nice example in the question itself. http://stackoverflow.com/questions/2754718/big-oh-notation-formal-definition – sr01853 Jan 09 '13 at 18:02

2 Answers2

2

Assume you have a function f(n) and you are trying to classify it - is it a big O of some other function g(n).

The definition basically says that f(n) is in O(g(n)) if there exists two constants C,N such that

f(n) <= c * g(n) for each n > N

Now, let's understand what it means.

Start with the n>N part - it means, we do not "care" for low values of n, we only care for high values, and if some (final number of) low values do not follow the criteria - we can silently ignore them by choosing N bigger then them.

Have a look on the following example:

enter image description here

Though we can see that for low values of n: n^2 < 10nlog(n), the second quickly catches up and after N=10 we get that for all n>10 the claim 10nlog(n) < n^2 is correct, and thus 10nlog(n) is in O(n^2). The constant c means we can also tolerate some multiple by constant factor, and we can still accept it as desired behavior (useful for example to show that 5*n is O(n), because without it we could never find N such that for each n > N: 5n < n, but with the constant c, we can use c=6 and show 5n < 6n and get that 5n is in O(n).

amit
  • 175,853
  • 27
  • 231
  • 333
0

This question is a math problem, not an algorithmic one.

You can find a definition and a good example here: https://math.stackexchange.com/questions/259063/big-o-interpretation

As @Thomas pointed out, Wikipedia also has a good article on this: http://en.wikipedia.org/wiki/Big_O_notation

If you need more details, try to ask a more specific question.

Community
  • 1
  • 1
BenC
  • 8,729
  • 3
  • 49
  • 68