09.12.2012 Views

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

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.

7.3 SOLVING RECURRENCES<br />

7.3 SOLVING RECURRENCES 323<br />

Now let’s focus our attention on one of the most important uses of<br />

generating functiorrs: the solution of recurrence relations.<br />

Given a sequence (gn) that satisfies a given recurrence, we seek a closed<br />

<strong>for</strong>m <strong>for</strong> gn in terms of n. A solution to this problem via generating functions<br />

proceeds in four steps that are almost mechanical enough to be programmed<br />

on a <strong>computer</strong>:<br />

1 Write down a single equation that expresses g,, in terms of other elements<br />

of the sequence. This equation should be valid <strong>for</strong> all integers n, assuming<br />

that g-1 = g-2 = ... = 0.<br />

2 Multiply both sides of the equation by zn and sum over all n. This gives,<br />

on the left, the sum x., gnzn, which is the generating function G (2). The<br />

right-hand side should be manipulated so that it becomes some other<br />

expression involving G (2).<br />

3 Solve the resulting equation, getting a closed <strong>for</strong>m <strong>for</strong> G (2).<br />

4 Expand G(z) into a power series and read off the coefficient of zn; this is<br />

a closed <strong>for</strong>m <strong>for</strong> gn.<br />

This method works because the single function G(z) represents the entire<br />

sequence (gn) in such a way that many manipulations are possible.<br />

Example 1: Fibonacci numbers revisited.<br />

For example, let’s rerun the derivation of Fibonacci numbers from Chapter<br />

6. In that chapter we were feeling our way, learning a new method; now<br />

we can be more systematic. The given recurrence is<br />

go = 0; 91 = 1;<br />

gn = %-1+%-z, <strong>for</strong> n 3 2.<br />

We will find a closed <strong>for</strong>m <strong>for</strong> g,, by using the four steps above.<br />

Step 1 tells us to write the recurrence as a “single equation” <strong>for</strong> gn. We<br />

could say<br />

9 n=<br />

0, ifn 1;<br />

but this is cheating. Step 1 really asks <strong>for</strong> a <strong>for</strong>mula that doesn’t involve a<br />

case-by-case construction. The single equation<br />

gn = gn-l+~ln-z<br />

works <strong>for</strong> n > 2, a.nd it also holds when n 6 0 (because we have go = 0<br />

and gnegative = 0). But when n = 1 we get 1 on the left and 0 on the right.

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

Saved successfully!

Ooh no, something went wrong!