next up previous
Next: Example: Use both methods Up: CSE 2320: Algorithms and Previous: Example - Wrong Way

Example - Right Way

T(n) = $\Theta(n)$ + T(n/3)
=
$\Theta(n)$ + [ $\Theta(n/3)$ + T(n/32)]
=
$\Theta(n)$ + $\Theta(n/3)$ + T(n/32)
=
$\Theta(n)$ + $\Theta(n/3)$ + $\Theta(n/3^2)$ + T(n/33)
=
\(\sum_{i=0}^{log_3 n-1} \; \Theta(n/3^i)\) + T(1)
=
\(\Theta(n \sum_{i=0}^{log_3 n-1} \; (1/3)^i)\) + T(1)
=
\(\Theta(n (\frac{(1/3)^{log_3 n} - 1}{1/3 - 1}))\) + T(1)
=
\(\Theta(3/2n(1 - 1/n))\) + T(1)
=
\(\Theta(\frac{3n}{2} - \frac{3n}{n})\) + T(1)
=
\(\Theta(n)\)



Copyright © 1998 The University of Texas at Arlington