Advanced Counting

Why Advanced Counting?

In Chapters 2 and 3 we developed the basic counting toolkit β€” permutations, combinations, and multinomial coefficients. These suffice when the objects we count are drawn from a single set and placed into a single structure. But many problems in probability and combinatorics require us to count partitions of a set into an unspecified number of blocks, or to enumerate permutations by their cycle structure. Stirling numbers and Bell numbers are the tools for these richer counting problems. They also preview the generating function technique that we will use systematically when we study probability generating functions in Chapter 9.

Definition:

Stirling Number of the Second Kind

For non-negative integers nn and kk, the Stirling number of the second kind, denoted S(n,k)S(n, k) or {nk}\left\{\begin{smallmatrix} n \\ k \end{smallmatrix}\right\}, is the number of ways to partition a set of nn elements into exactly kk non-empty, unordered subsets (called blocks).

By convention, S(0,0)=1S(0, 0) = 1 (the empty set has exactly one partition β€” the empty partition) and S(n,0)=0S(n, 0) = 0 for nβ‰₯1n \geq 1.

The notation {nk}\left\{\begin{smallmatrix} n \\ k \end{smallmatrix}\right\} is due to Knuth. The alternative S(n,k)S(n,k) is more common in probability texts.

Theorem: Recurrence for Stirling Numbers of the Second Kind

For nβ‰₯1n \geq 1 and 1≀k≀n1 \leq k \leq n: S(n,k)=kβ‹…S(nβˆ’1,k)+S(nβˆ’1,kβˆ’1)S(n, k) = k \cdot S(n-1, k) + S(n-1, k-1) with boundary conditions S(n,n)=1S(n, n) = 1 and S(n,1)=1S(n, 1) = 1 for all nβ‰₯1n \geq 1.

Consider element nn. Either it forms a singleton block (contributing S(nβˆ’1,kβˆ’1)S(n-1, k-1) partitions of the remaining elements into kβˆ’1k-1 blocks), or it is inserted into one of the kk existing blocks of a partition of {1,…,nβˆ’1}\{1, \ldots, n-1\} into kk blocks (contributing kβ‹…S(nβˆ’1,k)k \cdot S(n-1, k) partitions).

Example: Computing Small Stirling Numbers

Compute S(4,2)S(4, 2) β€” the number of ways to partition {1,2,3,4}\{1, 2, 3, 4\} into exactly 2 non-empty blocks.

Theorem: Explicit Formula for Stirling Numbers of the Second Kind

For 0≀k≀n0 \leq k \leq n: S(n,k)=1k!βˆ‘j=0k(βˆ’1)kβˆ’j(kj)jnS(n, k) = \frac{1}{k!} \sum_{j=0}^{k} (-1)^{k-j} \binom{k}{j} j^n

The factor k!k! accounts for the fact that blocks are unordered. The alternating sum is an inclusion-exclusion over surjections from [n][n] onto [k][k]: we count all functions, subtract those missing at least one value in [k][k], add back those missing at least two, and so on.

Definition:

Unsigned Stirling Number of the First Kind

The unsigned Stirling number of the first kind, denoted [nk]\left[\begin{smallmatrix} n \\ k \end{smallmatrix}\right] or c(n,k)c(n, k), is the number of permutations of [n]={1,2,…,n}[n] = \{1, 2, \ldots, n\} that have exactly kk disjoint cycles.

The signed Stirling number of the first kind is s(n,k)=(βˆ’1)nβˆ’kc(n,k)s(n, k) = (-1)^{n-k} c(n, k).

Theorem: Recurrence for Unsigned Stirling Numbers of the First Kind

For nβ‰₯1n \geq 1 and 1≀k≀n1 \leq k \leq n: c(n,k)=(nβˆ’1)β‹…c(nβˆ’1,k)+c(nβˆ’1,kβˆ’1)c(n, k) = (n-1) \cdot c(n-1, k) + c(n-1, k-1) with c(0,0)=1c(0, 0) = 1 and c(n,0)=0c(n, 0) = 0 for nβ‰₯1n \geq 1.

