Sie sind auf Seite 1von 10

MATH 261

Enumeration

3. Balls and Boxes

Balls and Boxes

We have looked at dierent examples, but for this section we will stick with one: balls and boxes. We have r balls and n boxes. We want count the number of ways to put the balls in the boxes. Of course it will not be quite that easy. We will need to gure out how to deal with the following situations: (i) Sometimes we can distinguish the balls and sometimes we cannot. (ii) Sometimes we can distinguish the boxes and sometimes we cannot. We already know how to do this if the boxes are distinguishable (imagine we select a box by throwing a ball into it). If the balls are also distinguishable then this is just ordered selection with repetition. If the balls are indistinguishable then this is just unordered selection with repetition. Balls distinguishable Boxes distinguishable Boxes indistinguishable nr (2.5) ? Balls indistinguishable
n +r 1 r

(2.26) ?

Table 2: Solutions to the balls in boxes problems. Now we will examine how to deal with indistinguishable boxes. Example 3.1. How many ways can we place three balls (distinguishable) into two boxes (indistinguishable)? Let us label our balls {1, 2, 3}. Let us label the boxes b1 and b2 initially. Now we can list all possible ways to do this: (1) (2) (3) (4) b1 b1 b1 b1 1 2 1 1 2 3 3 2 3 b2 b2 b2 b2 1 2 3 1

MATH 261

Enumeration

3. Balls and Boxes

(5) (6) (7) (8)

b1 b1 b1 b1

1 2 3 b2

b2 b2 b2 1

2 1 1 2

3 3 2 3

Now if the boxes are indistinguishable then option 1 and 8 are equivalent. This is because if the labels are removed, we can rearrange the boxes to make option 1 look like option 8. Also equivalent are: options 2 and 5; 3 and 6; and 4 and 7. Hence there are only 4 ways to place three balls (distinguishable) into two boxes (indistinguishable). These are: (1) (2) (3) (4) 1 2 1 1 2 3 3 2 3 1 2 3

3.1

Stirling numbers of the second kind.

The ideas can be developed further. Denition 3.2. A partition of {1, . . . , r } into k parts is a collection of k non-empty sets that are pairwise disjoint, and whose union is equal to {1, . . . , r }. The parts of the partition are also called blocks. Example 3.3. There is one partition of {1, 2, 3} into one part: namely {{1, 2, 3}}. (Note that this is a collection of one set, thus it is a set containing a set.) There are three partitions of {1, 2, 3} into two parts: {{1}, {2, 3}}, {{2}, {1, 3}}, and {{3}, {1, 2}}.

Finally, there is one partition of {1, 2, 3} into three parts: {{1}, {2}, {3}}. 2

MATH 261

Enumeration

3. Balls and Boxes

Denition 3.4. Suppose that r is a positive integer and 1 k r . The number of partitions of {1, . . . , r } into k parts is said to be a Stirling number of the second kind, and is denoted S (r, k ). It turns out that Stirling numbers of the second kind provide an answer to certain balls and boxes problems. Proposition 3.5. There are S (r, n) ways to distribute r distinguishable balls into n indistinguishable boxes so that each box contains at least one ball. Proof. A distribution is just the same as a partition of {1, . . . , r }. Proposition 3.6. The number of ways of distributing r distinguishable balls into n indistinguishable boxes is
n

S (r, 1) + S (r, 2) + + S (r, n) =

S (r, i).
i=1

Proof. We simply sum over the number of non-empty boxes, and apply Proposition 3.5. This answer is perhaps not very satisfying. We have really just redened the problem to one of computing S (r, k ). What can we nd out about these Stirling numbers? Proposition 3.7. If r is a positive integer then S (r, 1) = S (r, r ) = 1. Proof. The only partition of {1, . . . , r } into 1 part is {{1, 2, . . . , r }}. The only partition of {1, . . . , r } into r parts is {{1}, {2}, . . . , {r }}. Just like the binomial coecients, Stirling numbers also obey a recurrence relation. Proposition 3.8. Suppose that r > 1 is an integer, and 1 < k < r . Then S (r, k ) = S (r 1, k 1) + kS (r 1, k). Proof. Consider the partitions of {1, . . . , r } into k parts. There are two types of such partitions: those where r is contained in a block by itself i.e. {r } is one of the blocks, and those where it is not. If we have a partition of the rst type, we can construct a partition of {1, . . . , r 1} into k 1 parts by simply removing the block {r }. This is a one-to-one correspondence between partitions of the rst type, and partitions of {1, . . . , r 1} into k 1 parts. Thus the number of partitions of the rst type is S (r 1, k 1). 3

MATH 261

Enumeration

3. Balls and Boxes

Now we consider partitions of the second type, where r is contained in a block with other element(s). By deleting r , we produce a partition of {1, . . . , r 1} into k parts. But there are k partitions that would have produced the same partition of {1, . . . , r 1} after deleting r , because r might have been contained in any of the k blocks. Therefore the number of partitions of the second type is kS (r 1, k). The result follows. By using Propositions 3.7 and 3.8, we can construct a triangle of Stirling numbers of the second type.

1 1 1 1 1 1 1 63 31 301 15 90 350 7 25 65 140 3 6 10 15 21 1 1 1 1 1 1

The rows of this triangle are sequence A008277. Now at least we can compute S (r, k ). However the computation can be rather tedious if r is large. The problem is that there is no nice formula for these numbers (we will use some later techniques to produce a direct formula but it is not as simple as that for n r ). Example 3.9. We have 10 distinguishable balls, and 6 boxes. How many ways are there to put the balls into the boxes, ensuring that every box gets at least one ball, if: (i) the boxes are indistinguishable? (ii) 3 boxes are blue and 3 boxes are red but they are otherwise indistinguishable? (i) This is just the number of partitions of the balls. Hence there are S (10, 6) ways it can be done. (ii) We can solve this problem by breaking it down into cases depending on how many balls are in the blue boxes. Let i be the number of balls in the blue boxes. Each blue box must have a ball so i 3. Each red box must also have a ball so i 7. Now we can choose i balls to go into the blue boxes in 10 i ways. For each choice, there are S (i, 3) possible ways of 4

MATH 261

Enumeration

3. Balls and Boxes

distributing the balls into the blue boxes. Further there are S (10 i, 3) ways of distributing the remaining balls into the red boxes. Thus for a xed i we have 10 i S (i, 3) S (10 i, 3) ways. To complete the problem we need to sum over all possible values of i. This leads us to conclude that the total number of ways is:
7 i=3

10 S (i, 3) S (10 i, 3) i

(ii) alternative. Choose a distribution of (i) and then choose 3 boxes to colour blue. Hence there are 6 3 S (10, 6) ways.

3.2

Integer partitions

We will now consider the case when both balls and boxes are indistinguishable. This is related to the following problem. How many solutions are there to an equation of the form x1 + + xn = r , where x1 x2 . . . xn 1? Example 3.10. How many solutions are there if r = 7 and n = 3? If we list all solutions, we see that there are only 4. x1 = 5, x2 = 1, x3 = 1 or simply 5 + 1 + 1 4+2+1 3+3+1 3+2+2 Denition 3.11. A solution to x1 + + xn = r in which x1 , . . . , xn are positive integers satisfying x1 x2 xn 1 is known as an integer partition of r with n parts. Do not confuse the integer partitions of Denition 3.11 with the partitions of Denition 3.2. They are dierent things. Example 3.12. There are ve integer partitions of 8 into 4 parts. They are 5+1+1+1, 4+2+1+1, 3+3+1+1, 3+2+2+1, and 2+2+2+2.

Denition 3.13. Suppose that r is a positive integer, and that 1 n r . The number of integer partitions of r with n parts is denoted p(r, n). Numbers of the form p(r, n) are called partition numbers. 5

MATH 261

Enumeration

3. Balls and Boxes

Proposition 3.14. There are p(r, n) ways to distribute r indistinguishable balls into n indistinguishable boxes so that each box contains at least one ball. Proof. Let xi denote the number of balls in box i. Then each xi is a positive integer. Since the boxes can be arranged in any order we like, we can assume that x1 x2 xn . Now there is an obvious one-to-one correspondence between distributions of balls and integer partitions of r . Corollary 3.15. The number of dierent ways of distributing r indistinguishable balls into n indistinguishable boxes is:
n

p(r, 1) + p(r, 2) + + p(r, n) =

p(r, i).
i=1

Proof. We sum over the number of boxes that are non-empty, and apply Proposition 3.14. We can now state, in Table 3, a solution to all the variants of the balls in boxes problem. Balls distinguishable Boxes distinguishable Boxes indistinguishable nr (2.5) (3.6) Balls indistinguishable
n +r 1 r n i=1 p(r, i)

(2.26) (3.15)

n i=1 S (r, i)

Table 3: Solutions to the balls in boxes problems. The next result is easy to prove. Proposition 3.16. Suppose that r is a positive integer. Then p(r, 1) = p(r, r ) = 1. As with the Stirling numbers, there is a recurrence relation that governs the partition numbers. Proposition 3.17. Suppose that r > 1 is an integer, and 1 < k < r . Then p(r, k ) = p(r 1, k 1) + p(r k, k).

MATH 261

Enumeration

3. Balls and Boxes

Proof. Consider the integer partitions of r with k parts. We divide these into two sets, according to whether xk = 1 or not. The number of integer partitions with xk = 1 is equal to the number of solutions to x1 + + xk1 = r 1, where x1 , . . . , xk1 are positive integers satisfying x1 x2 xk1 . This is equal to p(r 1, k 1). Now consider an integer partition with x1 x2 xk > 1. By subtracting one from each variable xi , we create a one-to-one correspondence with integer partitions of r k into k parts. The result follows. Using Propositions 3.16 and 3.17, we can create a triangle of partition numbers. 1 1 1 1 1 1 1 1 4 3 5 3 4 5 2 3 3 3 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1

