# 组合数学 (Spring 2016)/Basic enumeration

## Basic Enumeration

The three basic rules for enumeration are:

• The sum rule: for any disjoint finite sets $\displaystyle{ S }$ and $\displaystyle{ T }$, the cardinality of the union $\displaystyle{ |S\cup T|=|S|+|T| }$.
• The product rule: for any finite sets $\displaystyle{ S }$ and $\displaystyle{ T }$, the cardinality of the Cartesian product $\displaystyle{ |S\times T|=|S|\cdot|T| }$.
• The bijection rule: if there exists a bijection between finite sets $\displaystyle{ S }$ and $\displaystyle{ T }$, then $\displaystyle{ |S|=|T| }$.

Now we apply these rules to solve some basic enumeration problems.

### Tuples

We count the number of $\displaystyle{ n }$-tuples of $\displaystyle{ [m] }$. Formally, we count the number of elements of $\displaystyle{ [m]^n }$. (Remember that $\displaystyle{ [m]=\{0,1,2,\ldots,m-1\} }$.)

It is not very hard to see that this number is $\displaystyle{ m^n }$. That is, $\displaystyle{ |[m]^n|=m^n }$.

To prove this rigorously, we use "the product rule".

• The product rule: for any finite sets $\displaystyle{ S }$ and $\displaystyle{ T }$, the cardinality of the Cartesian product $\displaystyle{ |S\times T|=|S|\cdot|T| }$.

To count the size of $\displaystyle{ [m]^n\, }$, we write $\displaystyle{ [m]^n=[m]\times[m]^{n-1} }$, thus $\displaystyle{ |[m]^n|=m\cdot|[m]^{n-1}|\, }$. Solving the recursion, we have that $\displaystyle{ |[m]^n|=m^n\, }$.

### Functions

Consider the problem of counting the number of functions mapping from $\displaystyle{ [n] }$ to $\displaystyle{ [m] }$, i.e. we count the number of functions in the form $\displaystyle{ f:[n]\rightarrow [m] }$.

We claim that this is the same as counting the number of $\displaystyle{ n }$-tuples of $\displaystyle{ [m] }$. To see this, for any $\displaystyle{ f:[n]\rightarrow [m] }$, we define a tuple $\displaystyle{ v_f\in[m]^n }$ by letting $\displaystyle{ v_f(i)=f(i-1) }$ for every $\displaystyle{ i=1,2,\ldots,n }$. It is easy to verify that $\displaystyle{ v }$ defines a bijection (a 1-1 correspondence) between $\displaystyle{ \{f:[n]\rightarrow [m]\} }$ and $\displaystyle{ [m]^n }$. (Consider this as an exercise.)

Now we summon the "the bijection rule".

• The bijection rule: if there exists a bijection between finite sets $\displaystyle{ S }$ and $\displaystyle{ T }$, then $\displaystyle{ |S|=|T| }$.

Applying this rule, we have that the number of functions from $\displaystyle{ [n] }$ to $\displaystyle{ [m] }$ equals the number of tuples in $\displaystyle{ [m]^n }$, which is $\displaystyle{ m^n }$ as we proved previously.

### Subsets

We count the number of subsets of a set.

Let$\displaystyle{ S=\{x_1,x_2,\ldots,x_n\} }$ be an $\displaystyle{ n }$-element set, or $\displaystyle{ n }$-set for short. Let $\displaystyle{ 2^S=\{T\mid T\subset S\} }$ denote the set of all subset of $\displaystyle{ S }$. $\displaystyle{ 2^S }$ is called the power set of $\displaystyle{ S }$.

We give a combinatorial proof that $\displaystyle{ |2^S|=2^n }$. We observe that every subset $\displaystyle{ T\in 2^S }$ corresponds to a unique bit-vector $\displaystyle{ v\in\{0,1\}^S }$, such that each bit $\displaystyle{ v_i }$ indicates whether $\displaystyle{ x_i\in S }$. Formally, define a map $\displaystyle{ \phi:2^S\rightarrow\{0,1\}^n }$ by $\displaystyle{ \phi(T)=(v_1,v_2,\ldots,v_n) }$, where

$\displaystyle{ v_i=\begin{cases} 1 & \mbox{if }x_i\in T\\ 0 & \mbox{if }x_i\not\in T. \end{cases} }$

The map $\displaystyle{ \phi }$ is a bijection. The proof that $\displaystyle{ \phi }$ is a bijection is left as an exercise.

Since there is a bijection between $\displaystyle{ 2^S }$ and $\displaystyle{ \{0,1\}^n }$, it holds that $\displaystyle{ |2^S|=|\{0,1\}^n|=2^n\, }$.

There are two elements of the proof:

• Find a 1-1 correspondence between subsets of an $\displaystyle{ n }$-set and $\displaystyle{ n }$-bit vectors.
An application of this in Computer Science is that we can use bit-array as a data structure for sets: any set defined over a universe $\displaystyle{ U }$ can be represented by an array of $\displaystyle{ |U| }$ bits.
• The bijection rule: if there is a 1-1 correspondence between two sets, then their cardinalities are the same.

Many counting problems are solved by establishing a bijection between the set to be counted and some easy-to-count set. This kind of proofs are usually called (non-rigorously) combinatorial proofs.

We give an alternative proof that $\displaystyle{ |2^S|=2^n }$. The proof needs another basic counting rule: "the sum rule".

• The sum rule: for any disjoint finite sets $\displaystyle{ S }$ and $\displaystyle{ T }$, the cardinality of the union $\displaystyle{ |S\cup T|=|S|+|T| }$.

Define the function $\displaystyle{ f(n)=|2^{S_n}| }$, where $\displaystyle{ S_n=\{x_1,x_2,\ldots,x_n\} }$ is an $\displaystyle{ n }$-set. Our goal is to compute $\displaystyle{ f(n) }$. We prove the following recursion for $\displaystyle{ f(n) }$.

 Lemma $\displaystyle{ f(n)=2f(n-1)\, }$.
