next up previous
Next: Solution Techniques Up: CSE 2320: Algorithms and Previous: Changing Variables

Example: Factorial

Factorial(n)
$\;\;\;\;\;$if n < 1
$\;\;\;\;\;$then return 1
$\;\;\;\;\;$else return n * Factorial(n-1)



T(n) = \( \left\{ \begin{array}{ll}
\Theta(1) & {\rm if} \; n = 0 \\
T(n-1) \; + \; \Theta(1) & {\rm if} \; n > 0
\end{array} \right. \)



Copyright © 1998 The University of Texas at Arlington