A generating functions approach to counting

by t0rajir0u, Jan 22, 2008, 1:47 AM

Problem (Balls and Urns): How many ways are there to distribute $ n$ indistinguishable balls among $ r$ distinguishable urns? In other words, how many ordered tuplets $ (x_1, x_2, ... x_r)$ of non-negative integers satisfy

$ x_1 + x_2 + ... + x_r = n$

?

Solution: The answer to this problem is well-known, but the approach that I will take (by generating functions) is in my opinion very instructive.

First, we define the notion of a generating function. Given a sequence $ \{ a_k \}_{k \ge 0}$, we wish to study it by studying the function

$ A(x) = \sum_{k = 0}^{\infty} a_k x^k$.

We will use the notation $ [x^k] F(x)$ to denote the coefficient of $ x^k$ in the series expansion of $ F(x)$. Thus $ [x^k] A(x) = a_k$.

Lemma: If $ A(x), B(x)$ are the generating functions of $ \{ a_k \}, \{ b_k \}$, respectively, then

$ [x^k] A(x) B(x) = \sum_{i + j = k} a_i b_j$.

In other words, multiplying the generating functions of two sequences produces a convolution of their terms. This turns out to be very useful in counting.

Consider the sequence $ c_n$ that gives the number of ways we can put $ n$ balls into a single urn. Since the balls are indistinguishable, there is only one way to do this, so the corresponding generating function is

$ C(x) = \sum_{k = 0}^{\infty} x^k = \frac {1}{1 - x}$.

The sequence we are really interested in gives us the number of ways we can put $ n$ balls into $ r$ urns. As we have stated, this is the number of solutions to $ x_1 + x_2 + ... + x_r = n$. But this is exactly the type of expression that appears in the lemma! In fact, the generating function we are really after is

$ C(x)^r = \sum_{k = 0}^{\infty} \left( \sum_{x_1 + x_2 + ... + x_r = k} 1 \right) x^k = \frac {1}{(1 - x)^r} = (1 - x)^{ - r}$.

But how do we go about finding the coefficients of this function?


The familiar Binomial Theorem $ (x + 1)^n = \sum_{k = 0}^{n} {n \choose k} x^k$ is taught to apply when $ n$ is a non-negative integer. In fact, it applies for non-integer, non-rational, even non-real $ n$; we just need $ {n \choose k}$ to be the Newton polynomial (as per the previous entry) in $ n$.

General Binomial Theorem: For $ \alpha \in \mathbb{C}$, we have

$ (x + 1)^\alpha = \sum_{k = 0}^{\infty} {\alpha \choose k} x^k$.

Proof: We can arrive at this conclusion by the familiar method of finding a Taylor series.

The generating function we were after is $ (1 - x)^{ - r}$. But now that we have the general binomial theorem, we can calculate this as

$ \sum_{k = 0}^{\infty} { - r \choose k} ( - x)^k$.

Now, note that

$ \begin{eqnarray*} { - r \choose k} ( - 1)^k & = & \frac { - r( - r - 1)...( - r - (k - 1))}{k!} ( - 1)^k \\ & = & \frac {r(r + 1)...(r + (k - 1))}{k!} \\ & = & {r + k - 1 \choose r - 1} \\ \end{eqnarray*}$

hence our final generating function can be written

$ \sum_{k = 0}^{\infty} {r + k - 1 \choose r - 1} x^k$.

This tells us that the number of ways to distribute $ n$ balls among $ r$ urns is $ {n + r - 1 \choose r - 1}$. :)


The "balls-and-urns" formula above shows up in a surprising number of combinatorial problems, and both it and the generating functions approach are worth learning. For a more thorough discussion, I highly recommend the online book generatingfunctionology.


Practice Problem 1: Prove Binet's formula using the generating function $ F(x) = \sum_{k = 0}^{\infty} F_k x^k$. (This proof is also in generatingfunctionology, and is in my opinion the most elegant one (although I enjoy the matrix method as well :) ).)

