next up previous
Next: Best Case Up: l3 Previous: Partition

Worst Case

Partition always yields subarrays of size n-1 and 1.

T(n) = T(n-1) + $\Theta(n)$

\begin{displaymath}=\; T(n-2) \;+\; \Theta(n-1) \;+\; \Theta(n), \;\;\;\; T(1) \;=\; \Theta(1)\end{displaymath}


\begin{displaymath}=\; T(n-3) \;+\; \Theta(n-2) \;+\; \Theta(n-1) \;+\; \Theta(n)\end{displaymath}

The ith term is T(n-i) and the boundary case is i=n-1. The summation is

\begin{displaymath}=\; \sum_{k=1}^n \Theta(k)\end{displaymath}

We know that \(\sum_{k=1}^n \Theta(f(k)) \;=\; \Theta(\sum_{k=1}^n f(k))\). Thus summation is then \(=\; \Theta(\sum_{k=1}^n k) \;=\; \Theta(n^2)\).

Note that Insertion Sort is O(n) in this same case (already sorted).


next up previous
Next: Best Case Up: l3 Previous: Partition