11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 14.2 Recurrence Rel<strong>at</strong>ions 475This form is known as a recurrence with full history. The key to solving such arecurrence is to cancel out the summ<strong>at</strong>ion terms. The shifting method for summ<strong>at</strong>ionsprovides a way to do this. Multiply both sides by n <strong>and</strong> subtract the resultfrom the formula for nT(n + 1):n−1∑nT(n) = cn 2 + 2 T(k)k=1(n + 1)T(n + 1) = c(n + 1) 2 + 2Subtracting nT(n) from both sides yields:n∑T(k).k=1(n + 1)T(n + 1) − nT(n) = c(n + 1) 2 − cn 2 + 2T(n)(n + 1)T(n + 1) − nT(n) = c(2n + 1) + 2T(n)(n + 1)T(n + 1) = c(2n + 1) + (n + 2)T(n)T(n + 1) =c(2n + 1)n + 1+ n + 2n + 1 T(n).At this point, we have elimin<strong>at</strong>ed the summ<strong>at</strong>ion <strong>and</strong> can now use our normal methodsfor solving recurrences to get a closed-form solution. Note th<strong>at</strong> c(2n+1)n+1< 2c,so we can simplify the result. Exp<strong>and</strong>ing the recurrence, we getT(n + 1) ≤ 2c + n + 2n + 1 T(n)= 2c + n + 2n + 1(2c + n + 1)n T(n − 1) (2c +n= 2c + n + 2 (2c + n + 1))n + 1 n n − 1 T(n − 2)= 2c + n + 2 (2c + · · · + 4 n + 13 (2c + 3 )2 T(1)) (= 2c 1 + n + 2n + 1 + n + 2 n + 1n + 1 n + · · · + n + 2n + 1( ( 1= 2c 1 + (n + 2)n + 1 + 1 n + · · · + 1 ))2= 2c + 2c(n + 2) (H n+1 − 1)n + 1n · · · 3 )2for H n+1 , the Harmonic Series. From Equ<strong>at</strong>ion 2.10, H n+1 = Θ(log n), so thefinal solution is Θ(n log n).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!