Practice Problem 2: Prove the balls-and-urns formula by a combinatorial argument.

Practice Problem 3 (Putnam 2007 A3): Let $ k$ be a positive integer. Suppose that the integers $ 1,2,3,\dots,3k + 1$ are written down in random order. What is the probability that at no time during this process, the sum of the integers that have been written up to that time is a positive integer divisible by $ 3?$ Your answer should be in closed form, but may include factorials.

Comment

8 Comments

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Number two seems quite a bit easier than one or three... :maybe:

by Temperal, Jan 22, 2008, 4:09 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
A side note. How can 2 or 3 be in the form of $ 3k+1$ for $ k\in\mathbb{Z}$

by hunter34, Jan 22, 2008, 4:27 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
You think it has, hunter 34? :roll:
PS: Actually, I like this topic most since I have spent much time training to expert it but I'm still unsuccessful. The problem 3 is the most challenging! Temporarily, I can't have time to think of it but after final, I hope to solve it with you, "brother"! :)

by ghjk, Jan 23, 2008, 12:46 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
3k+1 refers to the largest number, not the form of them.

by Cicatriz, Jan 23, 2008, 3:04 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
woot, another great blog post. and also the problems were all doable. huzzah for solving number 3. I've enjoyed the ones on things that I had a little prior knowledge about.

by Pakman2012, Jan 23, 2008, 7:05 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
I think your solution is too long, t0jair0u :D

by quangpbc, Jan 28, 2008, 1:30 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
You seem to have a great sense of mathematical elegance for a student .
Best wishes for your interesting blog, which I am going to check regularly.

by Anonymous, Feb 23, 2008, 7:46 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Sorry for stupid revival but the second problem can be seen here http://www.artofproblemsolving.com/Forum/viewtopic.php?p=2055811#p2055811

by Goutham, Oct 19, 2010, 12:09 PM

Various mathematical thoughts, ranging from problem-solving techniques to attempts to tie together related concepts.

avatar

t0rajir0u
Archives
+ March 2009
+ October 2007
+ May 2007
Shouts
Submit
  • orz $~~~~$

    by clarkculus, Jan 10, 2025, 4:13 PM

  • Insanely auraful

    by centslordm, Jan 1, 2025, 11:17 PM

  • Fly High :(

    by Siddharthmaybe, Oct 22, 2024, 8:34 PM

  • Dang it he is gone :(( /revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive/revive.

    by 799786, Aug 4, 2022, 1:56 PM

  • annoying precision

    by centslordm, May 16, 2021, 7:34 PM

  • rip t0rajir0u

    by OlympusHero, Dec 5, 2020, 9:29 PM

  • Shoutbox bump xD

    by DuoDuoling0, Oct 4, 2020, 2:25 AM

  • dang hes gone :(

    by OlympusHero, Jul 28, 2020, 3:52 AM

  • First shout in July

    by smartguy888, Jul 20, 2020, 3:08 PM

  • https://artofproblemsolving.com/community/c2448

    has more.

    -πφ

    by piphi, Jun 12, 2020, 8:20 PM

  • wait hold up 310,000
    people visited this man?!?!??

    by srisainandan6, May 29, 2020, 5:16 PM

  • first shout in 2020

    by OlympusHero, Apr 4, 2020, 1:15 AM

  • in his latest post he says he moved to wordpress

    by MelonGirl, Nov 16, 2019, 2:43 AM

  • Please revive!

    by AopsUser101, Oct 30, 2019, 7:10 PM

  • first shout in october fj9odiais

    by bulbasaur., Oct 14, 2019, 1:14 AM

128 shouts
Tags
About Owner
  • Posts: 12167
  • Joined: Nov 20, 2005
Blog Stats
  • Blog created: Dec 5, 2006
  • Total entries: 48
  • Total visits: 321828
  • Total comments: 202
Search Blog
a