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

Example: Fibonacci



Fibonacci(n)
$\;\;\;\;\;$if n < 2
$\;\;\;\;\;$then return n
$\;\;\;\;\;$else return Fibonacci(n-1) + Fibonacci(n-2)



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



Copyright © 1998 The University of Texas at Arlington