next up previous
Next: Up: Previous:

Worst Case Revisited

Assume we do not know what the worst partition is.

T(n) = \(\max_{1 \leq q \leq n-1}\)(T(q) + T(n-q)) + $\Theta(n)$.



By the substitution method (since we know the answer), try T(n) $\leq$cn2.


\begin{displaymath}T(n) \;\leq\; \max_{1 \leq q \leq n-1} (cq^2 \;+\; c(n-q)^2) \;+\; \Theta(n)\end{displaymath}


\begin{displaymath}=\; c * \max_{1 \leq q \leq n-1} (q^2 \;+\; (n-q)^2) \;+\; \Theta(n)\end{displaymath}



\(\frac{d}{dq} (q^2 \;+\; (n-q)^2)\) = 2q - 2(n-q) = 2q - 2n + 2q = 4q - 2n

\(\frac{d}{dq} (4q - 2n) = 4\).

For q=1: \(1^2 \;+\; (n-1)^2 \;=\; n^2 \;-\; 2n \;+\; 2\).

For q=n-1: \((n-1)^2 \;+\; 1^2 \;=\; n^2 \;-\; 2n \;+\; 2\).



\psfig{figure=figures/f3-7.ps,width=3.5in,height=1.5in}

T(n) $\leq$ cn2 - 2c(n - 1) + $\Theta(n)$$\leq$ cn2. Picking a large enough c,

T(n) = $\Theta(n^2)$


next up previous
Next: Up: Previous: