0

While I was studying time complexity, I found a web page explaining about Big O notation.

While I was reading I found the example they used and it got me confused.

In the example they said something like

2n^{2} = O(n^{3}) because for all n bigger than 2(n_{0}), there exists a c(which is 1) that satisfies 0 <= 2n^{2} <= cn^{3}

First I thought the Big O should be O(n^2). But after reading through few more texts I can see that n^2 is smaller than n^3 so can theoretically say that the big O is O(n^3). But is O(n^2) wrong for the example above?

smci
  • 32,567
  • 20
  • 113
  • 146
Andy Min
  • 91
  • 1
  • 6

1 Answers1

1

You're absolutely correct (though you should write out the proof for O(n^2) to convince yourself). Technically the example as written is not wrong, but it's also not a good example. You can think of O(g) as meaning that the function grows as slowly or slower than g. So if a function is O(n^2) it is also O(n^3). There are other variations on Big-O notation (Theta and Omega) which make stronger statements about the asymptotic behavior.

This thread had some nice information even though the focus of the question is slightly different Difference between Big-O and Little-O Notation.

Victor Chubukov
  • 1,345
  • 1
  • 10
  • 18