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.

464 Chap. 14 <strong>Analysis</strong> TechniquesDividing by both n <strong>and</strong> f(n − 1) happen to give us useful p<strong>at</strong>terns tof(n)work with.n= n+1 f(n)2, <strong>and</strong>f(n−1)= n+1n−1. Of course, lots of otherguesses for function g do not work. For example, f(n) − n = f(n −1). Knowing th<strong>at</strong> f(n) = f(n − 1) + n is not useful for determining theclosed form solution to this summ<strong>at</strong>ion. Or consider f(n) − f(n − 1) = n.Again, knowing th<strong>at</strong> f(n) = f(n − 1) + n is not useful. Finding the rightcombin<strong>at</strong>ion of equ<strong>at</strong>ions can be like finding a needle in a haystack.In our first example, we can see directly wh<strong>at</strong> the closed-form solutionshould be. Since f(n)n = n+12, obviously f(n) = n(n + 1)/2.Dividing f(n) by f(n − 1) does not give so obvious a result, but itprovides another useful illustr<strong>at</strong>ion.f(n)f(n − 1)= n + 1n − 1f(n)(n − 1) = (n + 1)f(n − 1)f(n)(n − 1) = (n + 1)(f(n) − n)nf(n) − f(n) = nf(n) + f(n) − n 2 − n2f(n) = n 2 + n = n(n + 1)f(n) =n(n + 1)2Once again, we still do not have a proof th<strong>at</strong> f(n) = n(n+1)/2. Why?Because we did not prove th<strong>at</strong> f(n)/n = (n + 1)/2 nor th<strong>at</strong> f(n)/f(n −1) = (n + 1)(n − 1). We merely hypothesized p<strong>at</strong>terns from looking <strong>at</strong> afew terms. Fortun<strong>at</strong>ely, it is easy to check our hypothesis with induction.Example 14.2 Solve the summ<strong>at</strong>ionn∑1/2 i .i=1We will begin by writing out a table listing the first few values of the summ<strong>at</strong>ion,to see if we can detect a p<strong>at</strong>tern.n 1 2 3 4 5 61f(n)211 − f(n)234147818151611631321326364164

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

Saved successfully!

Ooh no, something went wrong!