This is a review question and the teachers gave us the answer as $n^2$. Can someone explain why it is $n^2$?
Thank you
This is a review question and the teachers gave us the answer as $n^2$. Can someone explain why it is $n^2$?
Thank you
It is a sum of $n$ terms, each bounded by $4 n$, so bounded by $n \cdot 4 n = O(n^2)$.
(Yes, this is much less detailed than the other answers; but it also has the virtue that it doesn't require to get anywhere near the precise sum.)
If $$g(n)=0+1+2+\cdots +n= \dfrac{n(n+1)}{2}$$ then $$f(n)=3g(n)+ (n+1) = \dfrac{(3n+2)(n+1)}{2}$$ which is $O(n^2)$.
$$ s_n=1+4+7+\cdots+(3n+1)=\frac{3n^2+5n+2}{2}={\mathcal O}(n^2), $$ since $$ \frac{s_n}{n^2} $$ is bounded, and in particular, $$ \frac{3}{2}\le \frac{s_n}{n^2}\le 5. $$