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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

466 Chap. 14 <strong>Analysis</strong> TechniquesExample 14.4 For our second example of the shifting method, we solven∑f(n) = i2 i = 1 · 2 1 + 2 · 2 2 + 3 · 2 3 + · · · + n · 2 n .i=1We can achieve our goal if we multiply by two:n∑2f(n) = 2 i2 i = 1 · 2 2 + 2 · 2 3 + 3 · 2 4 + · · · + (n − 1) · 2 n + n · 2 n+1 .i=1The ith term of 2f(n) is i · 2 i+1 , while the (i + 1)th term of f(n) is(i + 1) · 2 i+1 . Subtracting one expression from the other yields the summ<strong>at</strong>ionof 2 i <strong>and</strong> a few non-canceled terms:n∑ n∑2f(n) − f(n) = 2 i2 i − i2 i=i=1n∑i2 i+1 −i=1i=1n∑i2 i .Shift i’s value in the second summ<strong>at</strong>ion, substituting (i + 1) for i:n−1∑n−1∑= n2 n+1 + i2 i+1 − (i + 1)2 i+1 .Break the second summ<strong>at</strong>ion into two parts:n−1∑n−1∑n−1∑= n2 n+1 + i2 i+1 − i2 i+1 − 2 i+1 .i=0i=0i=1i=0i=0i=0Cancel like terms:n−1∑= n2 n+1 − 2 i+1 .i=0Again shift i’s value in the summ<strong>at</strong>ion, substituting i for (i + 1):n∑= n2 n+1 − 2 i .Replace the new summ<strong>at</strong>ion with a solution th<strong>at</strong> we already know:= n2 n+1 − ( 2 n+1 − 2 ) .i=1Finally, reorganize the equ<strong>at</strong>ion:= (n − 1)2 n+1 + 2.

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

Saved successfully!

Ooh no, something went wrong!