组合数学 (Fall 2024)/Basic enumeration

From TCS Wiki
Jump to navigation Jump to search

Basic Enumeration

The three basic rules for enumeration are:

  • The sum rule: for any disjoint finite sets S and T, the cardinality of the union |ST|=|S|+|T|.
  • The product rule: for any finite sets S and T, the cardinality of the Cartesian product |S×T|=|S||T|.
  • The bijection rule: if there exists a bijection between finite sets S and T, then |S|=|T|.

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

Tuples

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

It is not very hard to see that this number is mn. That is, |[m]n|=mn.

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

  • The product rule: for any finite sets S and T, the cardinality of the Cartesian product |S×T|=|S||T|.


To count the size of [m]n, we write [m]n=[m]×[m]n1, thus |[m]n|=m|[m]n1|. Solving the recursion, we have that |[m]n|=mn.

Functions

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

We claim that this is the same as counting the number of n-tuples of [m]. To see this, for any f:[n][m], we define a tuple vf[m]n by letting vf(i)=f(i1) for every i=1,2,,n. It is easy to verify that v defines a bijection (a 1-1 correspondence) between {f:[n][m]} and [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 S and T, then |S|=|T|.

Applying this rule, we have that the number of functions from [n] to [m] equals the number of tuples in [m]n, which is mn as we proved previously.

Subsets

We count the number of subsets of a set.

LetS={x1,x2,,xn} be an n-element set, or n-set for short. Let 2S={TTS} denote the set of all subset of S. 2S is called the power set of S.

We give a combinatorial proof that |2S|=2n. We observe that every subset T2S corresponds to a unique bit-vector v{0,1}S, such that each bit vi indicates whether xiS. Formally, define a map ϕ:2S{0,1}n by ϕ(T)=(v1,v2,,vn), where

vi={1if xiT0if xiT.

The map ϕ is a bijection. The proof that ϕ is a bijection is left as an exercise.

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


There are two elements of the proof:

  • Find a 1-1 correspondence between subsets of an n-set and 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 U can be represented by an array of |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 |2S|=2n. The proof needs another basic counting rule: "the sum rule".

  • The sum rule: for any disjoint finite sets S and T, the cardinality of the union |ST|=|S|+|T|.


Define the function f(n)=|2Sn|, where Sn={x1,x2,,xn} is an n-set. Our goal is to compute f(n). We prove the following recursion for f(n).

Lemma
f(n)=2f(n1).
Proof.

Fix an element xn, let U be the set of subsets of Sn that contain xn and let V be the set of subsets of Sn that do not contain xn. It is obvious that U and V are disjoint (i.e. UV=) and 2Sn=UV, because any subset of Sn either contains xn or does not contain xn but not both.

Applying the sum rule,

f(n)=|UV|=|U|+|V|.

The next observation is that |U|=|V|=f(n1), because V is exactly the 2Sn1, and U is the set resulting from adding xn to every member of 2Sn1. Therefore,

f(n)=|U|+|V|=f(n1)+f(n1)=2f(n1).

The elementary case f(0)=1, because has only one subset . Solving the recursion, we have that |2S|=f(n)=2n.

Subsets of fixed size

We then count the number of subsets of fixed size of a set. Again, let S={x1,x2,,xn} be an n-set. We define (Sk) to be the set of all k-elements subsets (or k-subsets) of S. Formally, (Sk)={TS|T|=k}. The set (Sk) is sometimes called the k-uniform of S.

We denote that (nk)=|(Sk)|. The notation (nk) is read "n choose k".

Theorem
(nk)=n(n1)(nk+1)k(k1)1=n!k!(nk)!.
Proof.

The number of ordered k-subsets of an n-set is n(n1)(nk+1). Every k-subset has k!=k(k1)1 ways to order it.

Some notations
  • n!, read "n factorial", is defined as that n!=n(n1)(n2)1, with the convention that 0!=1.
  • n(n1)(nk+1)=n!(nk)! is usually denoted as (n)k, read "n lower factorial k".

Binomial coefficient

The quantity (nk) is called a binomial coefficient.

Proposition
  1. (nk)=(nnk);
  2. k=0n(nk)=2n.
Proof.

1. We give two proofs for the first equation:

(1) (numerical proof)
(nk)=n!k!(nk)!=(nnk).
(2) (combinatorial proof)
Choosing k elements from an n-set is equivalent to choosing the nk elements to leave out. Formally, every k-subset T(Sk) is uniquely specified by its complement ST(Snk), and the same holds for (nk)-subsets, thus we have a bijection between (Sk) and (Snk).

2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an n-element set S, it is obvious that we can enumerate all subsets of S by enumerating k-subsets for every possible size k, i.e. it holds that

2S=k=0n(Sk).

For different k, (Sk) are obviously disjoint. By the sum rule,

2n=|2S|=|k=0n(Sk)|=k=0n|(Sk)|=k=0n(nk).

(nk) 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)
(1+x)n=k=0n(nk)xk.
Proof.

Write (1+x)n as the product of n factors

(1+x)(1+x)(1+x).

The term xk is obtained by choosing x from k factors and 1 from the rest (nk) factors. There are (nk) ways of choosing these k factors, so the coefficient of xk is (nk).

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

Proposition
For n>0, the numbers of subsets of an n-set of even and of odd cardinality are equal.
Proof.

Set x=1 in the binomial theorem.

0=(11)n=k=0n(nk)(1)k=k even0kn(nk)k odd0kn(nk),

therefore

k even0kn(nk)=k odd0kn(nk).

For counting problems, what we care about are numbers. In the binomial theorem, a formal variable 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 n is an expression of n as an ordered sum of positive integers. A k-composition of n is a composition of n with exactly k positive summands.

Formally, a k-composition of n is a k-tuple (a1,a2,,ak){1,2,,n}k such that a1+a2++ak=n.

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

So the number of k-compositions of n equals the number of ways we put k1 bars "|" into n1 slots "", where each slot has at most one bar (because all the summands ai>0):

which is equal to the number of ways of choosing k1 slots out of n1 slots, which is (n1k1).

This graphic argument can be expressed as a formal proof. We construct a bijection between the set of k-compositions of n and ({1,2,,n1}k1) as follows.

Let ϕ be a mapping that given a k-composition (a1,a2,,ak) of n,

ϕ((a1,a2,,ak))={a1,a1+a2,a1+a2+a3,,a1+a2++ak1}={i=1jai|1j<k}.

ϕ maps every k-composition to a (k1)-subset of {1,2,,n1}. It is easy to verify that ϕ is a bijection, thus the number of k-compositions of n is (n1k1).


The number of k-compositions of n is equal to the number of solutions to x1+x2++xk=n in positive integers. This suggests us to relax the constraint and count the number of solutions to x1+x2++xk=n in nonnegative integers. We call such a solution a weak k-composition of n.

Formally, a weak k-composition of n is a tuple (x1,x2,,xk)[n+1]k such that x1+x2++xk=n.

Given a weak k-composition (x1,x2,,xk) of n, if we set yi=xi+1 for every 1ik, then yi>0 and

y1+y2++yk=(x1+1)+(x2+1)++(xk+1)=n+k,

i.e., (y1,y2,,yk) is a k-composition of n+k. It is easy to see that it defines a bijection between weak k-compositions of n and k-compositions of n+k. Therefore, the number of weak k-compositions of n is (n+k1k1).


We now count the number of solutions to x1+x2++xkn in nonnegative integers.

Let xk+1=n(x1+x2++xk). Then xk+10 and x1+x2++xk+xk+1=n. The problem is transformed to that counting the number of solutions to the above equation in nonnegative integers. The answer is (n+kk).

Multisets

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

Example
S={1,2,3,4}. All 3-combination without repetitions are
{1,2,3},{1,2,4},{1,3,4},{2,3,4}.
Allowing repetitions, we also include the following 3-combinations:
{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}

Combinations with repetitions can be formally defined as multisets. A multiset is a set with repeated elements. Formally, a multiset M on a set S is a function m:SN. For any element xS, the integer m(x)0 is the number of repetitions of x in M, called the multiplicity of x. The sum of multiplicities xSm(x) is called the cardinality of M and is denoted as |M|.

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

The set of all k-multisets on S is denoted ((Sk)). Assuming that n=|S|, denote ((nk))=|((Sk))|, which is the number of k-combinations of an n-set with repetitions.

Believe it or not: we have already evaluated the number ((nk)). If S={x1,x2,,xn}, let zi=m(xi), then ((nk)) is the number of solutions to z1+z2++zn=k in nonnegative integers, which is the number of weak n-compositions of k, which we have seen is (n+k1n1)=(n+k1k).


There is a direct combinatorial proof that ((nk))=(n+k1k).

Given a k-multiset 0a0a1ak1n1 on [n], then defining bi=ai+i, we see that {b0,b1,,bk1} is a k-subset of [n+k1]. Conversely, given a k-subset 0b0b1bk1n+k2 of [n+k1], then defining ai=bii, we have that {a0,a1,,ak1} is a k-multiset on [n]. Therefore, we have a bijection between (([n]k)) and ([n+k1]k).

Multinomial coefficients

The binomial coefficient (nk) may be interpreted as follows. Each element of an n-set is placed into two groups, with k elements in Group 1 and nk elements in Group 2. The binomial coefficient (nk) counts the number of such placements.

This suggests a generalization allowing more than two groups. Let (a1,a2,,am) be a tuple of nonnegative integers summing to n. Let (na1,a2,,am) denote the number of ways of assigning each element of an n-set to one of m groups G1,G2,,Gm so that exactly ai elements are assigned to Gi.

The binomial coefficient is just the case when there are two groups, and (nk)=(nk,nk). The number (na1,a2,,am) is called a multinomial coefficient. We can think of it as that n labeled balls are assigned to m labeled bins, and (na1,a2,,am) is the number of assignments such that the i-th bin has ai balls in it.

The multinomial coefficient can also be interpreted as the number of permutations of multisets. A permutation π of an n-set S can be defined in two equivalent ways:

  • a bijection π:SS;
  • a tuple π=(x1,x2,,xn)Sn such that all xi are distinct.

There are n! permutations of an n-set S.

A permutation of a multiset M is a tuple π=(x1,x2,,xn) such that every xiM appears in π for exactly m(xi) times, where m(xi) is the multiplicity of xi in 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 {a, i, i, l, l, m, m, n, o, t, u}.

Let M be a multiset of m distinct elements x1,x2,,xm such that xi has multiplicity ai in M. A permutation π of multiset M assigns n indices 1,2,,n to m groups, where each group corresponds to a distinct element xi, such that i is assigned to group j if πi=xj.

Therefore, (na1,a2,,am) is also the number of permutations of a multiset M with |M|=n such that M has m distinct elements whose multiplicities are given by a1,a2,,am.

Theorem
(na1,a2,,am)=n!a1!a2!am!.
Proof.

There are n! permutations of n objects. Assume that these n objects are the elements of an multiset M of m distinct elements with |M|=n and multiplicities a1,a2,,am. Since ai! permutations of object i do not change the permutation of the multiset M, every a1!a2!am! permutations of these n objects correspond to the same permutation of the multiset M. Thus, the number of permutations of M is n!a1!a2!am!.

We also have the Multinomial Theorem.

Theorem
(na1,a2,,am) is the coefficient of x1a1x2a2xmam in (x1+x2++xm)n.
Proof.

Write

(x1+x2++xm)n=(x1+x2++xm)(x1+x2++xm).

Each of the n factors corresponds to a distinct ball, and x1,x2,,xm correspond to m groups. The coefficient of x1a1x2a2xmam equals the number of ways to put ndistinct balls to m distinct groups so that group i receives ai balls, which is exactly our first definition of (na1,a2,,am).

Partitions of a set

A partition of finite set S is a collection P={S1,S2,,Sk} of subsets of S such that:

  • Si for every i;
  • SiSj= if ij (also called that blocks are pairwise disjoint);
  • S1S2Sk=S.

Each Si is called a block of partition P. We call P a k-partition of S if |P|=k.

Define {nk} to be the number of k-partitions of an n-set. Note that since a partition P is a set, the order of blocks S1,S2,,Sk is disregarded when counting k-partitions.

The number {nk} 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 {nk}. But we have the following recurrence:

Theorem
{nk}=k{n1k}+{n1k1}.
Proof.

To partition {1,2,,n} into k blocks,

  • we can partition {1,2,,n1} into k blocks and place n into one of the k blocks, which gives us k{n1k} ways to do so;
  • or we can partition {1,2,,n1} into k1 blocks and let {n} be a block by itself, which gives us {n1k1} ways to do so.

The partitions constructed by these two methods are different, since by the first method, n is always in a block of cardinality >1, and by the second method, {n} is always a block. So the cases are disjoint. And any k-partition of an n-set must be constructible by one of the two methods, thus by the sum rule,

{nk}=k{n1k}+{n1k1}.

Let Bn=k=1n{nk}, which gives the total number of partitions of an n-set. B(n) is called the Bell number.

Partitions of a number

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

A k-partition of a number n is a multiset {x1,x2,,xk} with xi1 for every element xi and x1+x2++xk=n.

We define pk(n) as the number of k-partitions of n.

For example, number 7 has the following partitions:

{7}p1(7)=1{1,6},{2,5},{3,4}p2(7)=3{1,1,5},{1,2,4},{1,3,3},{2,2,3}p3(7)=4{1,1,1,4},{1,1,2,3},{1,2,2,2}p4(7)=3{1,1,1,1,3},{1,1,1,2,2}p5(7)=2{1,1,1,1,1,2}p6(7)=1{1,1,1,1,1,1,1}p7(7)=1

Equivalently, we can also define that A k-partition of a number n is a k-tuple (x1,x2,,xk) with:

  • x1x2xk1;
  • x1+x2++xk=n.

pk(n) the number of integral solutions to the above system.

Let p(n)=k=1npk(n) be the total number of partitions of n. The function p(n) is called the partition number.

We now try to determine pk(n). Unfortunately, pk(n) does not have a nice closed form formula. We now give a recurrence for pk(n).

Proposition
pk(n)=pk1(n1)+pk(nk).
Proof.

Suppose that (x1,,xk) is a k-partition of n. Note that it must hold that

x1x2xk1.

There are two cases: xk=1 or xk>1.

Case 1.
If xk=1, then (x1,,xk1) is a distinct (k1)-partition of n1. And every (k1)-partition of n1 can be obtained in this way. Thus the number of k-partitions of n in this case is pk1(n1).
Case 2.
If xk>1, then (x11,,xk1) is a distinct k-partition of nk. And every k-partition of nk can be obtained in this way. Thus the number of k-partitions of n in this case is pk(nk).

In conclusion, the number of k-partitions of n is pk1(n1)+pk(nk), i.e.

pk(n)=pk1(n1)+pk(nk).

Use the above recurrence, we can compute the pk(n) for some decent n and k by computer simulation.

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

Theorem

For any fixed k,

pk(n)nk1k!(k1)!,

as n.

Proof.

Suppose that (x1,,xk) is a k-partition of n. Then x1+x2++xk=n and x1x2xk1.

The k! permutations of (x1,,xk) yield at most k! many k-compositions (the ordered sum of k positive integers). There are (n1k1) many k-compositions of n, every one of which can be yielded in this way by permuting a partition. Thus,

k!pk(n)(n1k1).

Let yi=xi+ki. That is, yk=xk,yk1=xk1+1,yk2=xk2+2,,y1=x1+k1. Then, it holds that

  • y1>y2>>yk1; and
  • y1+y2++yk=n+k(k1)2.

Each permutation of (y1,y2,,yk) yields a distinct k-composition of n+k(k1)2, because all yi are distinct. Thus,

k!pk(n)(n+k(k1)21k1).

Combining the two inequalities, we have

(n1k1)k!pk(n)(n+k(k1)21k1)k!.

The theorem follows.

Ferrers diagram

A partition of a number 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 (x1,x2,,xk) with that x1x2xk1 be a partition of n. Its Ferrers diagram consists of k rows, where the i-th row contains xi 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.

(6,4,4,2,1) conjugate: (5,4,3,3,1,1)

Clearly,

  • different partitions cannot have the same conjugate, and
  • every partition of n is the conjugate of some partition of n,

so the conjugation mapping is a permutation on the set of partitions of 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
  1. The number of partitions of n which have largest summand k, is pk(n).
  2. The number of n into k parts equals the number of partitions of nk into at most k parts. Formally,
pk(n)=j=1kpj(nk).
Proof.
  1. For every k-partition, the conjugate partition has largest part k. And vice versa.
  2. For a k-partition of n, remove the leftmost cell of every row of the Ferrers diagram. Totally k cells are removed and the remaining diagram is a partition of nk into at most k parts. And for a partition of nk into at most k parts, add a cell to each of the k rows (including the empty ones). This will give us a k-partition of n. It is easy to see the above mappings are 1-1 correspondences. Thus, the number of n into k parts equals the number of partitions of nk into at most k parts.

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 N and M be finite sets with |N|=n and |M|=m. We count the number of functions f:NM subject to different restrictions. There are three restrictions regarding the mapping f itself:

  1. f is an arbitrary function;
  2. f is an injection (one-to-one);
  3. f is a surjection (onto).

The elements of N and M can be regarded as distinguishable or indistinguishable. Think of N as a set of n balls and M as a set of m bins. A function f:NM is an assignment of the n balls into 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 N Elements of M Any f Injective (1-1) f Surjective (on-to) f
distinguishable distinguishable mn (m)n m!{nm}
indistinguishable distinguishable ((mn)) (mn) (n1m1)
distinguishable indistinguishable k=1m{nk} {1if nm0if n>m {nm}
indistinguishable indistinguishable k=1mpk(n) {1if nm0if n>m pm(n)

In the Volume 4A of Don Knuth's TAOCP, the twelvefold way is presented as the problems of counting the ways of assigning n balls into m bins. The domain N corresponds to a set of n balls, the range M corresponds to a set of m bins, and each function corresponds to an assignment of n balls into 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
n distinct balls,
m distinct bins
n-tuples
of m things
n-permutations
of m things
partition of [n]
into m ordered parts
n identical balls,
m distinct bins
n-combinations of [m]
with repetitions
n-combinations of [m]
without repetitions
m-compositions
of n
n distinct balls,
m identical bins
partitions of [n]
into m parts
n pigeons
into m holes
partitions of [n]
into m parts
n identical balls,
m identical bins
partitions of n
into m parts
n pigeons
into m holes
partitions of n
into m parts

Reference

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