0

I have to solve the following $n^2+n \in O(n^2−n)$.

I did it this way: $n^2+n \in O(n^2−n) = n^2 \in O(n^2−n) = n^2 / n^2-n = 2n / 2n-n$ which is infinite.

I don't know if this is correct because the $-n$ in the $O$ notation is confusing me and I haven't found anything about it online. I know if this would be at example -1000 that $n^2+n \in O(n^2−n)$ would be correct.

Could someone explain it to me ?

hengxin
  • 9,671
  • 3
  • 37
  • 75
Mattjo
  • 29
  • 4

1 Answers1

5

$f \in O(g)$ means there's $n_0$ and $c>0$ such that $n>n_0$ implies $f(n) \leq cg(n)$.

Note that for $n>2$, we have $n^2 \geq 3n$.

Then, for $n>2$, we have: $$ \begin{align} 2(n^2 - n) & = n^2 - 2n + n^2 \\ & \geq n^2 - 2n + 3n\\ & = n^2 + n\\ \end{align} $$

Summarizing: for $n>2$, we have $n^2+n \leq 2(n^2-n)$. Thus $n^2+n \in O(n^2-n)$.

ryan
  • 4,533
  • 1
  • 16
  • 41
Paul Hankin
  • 281
  • 2
  • 7