next up previous
Next: Up: Previous:

Example - Right Way

T(n) = T(n-1) + $\Theta(1)$
=
$\Theta(1)$ + [$\Theta(1)$ + T(n-2)]
=
$\Theta(1)$ + $\Theta(1)$ + [$\Theta(1)$ + T(n-3)]
Terminates when n - i = 0, or i = n.
=
\(\sum_{i=0}^{n-1} \Theta(1) \;+\; T(0)\)
=
\(\Theta(\sum_{i=0}^{n-1} 1)\) + T(0)
=
\(\Theta(n)\) + T(0)


next up previous
Next: Up: Previous: