# Combinatorics (Fall 2010)/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)\cdots 1}$ 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. A binomial is a polynomial with two terms ("poly-" means many, and "bi-" means two, like in "binary", "bipartite", etc). 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>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\leq k\leq n}{k{\text{ even}}}}{n \choose k}-\sum _{\overset {0\leq k\leq n}{k{\text{ odd}}}}{n \choose k},}$ therefore ${\displaystyle \sum _{\overset {0\leq k\leq n}{k{\text{ even}}}}{n \choose k}=\sum _{\overset {0\leq k\leq 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}>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{aligned}\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}^{j}a_{i}\,\,{\bigg |}\,\,1\leq j

${\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\leq i\leq k}$, then ${\displaystyle y_{i}>0}$ and

{\displaystyle {\begin{aligned}y_{1}+y_{2}+\cdots +y_{k}&=(x_{1}+1)+(x_{2}+1)+\cdots +(x_{k}+1)&=n+k,\end{aligned}}}

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}\leq n}$ in nonnegative integers.

Let ${\displaystyle x_{k+1}=n-(x_{1}+x_{2}+\cdots +x_{k})}$. Then ${\displaystyle x_{k+1}\geq 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{aligned}&\{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{aligned}}}

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)\geq 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({S \choose k}\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\leq a_{0}\leq a_{1}\leq \cdots \leq a_{k-1}\leq 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\leq b_{0}\leq b_{1}\leq \cdots \leq b_{k-1}\leq n+k-2}$ of ${\displaystyle [n+k-1]}$, then defining ${\displaystyle a_{i}=b_{i}-i}$, we have that ${\displaystyle \{b_{0},b_{1},\ldots ,b_{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=\{B_{1},B_{2},\ldots ,B_{k}\}}$ of subsets of ${\displaystyle S}$ such that:

• ${\displaystyle B_{i}\neq \emptyset }$ for every ${\displaystyle i}$;
• ${\displaystyle B_{i}\cap B_{j}=\emptyset }$ if ${\displaystyle i\neq j}$ (also called that blocks are pairwise disjoint);
• ${\displaystyle B_{1}\cup B_{2}\cup \cdots \cup B_{k}=S}$.

Each ${\displaystyle B_{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 S(n,k)}$ 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 B_{1},B_{2},\ldots ,B_{k}}$ is disregarded when counting ${\displaystyle k}$-partitions.

The number ${\displaystyle S(n,k)}$ 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 S(n,k)}$. But we have the following recurrence:

 Theorem ${\displaystyle S(n,k)=kS(n-1,k)+S(n-1,k-1)\,}$.
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 kS(n-1,k)}$ 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 S(n-1,k-1)}$ ways to do so. The permutation constructed by these two methods are different, since by the first method, ${\displaystyle n}$ is always in a block of cardinality ${\displaystyle >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 S(n,k)=kS(n-1,k)+S(n-1,k-1)}$.
${\displaystyle \square }$

Let ${\displaystyle B(n)=\sum _{k=1}^{n}S(n,k)}$, which gives the total number of partitions of an ${\displaystyle n}$-set. ${\displaystyle B(n)}$ is called the Bell number.

### Partitions of a number

For a positive integer ${\displaystyle n}$, we define a partition of ${\displaystyle n}$ into ${\displaystyle k}$ parts to be a sequence ${\displaystyle \lambda =(\lambda _{1},\lambda _{2},\ldots ,\lambda _{k})}$ of positive integers such that ${\displaystyle \lambda _{1}\geq \lambda _{2}\geq \cdots \lambda _{k}}$ and ${\displaystyle \sum _{i=1}^{k}\lambda _{i}=n}$.

A partition of ${\displaystyle n}$ into ${\displaystyle k}$ parts corresponds to a way of representing ${\displaystyle n}$ as a sum ${\displaystyle \lambda _{1}+\lambda _{2}+\cdots +\lambda _{k}}$ of ${\displaystyle k}$ positive integers, disregarding the order of summands. (Note the difference from ${\displaystyle k}$-composition, for which we care about the order of summands.)

Let ${\displaystyle p_{k}(n)}$ be the number of partitions of ${\displaystyle n}$ into ${\displaystyle k}$ parts. We will revisit this number in future.

## 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!S(n,m)\,}$
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}S(n,k)}$ ${\displaystyle {\begin{cases}1&{\mbox{if }}n\leq m\\0&{\mbox{if }}n>m\end{cases}}}$ ${\displaystyle S(n,m)\,}$
indistinguishable indistinguishable ${\displaystyle \sum _{k=1}^{m}p_{k}(n)}$ ${\displaystyle {\begin{cases}1&{\mbox{if }}n\leq m\\0&{\mbox{if }}n>m\end{cases}}}$ ${\displaystyle p_{m}(n)\,}$

In the fascicle version of Volume 4 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 \leq 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 \leq 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.