Skip to main content
\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)
Mathematics LibreTexts

1.4: Bell Numbers

We begin with a definition:

Definition: Partition

partition of a set \(S\) is a collection of non-empty subsets \(A_i\subseteq S\), \(1\le i\le k\) (the parts of the partition), such that \(\bigcup_{i=1}^k A_i=S\) and for every \(i\not=j\), \(A_i\cap A_j=\emptyset\).

Example \(\PageIndex{1}\):

The partitions of the set \(\{a,b,c\}\) are \(\{\{a\},\{b\},\{c\}\}\), \(\{\{a,b\},\{c\}\}\), \(\{\{a,c\},\{b\}\}\), \(\{\{b,c\},\{a\}\}\), and \(\{\{a,b,c\}\}\).

 

Partitions arise in a number of areas of mathematics. For example, if \(\equiv\) is an equivalence relation on a set \(S\), the equivalence classes of $\equiv$ form a partition of $S$. Here we consider the number of partitions of a finite set $S$, which we might as well take to be \([n]=\{1,2,3,\ldots,n\}\), unless some other set is of interest. We denote the number of partitions of an $n$-element set by $B_n$; this numbers are the Bell numbers. From the example above, we see that $B_3=5$. For convenience we let $B_0=1$. It is quite easy to see that $B_1=1$ and $B_2=2$.

There are no known simple formulas for \(B_n\), so we content ourselves with a recurrence relation.

Theorem 1.4.3: Bell numbers

The Bell numbers satisfy

$$ B_{n+1} = \sum_{k=0}^n {n\choose k} B_k. $$

 

Proof

Consider a partition of $S=\{1,2,\ldots,n+1\}$, $A_1$,…,$A_m$. We may suppose that $n+1$ is in $A_1$, and that $|A_1|=k+1$, for some $k$, $0\le k\le n$. Then $A_2$,…,$A_{m}$ form a partition of the remaining $n-k$ elements of $S$, that is, of $S\backslash A_1$. There are $B_{n-k}$ partitions of this set, so there are $B_{n-k}$ partitions of $S$ in which one part is the set $A_1$. There are ${n\choose k}$ sets of size $k+1$ containing $n+1$, so the total number of partitions of $S$ in which $n+1$ is in a set of size $k+1$ is ${n\choose k}B_{n-k}$. Adding up over all possible values of $k$, this means $$ \eqalignno{ B_{n+1} &= \sum_{k=0}^n {n\choose k} B_{n-k}.& (1.4.1)\cr } $$ We may rewrite this, using theorem 1.3.3, as $$ B_{n+1} = \sum_{k=0}^n {n\choose n-k} B_{n-k}, $$ and then notice that this is the same as the sum $$ B_{n+1} = \sum_{k=0}^n {n\choose k} B_k, $$ written backwards.

\(\square\)

Example \(\PageIndex{1}\):

We apply the recurrence to compute the first few Bell numbers:

$$ \eqalign{ B_1&=\sum_{k=0}^0 {0\choose 0}B_0 = 1\cdot 1 = 1\cr B_2&=\sum_{k=0}^1 {1\choose k}B_k = {1\choose 0}B_0 + {1\choose 1}B_1 = 1\cdot 1+1\cdot 1 =1+1 =2\cr B_3&=\sum_{k=0}^2 {2\choose k}B_k = 1\cdot 1 + 2\cdot 1 + 1\cdot 2 = 5\cr B_4&=\sum_{k=0}^3 {3\choose k}B_k = 1\cdot 1 + 3\cdot 1 + 3\cdot 2 + 1\cdot 5 = 15\cr } $$

 

The Bell numbers grow exponentially fast; the first few are 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597, 27644437.

The Bell numbers turn up in many other problems; here is an interesting example. A common need in some computer programs is to generate a random permutation of $1,2,3,\ldots,n$, which we may think of as a shuffle of the numbers, visualized as numbered cards in a deck. Here is an attractive method that is easy to program: Start with the numbers in order, then at each step, remove one number at random (this is easy in most programming languages) and put it at the front of the list of numbers. (Viewed as a shuffle of a deck of cards, this corresponds to removing a card and putting it on the top of the deck.) How many times should we do this? There is no magic number, but it certainly should not be small relative to the size of $n$. Let's choose $n$ as the number of steps.

