12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

486 Chap. 14 <strong>Analysis</strong> Techniquesthe summation is a fac<strong>to</strong>r of r, we can shift terms if we multiply the entireexpression by r:n∑rF (n) = r ar i = ar + ar 2 + ar 3 + · · · + ar n+1 .i=0We can now subtract the one equation from the other, as follows:F (n) − rF (n) = a + ar + ar 2 + ar 3 + · · · + ar n− (ar + ar 2 + ar 3 + · · · + ar n ) − ar n+1 .The result leaves only the end terms:F (n) − rF (n) =n∑n∑ar i − r ar i .i=0 i=0(1 − r)F (n) = a − ar n+1 .Thus, we get the resultwhere r ≠ 1.F (n) = a − arn+11 − rExample 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 summationof 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 summation, substituting (i + 1) for i:i=1

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

Saved successfully!

Ooh no, something went wrong!