Combinatorics (Fall 2010)/Basic enumeration: Difference between revisions

From TCS Wiki
Jump to navigation Jump to search
imported>WikiSysop
imported>WikiSysop
Line 2: Line 2:


== Basic Enumeration ==
== Basic Enumeration ==
The three basic rules for enumeration are:
*'''The sum rule''': for any '''''disjoint''''' finite sets <math>P</math> and <math>Q</math>, the cardinality of the union <math>|P\cup Q|=|P|+|Q|</math>.
*'''The product rule''': for any finite sets <math>P</math> and <math>Q</math>, the cardinality of the Cartesian product <math>|P\times Q|=|P|\cdot|Q|</math>.
*'''The bijection rule''': if there exists a bijection between finite sets <math>P</math> and <math>Q</math>, then <math>|P|=|Q|</math>.
Now we apply these rules to solve some basic enumeration problems.


=== Tuples ===
=== Tuples ===

Revision as of 09:05, 31 August 2010

Counting Problems

Basic Enumeration

The three basic rules for enumeration are:

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

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 P and Q, the cardinality of the Cartesian product |P×Q|=|P||Q|.


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 P and Q, then |P|=|Q|.

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 P and Q, the cardinality of the union |PQ|=|P|+|Q|.


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. 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)
(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 {b0,b1,,bk1} 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={B1,B2,,Bk} of subsets of S such that:

  • Bi for every i;
  • BiBj= if ij (also called that blocks are pairwise disjoint);
  • B1B2Bk=S.

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

Define S(n,k) to be the number of k-partitions of an n-set. Note that since a partition P is a set, the order of blocks B1,B2,,Bk is disregarded when counting k-partitions.

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

Theorem
S(n,k)=kS(n1,k)+S(n1,k1).
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 kS(n1,k) 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 S(n1,k1) ways to do so.

The permutation 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,

S(n,k)=kS(n1,k)+S(n1,k1).

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

Partitions of a number

For a positive integer n, we define a partition of n into k parts to be a sequence λ=(λ1,λ2,,λk) of positive integers such that λ1λ2λk and i=1kλi=n.

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

Let pk(n) be the number of partitions of n into k parts. We will revisit this number in future.

Ferrers diagram

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!S(n,m)
indistinguishable distinguishable ((mn)) (mn) (n1m1)
distinguishable indistinguishable k=1mS(n,k) {1if nm0if n>m S(n,m)
indistinguishable indistinguishable k=1mpk(n) {1if nm0if n>m pm(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 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.