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

Create successful ePaper yourself

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

The authors jest.<br />

7.5 CONVOLUTIONS 343<br />

Example 4: A convoluted recurrence.<br />

Our next example is especially important; in fact, it’s the “classic example”<br />

of why generating functions are useful in the solution of recurrences.<br />

Suppose we have n + 1 variables x0, x1, . . . , x, whose product is to be<br />

computed by doing n multiplications. How many ways C, are there to insert<br />

parentheses into the product xc ‘x1 . . . :x, so that the order of multiplication is<br />

completely specified? For example, when n = 2 there are two ways, xc. (xl .x2 )<br />

and (x0.x, ) . x2. And when n = 3 there are five ways,<br />

Thus Cl = 2, C3 = 5; we also have Cl = 1 and CO = 1.<br />

Let’s use the four-step procedure of Section 7.3. What is a recurrence<br />

<strong>for</strong> the C’s? The key observation is that there’s exactly one ‘ . ’ operation<br />

outside all of the parentheses, when n > 0; this is the final multiplication<br />

that ties everything together. If this ’ . ’ occurs between Xk and xk+l , there<br />

are Ck ways to full,y parenthesize xc.. . . . Xk, and there are C,- k 1 ways to<br />

fully parenthesize Xk+l . . . . x,; hence<br />

c, = CoC,-l+C,C,~2+~~'+C,~,C~,<br />

ifn>O.<br />

By now we recognize this expression as a convolution, and we know how to<br />

patch the <strong>for</strong>mula so that it holds <strong>for</strong> all integers n:<br />

cn = xCkCn-l-k + [n=o]. (7.65)<br />

k<br />

Step 1 is now complete. Step 2 tells us to multiply by Z” and sum:<br />

C(z) = t c,zn<br />

n<br />

= x ckcn-, -kZn + t Zn<br />

k.n<br />

n=O<br />

= x ckZkx cn-,-kZn-k + 1<br />

k n<br />

= c(z)~zc(z)+ 1.<br />

Lo and behold, the convolution has become a product, in the generatingfunction<br />

world. Life is full of surprises.

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

Saved successfully!

Ooh no, something went wrong!