Proof.
 Fix an element $\displaystyle{ x_n }$, let $\displaystyle{ U }$ be the set of subsets of $\displaystyle{ S_n }$ that contain $\displaystyle{ x_n }$ and let $\displaystyle{ V }$ be the set of subsets of $\displaystyle{ S_n }$ that do not contain $\displaystyle{ x_n }$. It is obvious that $\displaystyle{ U }$ and $\displaystyle{ V }$ are disjoint (i.e. $\displaystyle{ U\cap V=\emptyset }$) and $\displaystyle{ 2^{S_n}=U\cup V }$, because any subset of $\displaystyle{ S_n }$ either contains $\displaystyle{ x_n }$ or does not contain $\displaystyle{ x_n }$ but not both. Applying the sum rule, $\displaystyle{ f(n)=|U\cup V|=|U|+|V| }$. The next observation is that $\displaystyle{ |U|=|V|=f(n-1) }$, because $\displaystyle{ V }$ is exactly the $\displaystyle{ 2^{S_{n-1}} }$, and $\displaystyle{ U }$ is the set resulting from adding $\displaystyle{ x_n }$ to every member of $\displaystyle{ 2^{S_{n-1}} }$. Therefore, $\displaystyle{ f(n)=|U|+|V|=f(n-1)+f(n-1)=2f(n-1)\, }$.
$\displaystyle{ \square }$

The elementary case $\displaystyle{ f(0)=1 }$, because $\displaystyle{ \emptyset }$ has only one subset $\displaystyle{ \emptyset }$. Solving the recursion, we have that $\displaystyle{ |2^S|=f(n)=2^n }$.

### Subsets of fixed size

We then count the number of subsets of fixed size of a set. Again, let $\displaystyle{ S=\{x_1,x_2,\ldots,x_n\} }$ be an $\displaystyle{ n }$-set. We define $\displaystyle{ {S\choose k} }$ to be the set of all $\displaystyle{ k }$-elements subsets (or $\displaystyle{ k }$-subsets) of $\displaystyle{ S }$. Formally, $\displaystyle{ {S\choose k}=\{T\subseteq S\mid |T|=k\} }$. The set $\displaystyle{ {S\choose k} }$ is sometimes called the $\displaystyle{ k }$-uniform of $\displaystyle{ S }$.

We denote that $\displaystyle{ {n\choose k}=\left|{S\choose k}\right| }$. The notation $\displaystyle{ {n\choose k} }$ is read "$\displaystyle{ n }$ choose $\displaystyle{ k }$".

 Theorem $\displaystyle{ {n\choose k}=\frac{n(n-1)\cdots(n-k+1)}{k(k-1)\cdots 1}=\frac{n!}{k!(n-k)!} }$.
Proof.
 The number of ordered $\displaystyle{ k }$-subsets of an $\displaystyle{ n }$-set is $\displaystyle{ n(n-1)\cdots(n-k+1) }$. Every $\displaystyle{ k }$-subset has $\displaystyle{ k!=k(k-1)\cdots1 }$ ways to order it.
$\displaystyle{ \square }$
Some notations
• $\displaystyle{ n! }$, read "$\displaystyle{ n }$ factorial", is defined as that $\displaystyle{ n!=n(n-1)(n-2)\cdots 1 }$, with the convention that $\displaystyle{ 0!=1 }$.
• $\displaystyle{ n(n-1)\cdots(n-k+1)=\frac{n!}{(n-k)!} }$ is usually denoted as $\displaystyle{ (n)_k\, }$, read "$\displaystyle{ n }$ lower factorial $\displaystyle{ k }$".

### Binomial coefficient

The quantity $\displaystyle{ {n\choose k} }$ is called a binomial coefficient.

 Proposition $\displaystyle{ {n\choose k}={n\choose n-k} }$; $\displaystyle{ \sum_{k=0}^n {n\choose k}=2^n }$.
Proof.
 1. We give two proofs for the first equation: (1) (numerical proof) $\displaystyle{ {n\choose k}=\frac{n!}{k!(n-k)!}={n\choose n-k} }$. (2) (combinatorial proof) Choosing $\displaystyle{ k }$ elements from an $\displaystyle{ n }$-set is equivalent to choosing the $\displaystyle{ n-k }$ elements to leave out. Formally, every $\displaystyle{ k }$-subset $\displaystyle{ T\in{S\choose k} }$ is uniquely specified by its complement $\displaystyle{ S\setminus T\in {S\choose n-k} }$, and the same holds for $\displaystyle{ (n-k) }$-subsets, thus we have a bijection between $\displaystyle{ {S\choose k} }$ and $\displaystyle{ {S\choose n-k} }$. 2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an $\displaystyle{ n }$-element set $\displaystyle{ S }$, it is obvious that we can enumerate all subsets of $\displaystyle{ S }$ by enumerating $\displaystyle{ k }$-subsets for every possible size $\displaystyle{ k }$, i.e. it holds that $\displaystyle{ 2^S=\bigcup_{k=0}^n{S\choose k}. }$ For different $\displaystyle{ k }$, $\displaystyle{ {S\choose k} }$ are obviously disjoint. By the sum rule, $\displaystyle{ 2^n=|2^S|=\left|\bigcup_{k=0}^n{S\choose k}\right|=\sum_{k=0}^n\left|{S\choose k}\right|=\sum_{k=0}^n {n\choose k} }$.
$\displaystyle{ \square }$

$\displaystyle{ {n\choose k} }$ is called binomial coefficient for a reason. The following celebrated Binomial Theorem states that if a power of a binomial is expanded, the coefficients in the resulting polynomial are the binomial coefficients.

 Theorem (Binomial theorem) $\displaystyle{ (1+x)^n=\sum_{k=0}^n{n\choose k}x^k }$.
Proof.
 Write $\displaystyle{ (1+x)^n }$ as the product of $\displaystyle{ n }$ factors $\displaystyle{ (1+x)(1+x)\cdots (1+x) }$. The term $\displaystyle{ x^k }$ is obtained by choosing $\displaystyle{ x }$ from $\displaystyle{ k }$ factors and 1 from the rest $\displaystyle{ (n-k) }$ factors. There are $\displaystyle{ {n\choose k} }$ ways of choosing these $\displaystyle{ k }$ factors, so the coefficient of $\displaystyle{ x^k }$ is $\displaystyle{ {n\choose k} }$.
$\displaystyle{ \square }$

The following proposition has an easy proof due to the binomial theorem.

 Proposition For $\displaystyle{ n\gt 0 }$, the numbers of subsets of an $\displaystyle{ n }$-set of even and of odd cardinality are equal.
Proof.
 Set $\displaystyle{ x=-1 }$ in the binomial theorem. $\displaystyle{ 0=(1-1)^n=\sum_{k=0}^n{n\choose k}(-1)^k=\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}-\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}, }$ therefore $\displaystyle{ \sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}=\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}. }$
$\displaystyle{ \square }$

For counting problems, what we care about are numbers. In the binomial theorem, a formal variable $\displaystyle{ x }$ is introduced. It looks having nothing to do with our problem, but turns out to be very useful. This idea of introducing a formal variable is the basic idea of some advanced counting techniques, which will be discussed in future classes.

### Compositions of an integer

A composition of $\displaystyle{ n }$ is an expression of $\displaystyle{ n }$ as an ordered sum of positive integers. A $\displaystyle{ k }$-composition of $\displaystyle{ n }$ is a composition of $\displaystyle{ n }$ with exactly $\displaystyle{ k }$ positive summands.

Formally, a $\displaystyle{ k }$-composition of $\displaystyle{ n }$ is a $\displaystyle{ k }$-tuple $\displaystyle{ (a_1,a_2,\ldots,a_k)\in\{1,2,\ldots,n\}^k }$ such that $\displaystyle{ a_1+a_2+\cdots+a_k=n }$.

Suppose we have $\displaystyle{ n }$ identical balls in a line. A $\displaystyle{ k }$-composition partitions these $\displaystyle{ n }$ balls into $\displaystyle{ k }$ nonempty sets, illustrated as follows.

$\displaystyle{ \begin{array}{c|cc|c|c|ccc|cc} \bigcirc \,&\, \bigcirc \,& \bigcirc \,&\, \bigcirc \,&\, \bigcirc \,&\, \bigcirc &\, \bigcirc &\, \bigcirc \,&\, \bigcirc \,& \bigcirc \end{array} }$

So the number of $\displaystyle{ k }$-compositions of $\displaystyle{ n }$ equals the number of ways we put $\displaystyle{ k-1 }$ bars "$\displaystyle{ | }$" into $\displaystyle{ n-1 }$ slots "$\displaystyle{ \sqcup }$", where each slot has at most one bar (because all the summands $\displaystyle{ a_i\gt 0 }$):

$\displaystyle{ \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc }$

which is equal to the number of ways of choosing $\displaystyle{ k-1 }$ slots out of $\displaystyle{ n-1 }$ slots, which is $\displaystyle{ {n-1\choose k-1} }$.

This graphic argument can be expressed as a formal proof. We construct a bijection between the set of $\displaystyle{ k }$-compositions of $\displaystyle{ n }$ and $\displaystyle{ {\{1,2,\ldots,n-1\}\choose k-1} }$ as follows.

Let $\displaystyle{ \phi }$ be a mapping that given a $\displaystyle{ k }$-composition $\displaystyle{ (a_1,a_2,\ldots,a_k) }$ of $\displaystyle{ n }$,

\displaystyle{ \begin{align} \phi((a_1,a_2,\ldots,a_k)) &=\{a_1,\,\,a_1+a_2,\,\,a_1+a_2+a_3,\,\,\ldots,\,\,a_1+a_2+\cdots+a_{k-1}\}\\ &=\left\{\sum_{i=1}^ja_i\,\,\bigg|\,\, 1\le j\lt k\right\}. \end{align} }

$\displaystyle{ \phi }$ maps every $\displaystyle{ k }$-composition to a $\displaystyle{ (k-1) }$-subset of $\displaystyle{ \{1,2,\ldots,n-1\} }$. It is easy to verify that $\displaystyle{ \phi }$ is a bijection, thus the number of $\displaystyle{ k }$-compositions of $\displaystyle{ n }$ is $\displaystyle{ {n-1\choose k-1} }$.

The number of $\displaystyle{ k }$-compositions of $\displaystyle{ n }$ is equal to the number of solutions to $\displaystyle{ x_1+x_2+\cdots+x_k=n }$ in positive integers. This suggests us to relax the constraint and count the number of solutions to $\displaystyle{ x_1+x_2+\cdots+x_k=n }$ in nonnegative integers. We call such a solution a weak $\displaystyle{ k }$-composition of $\displaystyle{ n }$.

Formally, a weak $\displaystyle{ k }$-composition of $\displaystyle{ n }$ is a tuple $\displaystyle{ (x_1,x_2,\ldots,x_k)\in[n+1]^k }$ such that $\displaystyle{ x_1+x_2+\cdots+x_k=n }$.

Given a weak $\displaystyle{ k }$-composition $\displaystyle{ (x_1,x_2,\ldots,x_k) }$ of $\displaystyle{ n }$, if we set $\displaystyle{ y_i=x_i+1 }$ for every $\displaystyle{ 1\le i\le k }$, then $\displaystyle{ y_i\gt 0 }$ and

\displaystyle{ \begin{align} y_1+y_2+\cdots +y_k &=(x_1+1)+(x_2+1)+\cdots+(x_k+1)&=n+k, \end{align} }

i.e., $\displaystyle{ (y_1,y_2,\ldots,y_k) }$ is a $\displaystyle{ k }$-composition of $\displaystyle{ n+k }$. It is easy to see that it defines a bijection between weak $\displaystyle{ k }$-compositions of $\displaystyle{ n }$ and $\displaystyle{ k }$-compositions of $\displaystyle{ n+k }$. Therefore, the number of weak $\displaystyle{ k }$-compositions of $\displaystyle{ n }$ is $\displaystyle{ {n+k-1\choose k-1} }$.

We now count the number of solutions to $\displaystyle{ x_1+x_2+\cdots+x_k\le n }$ in nonnegative integers.

Let $\displaystyle{ x_{k+1}=n-(x_1+x_2+\cdots+x_k) }$. Then $\displaystyle{ x_{k+1}\ge 0 }$ and $\displaystyle{ x_1+x_2+\ldots+x_k+x_{k+1}=n }$. The problem is transformed to that counting the number of solutions to the above equation in nonnegative integers. The answer is $\displaystyle{ {n+k\choose k} }$.

### Multisets

A $\displaystyle{ k }$-subset of an $\displaystyle{ n }$-set $\displaystyle{ S }$ is sometimes called a $\displaystyle{ k }$-combination of $\displaystyle{ S }$ without repetitions. This suggests the problem of counting the number of $\displaystyle{ k }$-combinations of $\displaystyle{ S }$ with repetitions; that is, we choose $\displaystyle{ k }$ elements of $\displaystyle{ S }$, disregarding order and allowing repeated elements.

Example
$\displaystyle{ S=\{1,2,3,4\} }$. All $\displaystyle{ 3 }$-combination without repetitions are
$\displaystyle{ \{1,2,3\},\{1,2,4\},\{1,3,4\},\{2,3,4\}\, }$.
Allowing repetitions, we also include the following 3-combinations:
\displaystyle{ \begin{align} &\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,1,4\},\{1,2,2\},\{1,3,3\},\{1,4,4\},\\ &\{2,2,2\},\{2,2,3\},\{2,2,4\},\{2,3,3\},\{2,4,4\},\\ &\{3,3,3\},\{3,3,4\},\{3,4,4\}\\ &\{4,4,4\} \end{align} }

Combinations with repetitions can be formally defined as multisets. A multiset is a set with repeated elements. Formally, a multiset $\displaystyle{ M }$ on a set $\displaystyle{ S }$ is a function $\displaystyle{ m:S\rightarrow \mathbb{N} }$. For any element $\displaystyle{ x\in S }$, the integer $\displaystyle{ m(x)\ge 0 }$ is the number of repetitions of $\displaystyle{ x }$ in $\displaystyle{ M }$, called the multiplicity of $\displaystyle{ x }$. The sum of multiplicities $\displaystyle{ \sum_{x\in S}m(x) }$ is called the cardinality of $\displaystyle{ M }$ and is denoted as $\displaystyle{ |M| }$.

A $\displaystyle{ k }$-multiset on a set $\displaystyle{ S }$ is a multiset $\displaystyle{ M }$ on $\displaystyle{ S }$ with $\displaystyle{ |M|=k }$. It is obvious that a $\displaystyle{ k }$-combination of $\displaystyle{ S }$ with repetition is simply a $\displaystyle{ k }$-multiset on $\displaystyle{ S }$.

The set of all $\displaystyle{ k }$-multisets on $\displaystyle{ S }$ is denoted $\displaystyle{ \left.\left({\binom{S}{k}}\right)\right. }$. Assuming that $\displaystyle{ n=|S| }$, denote $\displaystyle{ \left({n\choose k}\right)=\left|\left({S\choose k}\right)\right| }$, which is the number of $\displaystyle{ k }$-combinations of an $\displaystyle{ n }$-set with repetitions.

Believe it or not: we have already evaluated the number $\displaystyle{ \left({n\choose k}\right) }$. If $\displaystyle{ S=\{x_1,x_2,\ldots,x_n\} }$, let $\displaystyle{ z_i=m(x_i) }$, then $\displaystyle{ \left({n\choose k}\right) }$ is the number of solutions to $\displaystyle{ z_1+z_2+\cdots+z_n=k }$ in nonnegative integers, which is the number of weak $\displaystyle{ n }$-compositions of $\displaystyle{ k }$, which we have seen is $\displaystyle{ {n+k-1\choose n-1}={n+k-1\choose k} }$.

There is a direct combinatorial proof that $\displaystyle{ \left({n\choose k}\right)={n+k-1\choose k} }$.

Given a $\displaystyle{ k }$-multiset $\displaystyle{ 0\le a_0\le a_1\le\cdots\le a_{k-1}\le n-1 }$ on $\displaystyle{ [n] }$, then defining $\displaystyle{ b_i=a_i+i }$, we see that $\displaystyle{ \{b_0,b_1,\ldots,b_{k-1}\} }$ is a $\displaystyle{ k }$-subset of $\displaystyle{ [n+k-1] }$. Conversely, given a $\displaystyle{ k }$-subset $\displaystyle{ 0\le b_0\le b_1\le\cdots\le b_{k-1}\le n+k-2 }$ of $\displaystyle{ [n+k-1] }$, then defining $\displaystyle{ a_i=b_i-i }$, we have that $\displaystyle{ \{a_0,a_1,\ldots,a_{k-1}\} }$ is a $\displaystyle{ k }$-multiset on $\displaystyle{ [n] }$. Therefore, we have a bijection between $\displaystyle{ \left({[n]\choose k}\right) }$ and $\displaystyle{ {[n+k-1]\choose k} }$.

### Multinomial coefficients

The binomial coefficient $\displaystyle{ {n\choose k} }$ may be interpreted as follows. Each element of an $\displaystyle{ n }$-set is placed into two groups, with $\displaystyle{ k }$ elements in Group 1 and $\displaystyle{ n-k }$ elements in Group 2. The binomial coefficient $\displaystyle{ {n\choose k} }$ counts the number of such placements.

This suggests a generalization allowing more than two groups. Let $\displaystyle{ (a_1,a_2,\ldots,a_m) }$ be a tuple of nonnegative integers summing to $\displaystyle{ n }$. Let $\displaystyle{ {n\choose a_1,a_2,\ldots,a_m} }$ denote the number of ways of assigning each element of an $\displaystyle{ n }$-set to one of $\displaystyle{ m }$ groups $\displaystyle{ G_1,G_2,\ldots,G_m }$ so that exactly $\displaystyle{ a_i }$ elements are assigned to $\displaystyle{ G_i }$.

The binomial coefficient is just the case when there are two groups, and $\displaystyle{ {n\choose k}={n\choose k,n-k} }$. The number $\displaystyle{ {n\choose a_1,a_2,\ldots,a_m} }$ is called a multinomial coefficient. We can think of it as that $\displaystyle{ n }$ labeled balls are assigned to $\displaystyle{ m }$ labeled bins, and $\displaystyle{ {n\choose a_1,a_2,\ldots,a_m} }$ is the number of assignments such that the $\displaystyle{ i }$-th bin has $\displaystyle{ a_i }$ balls in it.

The multinomial coefficient can also be interpreted as the number of permutations of multisets. A permutation $\displaystyle{ \pi }$ of an $\displaystyle{ n }$-set $\displaystyle{ S }$ can be defined in two equivalent ways:

• a bijection $\displaystyle{ \pi:S\rightarrow S }$;
• a tuple $\displaystyle{ \pi=(x_1,x_2,\ldots,x_n)\in S^n }$ such that all $\displaystyle{ x_i }$ are distinct.

There are $\displaystyle{ n! }$ permutations of an $\displaystyle{ n }$-set $\displaystyle{ S }$.

A permutation of a multiset $\displaystyle{ M }$ is a tuple $\displaystyle{ \pi=(x_1,x_2,\ldots,x_n) }$ such that every $\displaystyle{ x_i\in M }$ appears in $\displaystyle{ \pi }$ for exactly $\displaystyle{ m(x_i) }$ times, where $\displaystyle{ m(x_i) }$ is the multiplicity of $\displaystyle{ x_i }$ in $\displaystyle{ M }$.

Example
We want to enumerate all the ways of reordering the word "multinomial". Note that in this word, the letter "m", "l" and "i" each appears twice. So the problem is to enumerate the permutations of the multiset $\displaystyle{ \{\text{a, i, i, l, l, m, m, n, o, t, u}\} }$.

Let $\displaystyle{ M }$ be a multiset of $\displaystyle{ m }$ distinct elements $\displaystyle{ x_1,x_2,\ldots,x_m }$ such that $\displaystyle{ x_i }$ has multiplicity $\displaystyle{ a_i }$ in $\displaystyle{ M }$. A permutation $\displaystyle{ \pi }$ of multiset $\displaystyle{ M }$ assigns $\displaystyle{ n }$ indices $\displaystyle{ 1,2,\ldots,n }$ to $\displaystyle{ m }$ groups, where each group corresponds to a distinct element $\displaystyle{ x_i }$, such that $\displaystyle{ i }$ is assigned to group $\displaystyle{ j }$ if $\displaystyle{ \pi_i=x_j }$.

Therefore, $\displaystyle{ {n\choose a_1,a_2,\ldots,a_m} }$ is also the number of permutations of a multiset $\displaystyle{ M }$ with $\displaystyle{ |M|=n }$ such that $\displaystyle{ M }$ has $\displaystyle{ m }$ distinct elements whose multiplicities are given by $\displaystyle{ a_1,a_2,\ldots,a_m }$.

 Theorem $\displaystyle{ {n\choose a_1,a_2,\ldots,a_m}=\frac{n!}{a_1!a_2!\cdots a_m!}. }$
Proof.
 There are $\displaystyle{ n! }$ permutations of $\displaystyle{ n }$ objects. Assume that these $\displaystyle{ n }$ objects are the elements of an multiset $\displaystyle{ M }$ of $\displaystyle{ m }$ distinct elements with $\displaystyle{ |M|=n }$ and multiplicities $\displaystyle{ a_1,a_2,\ldots,a_m }$. Since $\displaystyle{ a_i! }$ permutations of object $\displaystyle{ i }$ do not change the permutation of the multiset $\displaystyle{ M }$, every $\displaystyle{ a_1!a_2!\cdots a_m! }$ permutations of these $\displaystyle{ n }$ objects correspond to the same permutation of the multiset $\displaystyle{ M }$. Thus, the number of permutations of $\displaystyle{ M }$ is $\displaystyle{ \frac{n!}{a_1!a_2!\cdots a_m!} }$.
$\displaystyle{ \square }$

We also have the Multinomial Theorem.

 Theorem $\displaystyle{ {n\choose a_1,a_2,\ldots,a_m} }$ is the coefficient of $\displaystyle{ x_1^{a_1}x_2^{a_2}\cdots x_m^{a_m} }$ in $\displaystyle{ (x_1+x_2+\cdots +x_m)^n }$.
Proof.
 Write $\displaystyle{ (x_1+x_2+\cdots +x_m)^n=(x_1+x_2+\cdots +x_m)\cdots (x_1+x_2+\cdots +x_m) }$. Each of the $\displaystyle{ n }$ factors corresponds to a distinct ball, and $\displaystyle{ x_1,x_2,\ldots,x_m }$ correspond to $\displaystyle{ m }$ groups. The coefficient of $\displaystyle{ x_1^{a_1}x_2^{a_2}\cdots x_m^{a_m} }$ equals the number of ways to put $\displaystyle{ n }$distinct balls to $\displaystyle{ m }$ distinct groups so that group $\displaystyle{ i }$ receives $\displaystyle{ a_i }$ balls, which is exactly our first definition of $\displaystyle{ {n\choose a_1,a_2,\ldots,a_m} }$.
$\displaystyle{ \square }$

### Partitions of a set

A partition of finite set $\displaystyle{ S }$ is a collection $\displaystyle{ P=\{S_1,S_2,\ldots,S_k\} }$ of subsets of $\displaystyle{ S }$ such that:

• $\displaystyle{ S_i\neq\emptyset }$ for every $\displaystyle{ i }$;
• $\displaystyle{ S_i\cap S_j=\emptyset }$ if $\displaystyle{ i\neq j }$ (also called that blocks are pairwise disjoint);
• $\displaystyle{ S_1\cup S_2\cup\cdots\cup S_k=S }$.

Each $\displaystyle{ S_i }$ is called a block of partition $\displaystyle{ P }$. We call $\displaystyle{ P }$ a $\displaystyle{ k }$-partition of $\displaystyle{ S }$ if $\displaystyle{ |P|=k }$.

Define $\displaystyle{ \left\{{n \atop k}\right\} }$ to be the number of $\displaystyle{ k }$-partitions of an $\displaystyle{ n }$-set. Note that since a partition $\displaystyle{ P }$ is a set, the order of blocks $\displaystyle{ S_1,S_2,\ldots,S_k }$ is disregarded when counting $\displaystyle{ k }$-partitions.

The number $\displaystyle{ \left\{{n \atop k}\right\} }$ is called a Stirling number of the second kind.

 Stirling number Stirling numbers are named after James Stirling.There are two kinds of Stirling numbers. Stirling number of the first kind is related to the number of permutations with fixed number of disjoint cycles. And Stirling number of the second kind counts the number of ways of partitioning a set into fixed number of disjoint blocks. Both numbers arise from important combinatorial problems and have various applications in combinatorics and other branches of Mathematics.

Unlike previous identities, it is very difficult to give a determinant for $\displaystyle{ \left\{{n \atop k}\right\} }$. But we have the following recurrence:

 Theorem $\displaystyle{ \left\{{n \atop k}\right\}=k\left\{{n-1 \atop k}\right\}+\left\{{n-1 \atop k-1}\right\} }$.
Proof.
 To partition $\displaystyle{ \{1,2,\ldots,n\} }$ into $\displaystyle{ k }$ blocks, we can partition $\displaystyle{ \{1,2,\ldots,{n-1}\} }$ into $\displaystyle{ k }$ blocks and place $\displaystyle{ n }$ into one of the $\displaystyle{ k }$ blocks, which gives us $\displaystyle{ k\left\{{n-1 \atop k}\right\} }$ ways to do so; or we can partition $\displaystyle{ \{1,2,\ldots,{n-1}\} }$ into $\displaystyle{ k-1 }$ blocks and let $\displaystyle{ \{n\} }$ be a block by itself, which gives us $\displaystyle{ \left\{{n-1 \atop k-1}\right\} }$ ways to do so. The partitions constructed by these two methods are different, since by the first method, $\displaystyle{ n }$ is always in a block of cardinality $\displaystyle{ \gt 1 }$, and by the second method, $\displaystyle{ \{n\} }$ is always a block. So the cases are disjoint. And any $\displaystyle{ k }$-partition of an $\displaystyle{ n }$-set must be constructible by one of the two methods, thus by the sum rule, $\displaystyle{ \,\left\{{n \atop k}\right\}=k\left\{{n-1 \atop k}\right\}+\left\{{n-1 \atop k-1}\right\} }$.
$\displaystyle{ \square }$

Let $\displaystyle{ B_n=\sum_{k=1}^n \left\{{n \atop k}\right\} }$, which gives the total number of partitions of an $\displaystyle{ n }$-set. $\displaystyle{ B(n) }$ is called the Bell number.

### Partitions of a number

We count the ways of partitioning $\displaystyle{ n }$ identical objects into $\displaystyle{ k }$ unordered groups. This is equivalent to counting the ways partitioning a number $\displaystyle{ n }$ into $\displaystyle{ k }$ unordered parts.

A $\displaystyle{ k }$-partition of a number $\displaystyle{ n }$ is a multiset $\displaystyle{ \{x_1,x_2,\ldots,x_k\} }$ with $\displaystyle{ x_i\ge 1 }$ for every element $\displaystyle{ x_i }$ and $\displaystyle{ x_1+x_2+\cdots+x_k=n }$.

We define $\displaystyle{ p_k(n) }$ as the number of $\displaystyle{ k }$-partitions of $\displaystyle{ n }$.

For example, number 7 has the following partitions:

\displaystyle{ \begin{align} &\{7\} & p_1(7)=1\\ &\{1,6\},\{2,5\},\{3,4\} & p_2(7)=3\\ &\{1,1,5\}, \{1,2,4\}, \{1,3,3\}, \{2,2,3\} & p_3(7)=4\\ &\{1,1,1,4\},\{1,1,2,3\}, \{1,2,2,2\} & p_4(7)=3\\ &\{1,1,1,1,3\},\{1,1,1,2,2\} & p_5(7)=2\\ &\{1,1,1,1,1,2\} & p_6(7)=1\\ &\{1,1,1,1,1,1,1\} & p_7(7)=1 \end{align} }

Equivalently, we can also define that A $\displaystyle{ k }$-partition of a number $\displaystyle{ n }$ is a $\displaystyle{ k }$-tuple $\displaystyle{ (x_1,x_2,\ldots,x_k) }$ with:

• $\displaystyle{ x_1\ge x_2\ge\cdots\ge x_k\ge 1 }$;
• $\displaystyle{ x_1+x_2+\cdots+x_k=n }$.

$\displaystyle{ p_k(n) }$ the number of integral solutions to the above system.

Let $\displaystyle{ p(n)=\sum_{k=1}^n p_k(n) }$ be the total number of partitions of $\displaystyle{ n }$. The function $\displaystyle{ p(n) }$ is called the partition number.

We now try to determine $\displaystyle{ p_k(n) }$. Unfortunately, $\displaystyle{ p_k(n) }$ does not have a nice closed form formula. We now give a recurrence for $\displaystyle{ p_k(n) }$.

 Proposition $\displaystyle{ p_k(n)=p_{k-1}(n-1)+p_k(n-k)\, }$.
