0

I was reading an article and came across the following :

Informally, O(g(n)) can be defined as the set of mathematical functions that contains all functions that don’t “grow faster” than g(n). Thus, all functions below are in the set O(n²): f(n) = n²+3n + 2, f(n) = n log(n), f(n) = 3n+1 . Can please anyone tell me how f(n) = n²+3n + 2 grows faster than g(n)?

luk2302
  • 55,258
  • 23
  • 97
  • 137
  • Do you know the definitions, are you familiar with the math behind the O notation? – luk2302 Nov 06 '21 at 15:47
  • 1
    Does this answer your question? [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) – Welbog Nov 06 '21 at 15:48
  • You're asking how n²+3n + 2 grows faster than n². Is that really what you meant to ask? – Kelly Bundy Nov 06 '21 at 15:54

2 Answers2

1

Can please anyone tell me how f(n) = n²+3n + 2 grows faster than g(n)?

Here is one way to understand it (a bit informal, but I find it more intuitive).

Let L be limit as n goes to infinity of f(n)/g(n)

If L is infinity then f(n) grows faster than g(n) (numerator overwhelms denominator).

If L is 0 then f(n) grows slower than g(n) (denominator overwhelms numerator)

If L is finite number then they have same (comparable) growth rates.

Eugene Loy
  • 12,224
  • 8
  • 53
  • 79
0

We can define O(g(n)) as the following set:

O(g(n)) = { f(n) ∶ ∃ c > 0 and n0 > 0 | 0 ≤ f(n) ≤ c ⋅ g(n), ∀n ≥ n0 }

This means O(g(n)) is the set of all functions f(n) which grow slower than g(n) for some constant c and for n ≥ n0. In order to find n0 and c we use a justification like the following:

n²+3n + 2 ≤ n² + 3n² + 2n²
n²+3n + 2 ≤ 6n² for c = 6 and n ≥ 1

Now if you just use g(n) = n² obviously f(n) = n² + 3n + 2 will grow faster than g(n); but by choosing the value of c correctly g(n) will grow faster than f(n) for n ≥ n0.

gst
  • 828
  • 5
  • 15
  • I highly doubt OP understands that. And it does not really answer the question why f(n) grows faster than g(n). – luk2302 Nov 06 '21 at 15:46
  • I think given the description it is obvious why f(n) might grow faster than g(n) for some values of c – gst Nov 06 '21 at 15:54
  • 1
    I agree its obvious - but if it were obvious to OP the question would not have been posted. It should not have been posted but here we are... – luk2302 Nov 06 '21 at 15:55
  • Agree to disagree – gst Nov 06 '21 at 15:57