next up previous
Next: Summations Up: CSE 2320: Algorithms and Previous: Factorials

Example: Generate and Test Sorting

GTSort(A)
   B = A
   while not ordered(B)
      B = permute(A)



How many permutations?

Worst case analysis


\begin{eqnarray*}T(n) & = & \Theta(n * n!) \\
\lg T(n) & = & \Theta(\lg (n * n!...
...n + \lg n!) \\
& = & \Theta(\lg n!) \\
& = & \Theta(n \lg n)
\end{eqnarray*}




Insertion Sort (worst case): $\lg T(n) = \Theta(\lg n^2) = \Theta(2 \lg n)
= \Theta(\lg n)$

Merge Sort (worst case): $\lg T(n) = \Theta(\lg (n \lg n))$



Copyright © 1998 The University of Texas at Arlington