We can write such a shuffle as a list of $n$ integers, $(m_1,m_2,\ldots,m_n)$. This indicates that at step $i$, the number $m_i$ is moved to the front.

Example \(\PageIndex{1}\):

Let's follow the shuffle $(3,2,2,4,1)$: $$ \eqalign{ (3)&:\quad 3 1 2 4 5\cr (2)&:\quad 2 3 1 4 5\cr (2)&:\quad 2 3 1 4 5\cr (4)&:\quad 4 2 3 1 5\cr (1)&:\quad 1 4 2 3 5\cr } $$

 

Note that we allow "do nothing'' moves, removing the top card and then placing it on top. The number of possible shuffles is then easy to count: there are $n$ choices for the card to remove, and this is repeated $n$ times, so the total number is $n^n$. (If we continue a shuffle for $m$ steps, the number of shuffles is $n^m$.) Since there are only $n!$ different permutations of $1,2,\ldots,n$, this means that many shuffles give the same final order.

Here's our question: how many shuffles result in the original order?

 

Example 1.4.6 These shuffles return to the original order: $(1,1,1,1,1)$, $(5,4,3,2,1)$, $(4,1,3,2,1)$.

 

Theorem 1.4.7

The number of shuffles of $[n]$ that result in the original sorted order is \(B_n\).

Proof

Since we know that $B_n$ counts the number of partitions of $\{1,2,3,\ldots,n\}$, we can prove the theorem by establishing a 1–1 correspondence between the shuffles that leave the deck sorted and the partitions. Given a shuffle $(m_1,m_2,\ldots,m_n)$, we put into a single set all $i$ such that $m_i$ has a single value. For example, using the shuffle $(4,1,3,2,1)$, Since $m_2=m_5$, one set is $\{2,5\}$. All the other values are distinct, so the other sets in the partition are $\{1\}$, $\{3\}$, and $\{4\}$.

Note that every shuffle, no matter what the final order, produces a partition by this method. We are only interested in the shuffles that leave the deck sorted. What we now need is to show that each partition results from exactly one such shuffle.

Suppose we have a partition with $k$ parts. If a shuffle leaves the deck sorted, the last entry, $m_n$, must be 1. If the part containing $n$ is $A_1$, then it must be that $m_i=1$ if and only if $i\in A_1$. If $k=1$, then the only part contains all of $\{1,2,\ldots,n\}$, and the shuffle must be $(1,1,1,\ldots,1)$.

If $k>1$, the last move that is not 1 must be 2, since 2 must end up immediately after 1. Thus, if $j_2$ is the largest index such that $j_2\notin A_1$, let $A_2$ be the part containing $j_2$, and it must be that $m_i=2$ if and only if $i\in A_2$. We continue in this way: Once we have discovered which of the $m_i$ must have values $1,2,\ldots,p$, let $j_{p+1}$ be the largest index such that $j_{p+1}\notin A_1\cup\cdots\cup A_p$, let $A_{p+1}$ be the part containing $j_{p+1}$, and then $m_i=p+1$ if and only if $i\in A_{p+1}$. When $p=k$, all values $m_i$ have been determined, and this is the unique shuffle that corresponds to the partition.

$\square$

Example 1.4.8 Consider the partition $\{\{1,5\},\{2,3,6\},\{4,7\}\}$. We must have $m_7=m_4=1$, $m_6=m_3=m_2=2$, and $m_5=m_1=3$, so the shuffle is $(3,2,2,1,3,2,1)$.

 

Returning to the problem of writing a computer program to generate a partition: is this a good method? When we say we want a random permutation, we mean that we want each permutation to occur with equal probability, namely, $1/n!$. Since the original order is one of the permutations, we want the number of shuffles that produce it to be exactly $n^n/n!$, but $n!$ does not divide $n^n$, so this is impossible. The probability of getting the original permutation is $B_n/n^n$, and this turns out to be quite a bit larger than $1/n!$. Thus, this is not a suitable method for generating random permutations.