Proof.
 Suppose that $\displaystyle{ (x_1,\ldots,x_k) }$ is a $\displaystyle{ k }$-partition of $\displaystyle{ n }$. Note that it must hold that $\displaystyle{ x_1\ge x_2\ge \cdots \ge x_k\ge 1 }$. There are two cases: $\displaystyle{ x_k=1 }$ or $\displaystyle{ x_k\gt 1 }$. Case 1. If $\displaystyle{ x_k=1 }$, then $\displaystyle{ (x_1,\cdots,x_{k-1}) }$ is a distinct $\displaystyle{ (k-1) }$-partition of $\displaystyle{ n-1 }$. And every $\displaystyle{ (k-1) }$-partition of $\displaystyle{ n-1 }$ can be obtained in this way. Thus the number of $\displaystyle{ k }$-partitions of $\displaystyle{ n }$ in this case is $\displaystyle{ p_{k-1}(n-1) }$. Case 2. If $\displaystyle{ x_k\gt 1 }$, then $\displaystyle{ (x_1-1,\cdots,x_{k}-1) }$ is a distinct $\displaystyle{ k }$-partition of $\displaystyle{ n-k }$. And every $\displaystyle{ k }$-partition of $\displaystyle{ n-k }$ can be obtained in this way. Thus the number of $\displaystyle{ k }$-partitions of $\displaystyle{ n }$ in this case is $\displaystyle{ p_{k}(n-k) }$. In conclusion, the number of $\displaystyle{ k }$-partitions of $\displaystyle{ n }$ is $\displaystyle{ p_{k-1}(n-1)+p_k(n-k) }$, i.e. $\displaystyle{ p_k(n)=p_{k-1}(n-1)+p_k(n-k)\, }$.
$\displaystyle{ \square }$

Use the above recurrence, we can compute the $\displaystyle{ p_k(n) }$ for some decent $\displaystyle{ n }$ and $\displaystyle{ k }$ by computer simulation.

If we are not restricted ourselves to the precise estimation of $\displaystyle{ p_k(n) }$, the next theorem gives an asymptotic estimation of $\displaystyle{ p_k(n) }$. Note that it only holds for constant $\displaystyle{ k }$, i.e. $\displaystyle{ k }$ does not depend on $\displaystyle{ n }$.

 Theorem For any fixed $\displaystyle{ k }$, $\displaystyle{ p_k(n)\sim\frac{n^{k-1}}{k!(k-1)!} }$, as $\displaystyle{ n\rightarrow \infty }$.
Proof.
 Suppose that $\displaystyle{ (x_1,\ldots,x_k) }$ is a $\displaystyle{ k }$-partition of $\displaystyle{ n }$. Then $\displaystyle{ x_1+x_2+\cdots+x_k=n }$ and $\displaystyle{ x_1\ge x_2\ge \cdots \ge x_k\ge 1 }$. The $\displaystyle{ k! }$ permutations of $\displaystyle{ (x_1,\ldots,x_k) }$ yield at most $\displaystyle{ k! }$ many $\displaystyle{ k }$-compositions (the ordered sum of $\displaystyle{ k }$ positive integers). There are $\displaystyle{ {n-1\choose k-1} }$ many $\displaystyle{ k }$-compositions of $\displaystyle{ n }$, every one of which can be yielded in this way by permuting a partition. Thus, $\displaystyle{ k!p_k(n)\ge{n-1\choose k-1} }$. Let $\displaystyle{ y_i=x_i+k-i }$. That is, $\displaystyle{ y_k=x_k, y_{k-1}=x_{k-1}+1, y_{k-2}=x_{k-2}+2,\ldots, y_{1}=x_{1}+k-1 }$. Then, it holds that $\displaystyle{ y_1\gt y_2\gt \cdots\gt y_k\ge 1 }$; and $\displaystyle{ y_1+y_2+\cdots+y_k=n+\frac{k(k-1)}{2} }$. Each permutation of $\displaystyle{ (y_1,y_2,\ldots,y_k) }$ yields a distinct $\displaystyle{ k }$-composition of $\displaystyle{ n+\frac{k(k-1)}{2} }$, because all $\displaystyle{ y_i }$ are distinct. Thus, $\displaystyle{ k!p_k(n)\le {n+\frac{k(k-1)}{2}-1\choose k-1} }$. Combining the two inequalities, we have $\displaystyle{ \frac{{n-1\choose k-1}}{k!}\le p_k(n)\le \frac{{n+\frac{k(k-1)}{2}-1\choose k-1}}{k!} }$. The theorem follows.
$\displaystyle{ \square }$

### Ferrers diagram

A partition of a number $\displaystyle{ n }$ can be represented as a diagram of dots (or squares), called a Ferrers diagram (the square version of Ferrers diagram is also called a Young diagram, named after a structured called Young tableaux).

Let $\displaystyle{ (x_1,x_2,\ldots,x_k) }$ with that $\displaystyle{ x_1\ge x_2\ge \cdots x_k\ge 1 }$ be a partition of $\displaystyle{ n }$. Its Ferrers diagram consists of $\displaystyle{ k }$ rows, where the $\displaystyle{ i }$-th row contains $\displaystyle{ x_i }$ dots (or squares).

Ferrers diagram (dot version) of (5,4,2,1) Ferrers diagram (square version) of (5,4,2,1)
Conjugate partition

The partition we get by reading the Ferrers diagram by column instead of rows is called the conjugate of the original partition.

$\displaystyle{ (6,4,4,2,1) }$ conjugate: $\displaystyle{ (5,4,3,3,1,1) }$

Clearly,

• different partitions cannot have the same conjugate, and
• every partition of $\displaystyle{ n }$ is the conjugate of some partition of $\displaystyle{ n }$,

so the conjugation mapping is a permutation on the set of partitions of $\displaystyle{ n }$. This fact is very useful in proving theorems for partitions numbers.

Some theorems of partitions can be easily proved by representing partitions in Ferrers diagrams.

 Proposition The number of partitions of $\displaystyle{ n }$ which have largest summand $\displaystyle{ k }$, is $\displaystyle{ p_k(n) }$. The number of $\displaystyle{ n }$ into $\displaystyle{ k }$ parts equals the number of partitions of $\displaystyle{ n-k }$ into at most $\displaystyle{ k }$ parts. Formally, $\displaystyle{ p_k(n)=\sum_{j=1}^k p_j(n-k) }$.
