0

Our teacher gave us the following definition of Big O notation:

O(f(n)): A function g(n) is in O(f(n)) (“big O of f(n)”) if there exist constants c > 0 and N such that |g(n)| ≤ c |f(n)| for all n > N. I'm trying to tease apart the various components of this definition. First of all, I'm confused by what it means for g(n) to be in O(f(n)). What does in mean?

Next, I'm confused by the overall second portion of the statement. Why does saying that the absolute value of g(n) less than or equal f(n) for all n > N mean anything about Big O Notation?

My general intuition for what Big O Notation means is that it is a way to describe the runtime of an algorithm. For example, if bubble sort runs in O(n^2) in the worst case, this means that it takes the time of n^2 operations (in this case comparisons) to complete the algorithm. I don't see how this intuition follows from the above definition.

blah
  • 1

1 Answers1

1

O(f(n)) means the family of function of f(n), a family of function for example could be {n^2, 3*n^2, 6*n^2, ...k*n^2}, for g(n) to be in the O(f(n)), it means that g(n) is less than all elements of f(n) in the long run. In the above example, it could be g(n) = n, versus O(f(n)) = O(n^2), obviously, n^2 is bigger than n for all n in the long run.

Absolute value sign compares the absolute values of these two functions so that even if g(n) is negative, we can compare which negative grows faster i.e. -n^2 grows faster than -n is equivalent to n^2 grows faster than n

n>N means in the long run

Bubble sort runs O(n^2) in the worst case means that Bubble sort can run much faster than O(n^2), but it does not exceed O(n^2). For example, we want to sort two elements {2,1} using bubble sort, obviously this takes 1 operation and that's it, 1 is smaller than n^2.

Olórin
  • 859
  • 2
  • 12
  • 22