Probably a stupid question but I don't get it right now. I have an algorithm with an input n. It needs n + (n-1) + (n-2) + ... + 1 steps to finish. Is it possible to give a runtime estimation in Big-O notation?
Asked
Active
Viewed 44 times
2 Answers
3
Indeed, it is. Since we have $$n+(n-1)+(n-2)+\cdots+1=\frac{n(n+1)}2,$$ then you should be able to show rather readily that the runtime will be $\mathcal{O}(n^2)$.
Cameron Buie
- 102,994
1
There are $n$ terms in your series, and each term is of the order $n$ at maximum. Therefore the operation takes on the order of $O(n^2)$ steps.
rgettman
- 764
O(n^2). – David G Sep 08 '14 at 18:52O(n^2)though. – David G Sep 09 '14 at 13:58