complexity proof with big-o

60 Views Asked by At

how can I prove that $f(n) = \frac{n^2 + n}{2} \in O(n^3)$ ?

I did it like this:

for $n \ge 1$, it holds that:

$\frac{n^2 + n}{2} \le n^2 + n \le n^2 + n^2 \le 2n^2 \le (2n^2)\times n = 2n^3$

$2n^3 < cn^3$ for any $c > 2$

but I'm not sure if this is enough, since I'm just ignoring the existence of some $n_0$ such that the inequality holds for any $n > n_0$.

Did I make any mistake? If the way I did is right, how can I find $n_0$ ?

If it isn't, how can I do?

1

There are 1 best solutions below

0
On BEST ANSWER

Once you have shown that $\dfrac{n^2+n}{2} \le 2n^3 $, you are done.

All you need to do is to show that there is a $c > 0$ and $n_0 > 0$ such that $\dfrac{n^2+n}{2} \le cn^3 $ for $n \ge n_0$. You have shown this for $c = 2$ and $n_0 = 1$, and this is enough.