Consider element nn in a permutation of [n][n]. Either nn forms a fixed point (a cycle of length 1), contributing c(nβˆ’1,kβˆ’1)c(n-1, k-1) from the remaining elements, or nn is inserted into an existing cycle of a permutation of [nβˆ’1][n-1] with kk cycles. There are nβˆ’1n-1 positions where nn can be inserted (after any of the nβˆ’1n-1 elements in that permutation), giving (nβˆ’1)β‹…c(nβˆ’1,k)(n-1) \cdot c(n-1, k).

Example: Permutations of [3][3] by Cycle Structure

List all permutations of {1,2,3}\{1, 2, 3\} and classify them by number of cycles. Verify the values c(3,1)c(3, 1), c(3,2)c(3, 2), c(3,3)c(3, 3).

Duality Between Stirling Numbers

The two kinds of Stirling numbers satisfy an orthogonality relation. If we define s(n,k)=(βˆ’1)nβˆ’kc(n,k)s(n,k) = (-1)^{n-k} c(n,k), then: βˆ‘j=kns(n,j)β‹…S(j,k)=Ξ΄nk,βˆ‘j=knS(n,j)β‹…s(j,k)=Ξ΄nk\sum_{j=k}^{n} s(n,j) \cdot S(j,k) = \delta_{nk}, \qquad \sum_{j=k}^{n} S(n,j) \cdot s(j,k) = \delta_{nk} In matrix form, the matrices of signed Stirling numbers of the first and second kind are inverses of each other.

Definition:

Bell Number

The Bell number BnB_n is the total number of partitions of a set of nn elements into non-empty, unordered subsets: Bn=βˆ‘k=0nS(n,k)B_n = \sum_{k=0}^{n} S(n, k) By convention, B0=1B_0 = 1.

The first few Bell numbers are: B0=1B_0 = 1, B1=1B_1 = 1, B2=2B_2 = 2, B3=5B_3 = 5, B4=15B_4 = 15, B5=52B_5 = 52.

Theorem: Bell Number Recurrence

For nβ‰₯1n \geq 1: Bn=βˆ‘k=0nβˆ’1(nβˆ’1k)BkB_n = \sum_{k=0}^{n-1} \binom{n-1}{k} B_k

Consider element nn. It belongs to some block of size jj where 1≀j≀n1 \leq j \leq n. Choose the jβˆ’1j-1 other elements of that block from the remaining nβˆ’1n-1 in (nβˆ’1jβˆ’1)\binom{n-1}{j-1} ways, then partition the other nβˆ’jn-j elements in Bnβˆ’jB_{n-j} ways. Summing over jj and substituting k=nβˆ’jk = n - j gives the formula.

Theorem: Exponential Generating Function of Bell Numbers

The exponential generating function (EGF) of the Bell numbers is: βˆ‘n=0∞Bnxnn!=eexβˆ’1\sum_{n=0}^{\infty} B_n \frac{x^n}{n!} = e^{e^x - 1}

The EGF for set partitions factors as the exponential of the EGF for non-empty subsets. Since the EGF for a single non-empty subset is exβˆ’1e^x - 1, the composition gives exp⁑(exβˆ’1)\exp(e^x - 1). This is a fundamental instance of the exponential formula in enumerative combinatorics.

Definition:

Integer Partition

An integer partition of a positive integer nn is a way of writing nn as a sum of positive integers, where the order of summands does not matter. Each summand is called a part. The number of integer partitions of nn is denoted p(n)p(n).

For example, the partitions of 5 are: 55, 4+14+1, 3+23+2, 3+1+13+1+1, 2+2+12+2+1, 2+1+1+12+1+1+1, 1+1+1+1+11+1+1+1+1, so p(5)=7p(5) = 7.

Integer partitions are distinct from set partitions. The set {1,2,3,4,5}\{1,2,3,4,5\} has B5=52B_5 = 52 set partitions, but the integer 5 has only p(5)=7p(5) = 7 integer partitions. Integer partitions count how many objects go in each block; set partitions also track which objects go where.

Historical Note: Euler and the Theory of Partitions

18th–20th century

