I was able to solve this relation as described here Solving the recurrence relation $T(n)=T(n-1)+cn$
By the way, my exercises asks also to demostrate by "substitution" and "induction" why the result shall be $T(n) = O(n^2)$
This is what I tried:
$Goal$ We shall demostrate that T(n)<=$O(n^2)$
Where
- T(1) = c' if n=1 (c' is a constant greater than zero)
- T(n) = T(n-1) + cn if n>1 (c is a constant greater than zero)
Thesis: Exists some d>0 such as $T(n) <= dn^2$. d is a positive constant.
Base case (with n=1)
$T(1) = c' <= d(1^2)$ Hence true dor any d>=c'.
Induction hypotesis: the thesis is still true for any m<n.
| Equation | Applied hypotesis | Our constraint |
|---|---|---|
| $T(n) = T(n-1) + cn $ | $<= d(n-1)^2+cn$ $= dn^2-2dn-d+cn$ | <= dn^2 |
Now, solving the equation
$dn^2-2dn-d+cn <= dn^2 $
$-2dn-d+cn <= 0 $
$cn <= 2dn+d $
Then I stuck, I cannot demostrate for d because n is still there, normally I will get some kind of semplification where can I get something like true for all c greater than ...
What am I doing wrong?
\leq($\leq$) orleqslant($\leqslant$) instead of $<=$. (leqstands for lesser than or equal to. Same thing with\geqand\geqslantwill produce the greater than or equal sign) – Didier Jan 15 '23 at 18:10d shall be an arbitrary constants, that shall exists and be greter than zero, to demostrate that the algorithm can be in the order of $n^2$. In trying then to replace the original equation with my $dn^2$. Is now more understandable?
– Delayer Jan 22 '23 at 17:04