Proof.
 For every $\displaystyle{ k }$-partition, the conjugate partition has largest part $\displaystyle{ k }$. And vice versa. For a $\displaystyle{ k }$-partition of $\displaystyle{ n }$, remove the leftmost cell of every row of the Ferrers diagram. Totally $\displaystyle{ k }$ cells are removed and the remaining diagram is a partition of $\displaystyle{ n-k }$ into at most $\displaystyle{ k }$ parts. And for a partition of $\displaystyle{ n-k }$ into at most $\displaystyle{ k }$ parts, add a cell to each of the $\displaystyle{ k }$ rows (including the empty ones). This will give us a $\displaystyle{ k }$-partition of $\displaystyle{ n }$. It is easy to see the above mappings are 1-1 correspondences. Thus, the number of $\displaystyle{ n }$ into $\displaystyle{ k }$ parts equals the number of partitions of $\displaystyle{ n-k }$ into at most $\displaystyle{ k }$ parts.
$\displaystyle{ \square }$

## The twelvfold way

We now introduce a general framework for counting problems, called the twelvefold way. This framework is introduced by the great mathematician and also a great teacher, Gian-Carlo Rota.

Let $\displaystyle{ N }$ and $\displaystyle{ M }$ be finite sets with $\displaystyle{ |N|=n }$ and $\displaystyle{ |M|=m }$. We count the number of functions $\displaystyle{ f:N\rightarrow M }$ subject to different restrictions. There are three restrictions regarding the mapping $\displaystyle{ f }$ itself:

1. $\displaystyle{ f }$ is an arbitrary function;
2. $\displaystyle{ f }$ is an injection (one-to-one);
3. $\displaystyle{ f }$ is a surjection (onto).

The elements of $\displaystyle{ N }$ and $\displaystyle{ M }$ can be regarded as distinguishable or indistinguishable. Think of $\displaystyle{ N }$ as a set of $\displaystyle{ n }$ balls and $\displaystyle{ M }$ as a set of $\displaystyle{ m }$ bins. A function $\displaystyle{ f:N\rightarrow M }$ is an assignment of the $\displaystyle{ n }$ balls into $\displaystyle{ m }$ bins. The balls are distinguishable if each ball has a distinct label on it, and the balls are indistinguishable if they are identical. The same also applies to the bins.

Three restrictions on the functions, with two restrictions on each of the domain and the range, together give us twelve counting problems, called the Twelvefold Way.

The following table gives the solutions to the counting problems.

Elements of $\displaystyle{ N }$ Elements of $\displaystyle{ M }$ Any $\displaystyle{ f }$ Injective (1-1) $\displaystyle{ f }$ Surjective (on-to) $\displaystyle{ f }$
distinguishable distinguishable $\displaystyle{ m^n\, }$ $\displaystyle{ \left(m\right)_n }$ $\displaystyle{ m!\left\{{n\atop m}\right\}\, }$
indistinguishable distinguishable $\displaystyle{ \left({m\choose n}\right) }$ $\displaystyle{ {m\choose n} }$ $\displaystyle{ {n-1\choose m-1} }$
distinguishable indistinguishable $\displaystyle{ \sum_{k=1}^m \left\{{n\atop k}\right\} }$ $\displaystyle{ \begin{cases}1 & \mbox{if }n\le m\\ 0& \mbox{if }n\gt m\end{cases} }$ $\displaystyle{ \left\{{n\atop m}\right\}\, }$
indistinguishable indistinguishable $\displaystyle{ \sum_{k=1}^m p_k(n) }$ $\displaystyle{ \begin{cases}1 & \mbox{if }n\le m\\ 0& \mbox{if }n\gt m\end{cases} }$ $\displaystyle{ p_m(n)\, }$

In the Volume 4A of Don Knuth's TAOCP, the twelvefold way is presented as the problems of counting the ways of assigning $\displaystyle{ n }$ balls into $\displaystyle{ m }$ bins. The domain $\displaystyle{ N }$ corresponds to a set of $\displaystyle{ n }$ balls, the range $\displaystyle{ M }$ corresponds to a set of $\displaystyle{ m }$ bins, and each function corresponds to an assignment of $\displaystyle{ n }$ balls into $\displaystyle{ m }$ bins. Balls (or bins) are distinguishable if they are distinct and are indistinguishable if they are identical. An injective function corresponds to an assignment with at most one ball in each bin, and a surjective function corresponds to an assignment with at least one ball(s) in each bin.

balls per bin unrestricted ≤ 1 ≥ 1
$\displaystyle{ n }$ distinct balls,
$\displaystyle{ m }$ distinct bins
$\displaystyle{ n }$-tuples
of $\displaystyle{ m }$ things
$\displaystyle{ n }$-permutations
of $\displaystyle{ m }$ things
partition of $\displaystyle{ [n] }$
into $\displaystyle{ m }$ ordered parts
$\displaystyle{ n }$ identical balls,
$\displaystyle{ m }$ distinct bins
$\displaystyle{ n }$-combinations of $\displaystyle{ [m] }$
with repetitions
$\displaystyle{ n }$-combinations of $\displaystyle{ [m] }$
without repetitions
$\displaystyle{ m }$-compositions
of $\displaystyle{ n }$
$\displaystyle{ n }$ distinct balls,
$\displaystyle{ m }$ identical bins
partitions of $\displaystyle{ [n] }$
into $\displaystyle{ \le m }$ parts
$\displaystyle{ n }$ pigeons
into $\displaystyle{ m }$ holes
partitions of $\displaystyle{ [n] }$
into $\displaystyle{ m }$ parts
$\displaystyle{ n }$ identical balls,
$\displaystyle{ m }$ identical bins
partitions of $\displaystyle{ n }$
into $\displaystyle{ \le m }$ parts
$\displaystyle{ n }$ pigeons
into $\displaystyle{ m }$ holes
partitions of $\displaystyle{ n }$
into $\displaystyle{ m }$ parts

## Reference

• Stanley, Enumerative Combinatorics, Volume 1, Chapter 1.