Leonhard Euler initiated the systematic study of integer partitions in the 1740s. His key insight was to encode partitions via generating functions: the number of partitions of nn is the coefficient of xnx^n in the product ∏k=1∞11βˆ’xk\prod_{k=1}^{\infty} \frac{1}{1 - x^k}. This observation opened the door to an entire branch of combinatorics and number theory. A century and a half later, Hardy and Ramanujan (1918) established the celebrated asymptotic formula p(n)∼14n3eΟ€2n/3p(n) \sim \frac{1}{4n\sqrt{3}} e^{\pi\sqrt{2n/3}} using the circle method β€” one of the landmarks of analytic number theory.

Theorem: Generating Function for Integer Partitions

The ordinary generating function for the partition function p(n)p(n) is: βˆ‘n=0∞p(n) xn=∏k=1∞11βˆ’xk,∣x∣<1\sum_{n=0}^{\infty} p(n)\, x^n = \prod_{k=1}^{\infty} \frac{1}{1 - x^k}, \qquad |x| < 1

Each factor 11βˆ’xk=1+xk+x2k+β‹―\frac{1}{1 - x^k} = 1 + x^k + x^{2k} + \cdots corresponds to choosing how many parts of size kk appear in the partition: 0, 1, 2, and so on. The product over all kk generates all possible combinations of part sizes.

,

Generating Functions: A Preview

The generating functions we encountered for Bell numbers and integer partitions are instances of a powerful general technique: encode a counting sequence {an}\{a_n\} as the coefficients of a formal power series A(x)=βˆ‘anxnA(x) = \sum a_n x^n (ordinary GF) or A(x)=βˆ‘anxn/n!A(x) = \sum a_n x^n/n! (exponential GF). Algebraic operations on power series β€” multiplication, composition, differentiation β€” then correspond to combinatorial operations on the underlying structures.

In Chapter 9 we will formalize this idea in the probabilistic setting: the probability generating function GX(z)=E[zX]G_X(z) = \mathbb{E}[z^X] and the moment generating function MX(t)=E[etX]M_X(t) = \mathbb{E}[e^{tX}] will let us derive distributions of sums of independent random variables, prove the central limit theorem, and establish large deviation bounds.

Stirling number of the second kind

S(n,k)S(n,k): the number of partitions of an nn-element set into exactly kk non-empty, unordered subsets.

Related: Bell number, set partition

Stirling number of the first kind

c(n,k)c(n,k) (unsigned): the number of permutations of [n][n] with exactly kk cycles.

Related: Stirling number of the second kind

Bell number

Bn=βˆ‘k=0nS(n,k)B_n = \sum_{k=0}^{n} S(n,k): the total number of partitions of an nn-element set.

Related: Stirling number of the second kind, set partition

set partition

A collection of non-empty, pairwise disjoint subsets (blocks) of a set SS whose union is SS.

Related: Bell number

integer partition

A representation of a positive integer nn as an unordered sum of positive integers. The number of such representations is p(n)p(n).

Related: set partition

Quick Check

What is S(4,3)S(4, 3)?

3

6

7

4

Quick Check

What is B4B_4?

14

15

16

52

Common Mistake: Set Partitions vs. Integer Partitions

Mistake:

Confusing the number of set partitions of [n][n] (counted by BnB_n) with the number of integer partitions of nn (counted by p(n)p(n)).

Correction:

Set partitions care about which elements go into each block; integer partitions care only about the sizes of the blocks. For n=5n = 5: B5=52B_5 = 52 set partitions but only p(5)=7p(5) = 7 integer partitions.

Key Takeaway

Stirling numbers of the second kind S(n,k)S(n,k) count set partitions into kk blocks; Stirling numbers of the first kind c(n,k)c(n,k) count permutations with kk cycles. Both satisfy simple recurrences that parallel Pascal's identity. Bell numbers BnB_n sum over all kk and admit the elegant EGF eexβˆ’1e^{e^x - 1}. Integer partitions p(n)p(n) have the Euler product generating function ∏(1βˆ’xk)βˆ’1\prod(1-x^k)^{-1}.