1

Definition: enter image description here

Example:

f(n) = n

g(n) = 0.5n

Notice that when c = 1 and n0 = 1, n >= 1(0.5n) for all n >= n0.

However, the definition states that "there is" a real constant c > 0, not "for all". So in this case, if we choose c = 3 and n0 = 1, n <= 3(0.5n) for all n >= n0 holds, thus, n is O(0.5n)?

If so, what's the semantic meaning of the statement, n is O(0.5n)?
n's behaviour towards infinity is similar to the behaviour of 0.5n?

NoName
  • 9,824
  • 5
  • 32
  • 52
  • Seems like a duplicate of [What is a plain English explanation of “Big O” notation?](https://stackoverflow.com/questions/487258/what-is-a-plain-english-explanation-of-big-o-notation) – Bernhard Barker Sep 16 '17 at 20:38

3 Answers3

1

Yes, and 0.5n is also O(n). For Big-O you can always drop constants (read: ignore the constants), since they do not grow with the input size.

Edit: just saw your edit. The semantic meaning of Big-O isn't that one function "behaves similarly" to another at another at arbitrary input size--it's that one function is upper-bounded by another, within constant factors.

Also see the second answer on this post: What is a plain English explanation of "Big O" notation?

information_interchange
  • 2,538
  • 6
  • 31
  • 49
1

First of all, the definition states "if there is", not "there is" (I'm sure you meant the former but just saying).

And yes, the result you described matches exactly the definition. However, usually we drop constants in Big-Oh notations, as they are useful to give us the "upper bound" of functions. If you choose c = 2, you will get n = O(n). Another example, (3n + 9) is O(n), and (9 log n + n) is O(n) because (9 log n + n) <= 10n with n0 = 1.

Cs_Is_Better
  • 121
  • 9
1

It means that it is upper bounded (and often the intended meaning is 'equal to') that runtime or space complexity, for n>=n0.

It is important to keep in mind that O(n) is a set of functions. As such, the meaning of some function g(n), where n is the input size to the function g, being O(n) is that g(n) is upper bounded by O(n). Informally, but not entirely correctly, we often write g(n) = O(n) or that some algorithm = O(n).

As already pointed out, asymptotic notation like O(n) ignores constants, so O(0.5n) = O(n). Or, more generally, O(cn) = O(n).

Martin Dinov
  • 8,757
  • 3
  • 29
  • 41