next up previous
Next: Example - Wrong Way Up: CSE 2320: Algorithms and Previous: Example: Factorial

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)



Copyright © 1998 The University of Texas at Arlington