06.03.2017 Views

Mathematics for Computer Science

e9ck2Ar

e9ck2Ar

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

“mcs” — 2017/3/3 — 11:21 — page 682 — #690<br />

682<br />

Chapter 16<br />

Generating Functions<br />

16.2.6 An Absurd Counting Problem<br />

So far everything we’ve done with generating functions we could have done another<br />

way. But here is an absurd counting problem—really over the top! In how many<br />

ways can we fill a bag with n fruits subject to the following constraints?<br />

The number of apples must be even.<br />

The number of bananas must be a multiple of 5.<br />

There can be at most four oranges.<br />

There can be at most one pear.<br />

For example, there are 7 ways to <strong>for</strong>m a bag with 6 fruits:<br />

Apples 6 4 4 2 2 0 0<br />

Bananas 0 0 0 0 0 5 5<br />

Oranges 0 2 1 4 3 1 0<br />

Pears 0 0 1 0 1 0 1<br />

These constraints are so complicated that getting a nice answer may seem impossible.<br />

But let’s see what generating functions reveal.<br />

First, we’ll construct a generating function <strong>for</strong> choosing apples. We can choose a<br />

set of 0 apples in one way, a set of 1 apple in zero ways (since the number of apples<br />

must be even), a set of 2 apples in one way, a set of 3 apples in zero ways, and so<br />

<strong>for</strong>th. So, we have:<br />

A.x/ D 1 C x 2 C x 4 C x 6 C D 1<br />

1 x 2<br />

Similarly, the generating function <strong>for</strong> choosing bananas is:<br />

B.x/ D 1 C x 5 C x 10 C x 15 C D 1<br />

1 x 5<br />

Now, we can choose a set of 0 oranges in one way, a set of 1 orange in one way,<br />

and so on. However, we cannot choose more than four oranges, so we have the<br />

generating function:<br />

O.x/ D 1 C x C x 2 C x 3 C x 4 D 1 x5<br />

1 x :<br />

Here the right-hand expression is simply the <strong>for</strong>mula (14.2) <strong>for</strong> a finite geometric<br />

sum. Finally, we can choose only zero or one pear, so we have:<br />

P.x/ D 1 C x

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

Saved successfully!

Ooh no, something went wrong!