Entry number k in row number r is p(r, k ). The rows of this triangle are sequence A008284. Example 3.18. We have 10 indistinguishable balls, and 6 boxes. How many ways are there to put the balls into the boxes, ensuring that every box gets at least one ball, if: (i) the boxes are indistinguishable? (ii) 3 boxes are blue and 3 boxes are red but they are otherwise indistinguishable? (i) This is just the number of integer partitions of the balls. Hence there are p(10, 6) ways it can be done. (ii) We can solve this problem by breaking it down into cases depending on how many balls are in the blue boxes. Let i be the number of balls in the blue boxes. Each blue box must have a ball so i 3. Each red box must also have a ball so i 7. Now we do not need to worry about how we choose the balls to go into the blue boxes, because the balls are indistinguishable. For each choice of i, there are p(i, 3) possible ways of distributing the balls into the blue boxes. Further there are p(10 i, 3) ways 7

MATH 261

Enumeration

3. Balls and Boxes

of distributing the remaining balls into the red boxes. Thus for a xed i we have p(i, 3) p(10 i, 3) ways. To complete the problem we need to sum over all possible values of i. This leads us to conclude that the total number of ways is:
7 i=3

p(i, 3) p(10 i, 3) = 129

(ii) Note that the alternative approach to solving the similar problem of Example 3.9 does not work in this case! If we choose a distribution of (i) and then choose 3 boxes to colour blue we get 6 3 p(10, 6) = 700 ways. You should gure out why there are over-counts with this approach.

3.3

One-one and onto functions

While balls and boxes provide a useful way to visualise these combinatorial problems, what we are really doing is counting functions. We are counting functions from the set of balls to the set of boxes. The conditions of making the balls indistinguishable or the boxes indistinguishable reduce the number of functions. We can also consider other restrictions such as: (i) Sometimes no box can have more than one ball. (ii) Sometimes no box can be left empty. Condition (i) can be interpreted as counting one-one functions and condition (ii) as counting onto functions. The analogous results for condition (i) are relatively simple. If the boxes are distinguishable, then the problem becomes ordered selection and unordered selection without repetition. If the boxes are indistinguishable, then there can only be one possible solution provided r n. Balls distinguishable Boxes distinguishable Boxes indistinguishable P (n, r ) (2.9) 1 Balls indistinguishable
n r

(2.18) 1

Table 4: Solutions to the balls in boxes problems, with at most one ball per box (assume n r ). 8

MATH 261

Enumeration

3. Balls and Boxes

For the case of onto functions we have already solved two of the problems. If the boxes are indistinguishable, then we can use Stirling numbers to solve the case when balls are distinguishable and partition numbers to solve the case when balls are indistinguishable. Our remaining two cases are as follows:
r 1 Proposition 3.19. There are n 1 ways of placing r indistinguishable balls in n distinguishable boxes so that no box is empty.

Proof. We have n boxes, as the balls are indistinguishable rst we place a ball in each box. Now we have r n balls left. We distribute these balls every possible way. Using Proposition 2.26 we see that the number of possibilities is: (r n) + n 1 rn = r1 rn = r1 r 1 (r n) = r1 n1

Proposition 3.20. There are n!S (r, n) ways of placing r distinguishable balls in n distinguishable boxes so that no box is empty. Proof. If the boxes are indistinguishable, then we know that there are S (r, n) ways to do this. But now we just have to label the boxes. This can be done n! ways so by the rule of product we have n!S (r, n) ways to do this. These results are summarised in the Table 5. Balls distinguishable Boxes distinguishable Boxes indistinguishable n!S (r, n) (3.20) S (r, n) (3.5) Balls indistinguishable
r 1 n 1

(3.19) (3.14)

p(r, n)

Table 5: Solutions to the balls in boxes problems, with non-empty boxes. Example 3.21. We have balls numbered from 1 to 12. We have 4 identical boxes. (i) How many ways are there to put the balls into the boxes if every box must get a ball?

MATH 261

Enumeration

3. Balls and Boxes

(ii) How many ways are there to put the balls into the boxes if every box must get a ball, and no box can have both even and odd numbered balls? (i) From Table 5 we see that the answer is S (12, 4). (ii) This can be solved by dividing into cases based on the number of boxes that have balls with even numbers. If one box has them all, then the odd balls can be placed in the remaining boxes in S (6, 3) ways. If two boxes have them, then the even balls can be placed in these boxes in S (6, 2) ways and the odd balls in the remaining boxes S (6, 2) ways. Finally, if the even balls are in three boxes, then this can be done in S (6, 3) ways and the odd balls must be placed in the remaining box. Hence the total number of ways is 2 S (6, 3) + (S (6, 2))2 . 3.3.1 The 12-fold way

Table 6 summarises the results of this section in terms of counting functions. This table is known as the 12-fold way. All functions X Y X Y X Y X Y distinguishable distinguishable indistinguishable distinguishable distinguishable indistinguishable indistinguishable indistinguishable nr
n +r 1 r n i=1 S (r, i) n i=1 p(r, i)

All one-one functions P (n, r )


n r

All onto functions n!S (r, n)


r 1 n 1

1 if r n 0 otherwise 1 if r n 0 otherwise

S (r, n) p(r, n)

Table 6: Number of functions f : X Y meeting dierent criteria. r = |X | and n = |Y |.

10

Das könnte Ihnen auch gefallen