The recurrence relation above is a somewhat cumbersome way to compute the Bell numbers. Another way to compute them is with a different recurrence, expressed in the Bell triangle, whose construction is similar to that of Pascal's triangle: $$\matrix{ A_{1,1}\cr A_{2,1}&A_{2,2}\cr A_{3,1}&A_{3,2}&A_{3,3}\cr A_{4,1}&A_{4,2}&A_{4,3}&A_{4,4}\cr} \qquad\matrix{ 1\cr 1&2\cr 2&3&5\cr 5&7&10&15\cr} $$ The rule for constructing this triangle is: $A_{1,1}=1$; the first entry in each row is the last entry in the previous row; other entries are $A_{n,k}=A_{n,k-1}+A_{n-1,k-1}$; row $n$ has $n$ entries. Both the first column and the diagonal consist of the Bell numbers, with $A_{n,1}=B_{n-1}$ and $A_{n,n}=B_n$.

$A_{n,k}$ may be interpreted as the number of partitions of $\{1,2,\ldots,n+1\}$ in which $\{k+1\}$ is the singleton set with the largest entry in the partition. For example, $A_{3,2}=3$; the partitions of $3+1=4$ in which $2+1=3$ is the largest number appearing in a singleton set are $\{\{1\},\{2,4\},\{3\}\}$, $\{\{2\},\{1,4\},\{3\}\}$, and $\{\{1,2,4\},\{3\}\}$.

To see that this indeed works as advertised, we need to confirm a few things. First, consider $A_{n,n}$, the number of partitions of $\{1,2,\ldots,n+1\}$ in which $\{n+1\}$ is the singleton set with the largest entry in the partition. Since $n+1$ is the largest element of the set, all partitions containing the singleton $\{n+1\}$ satisfy the requirement, and so the $B_n$ partitions of $\{1,2,\ldots,n\}$ together with $\{n+1\}$ are exactly the partitions of interest, that is, $A_{n,n}=B_n$.

Next, we verify that under the desired interpretation, it is indeed true that $A_{n,k}=A_{n,k-1}+A_{n-1,k-1}$ for $k>1$. Consider a partition counted by $A_{n,k-1}$. This contains the singleton $\{k\}$, and the element $k+1$ is not in a singleton. If we interchange $k$ and $k+1$, we get the singleton $\{k+1\}$, and no larger element is in a singleton. This gives us partitions in which $\{k+1\}$ is a singleton and $\{k\}$ is not. Now consider a partition of $\{1,2,\ldots,n\}$ counted by $A_{n-1,k-1}$. Replace all numbers $j>k$ by $j+1$, and add the singleton $\{k+1\}$. This produces a partition in which both $\{k+1\}$ and $\{k\}$ appear. In fact, we have described how to produce each partition counted by $A_{n,k}$ exactly once, and so $A_{n,k}=A_{n,k-1}+A_{n-1,k-1}$.

Finally, we need to verify that $A_{n,1}=B_{n-1}$. We know that $A_{1,1}=1=B_0$. Now we claim that for $n>1$, $$ A_{n,1}=\sum_{k=0}^{n-2}{n-2\choose k}A_{k+1,1}. $$ In a partition counted by $A_{n,1}$, 2 is the largest element in a singleton, so $\{n+1\}$ is not in the partition. Choose any $k\ge 1$ elements of $\{3,4,\ldots,n\}$ to form the set containing $n+1$. There are $A_{n-k-1,1}$ partitions of the remaining $n-k$ elements in which 2 is the largest element in a singleton. This accounts for ${n-2\choose k}A_{n-k-1,1}$ partitions of $\{1,2,\ldots,n+1\}$, or over all $k$: $$ \sum_{k=1}^{n-2}{n-2\choose k}A_{n-k-1,1}= \sum_{k=1}^{n-2}{n-2\choose n-k-2}A_{n-k-1,1}= \sum_{k=0}^{n-3} {n-2\choose k}A_{k+1,1}. $$ We are missing those partitions in which 1 is in the part containing $n+1$. We may produce all such partitions by starting with a partition counted by $A_{n-1,1}$ and adding $n+1$ to the part containing 1. Now we have $$ A_{n,1} = A_{n-1,1}+\sum_{k=0}^{n-3} {n-2\choose k}A_{k+1,1}= \sum_{k=0}^{n-2} {n-2\choose k}A_{k+1,1}. $$ Although slightly disguised by the shifted indexing of the $A_{n,1}$, this is the same as the recurrence relation for the $B_n$, and so $A_{n,1}=B_{n-1}$ as desired.