0

According to the book "Introduction to Algorithms" a function that has the following form
$f(n)=an+b$
belong to $O(n^2)$ , and that this can be easily proven if we set
$c = a +|b|$
But I don't get it, it still seems to belong to $O(n)$.

QxFFu
  • 45
  • 1
  • 1
  • 4

2 Answers2

0

To be strict: $\forall n>N \ an +b <an^2 +b n^2 = (a+b)n^2 = O(n^2)$ hence the result, a very loose one of course.

Alex
  • 19,262
0

Everything in $O(n)$ is also $O(n^2)$. Recall that a function f(n) is O(n) if $f(n) \leq cn$ for sufficiently large $n$ and some constant $c>0$. Well, if $f(n) \leq cn$, then it's also the case that $f(n) \leq c n^2$ for all appropriately large $n$, so f(n) is $O(n^2)$ as well.