13

I encountered this problem in my probability class, and we weren't able to solve it, so I would like to know the answer.

If you have $m$ balls and $n$ boxes, with $n < m$, and you insert the balls into the boxes randomly, what is the probability that all the boxes have at least one ball in it?

The problem doesn't specify if the balls are distinguishable or not, so you may assume either, so another question would be, if you assume they are distinguishable will you get the same answer as assuming they are not distinguishable? (This would be great because I think the non-distinguishable case is easier).

I appreciate any insight on the problem.

alejopelaez
  • 2,707
  • 1
    Note that a distinction may also need to be made whether the boxes are distinguishable or not. In total, there are 4 possible interpretations of the question. – Lie Ryan Mar 12 '11 at 15:32
  • 1
    The distinguishable case is easier. This is actually a rephrasing of the "coupon collector problem"; if you've heard of that problem, great, and if it's not, you have another term to search for. – Michael Lugo Mar 12 '11 at 15:53
  • As a probability question, I think you can only use counting methods if each possibility has equal probability. That will only happen if you use distinguishable balls (first, second, third etc.) and boxes (left, next to right, etc.). – Henry Mar 12 '11 at 16:05

3 Answers3

14

This answer treats the balls and boxes as distinguishable so each pattern is of equal probability. I doubt there is a practical experiment to test this which does not also have them distinguishable.

The number of ways of putting $m$ balls in $n$ boxes is $n^m$ since each ball can go in any of the boxes.

The calculation for the number of ways of putting $m$ balls in $n$ boxes with each box having at least one ball is more complicated. Let's call it $A(m,n)$. If, when deciding what to do with the last ball, all the other boxes are full, then it can go in any of the $n$ boxes; if however one of the $n$ boxes is empty and the others full then it must go in the empty one. So $$A(m,n) = n A(m-1,n) + n A(m-1,n-1)$$ and clearly $A(m,1) = 1$ (there is only one way with one box) and $A(m,n) = 0$ for $m<n$. It turns out that $$A(m,n) = n! \, S_2 (m,n)$$ where $S_2$ means Stirling numbers of the second kind (OEIS A019538). $A(n,n)=n!$ as one would expect.

So the probability that all the boxes have at least one ball is $$ \frac{n! \, S_2 (m,n)}{n^m}.$$

For example, with 3 balls and 2 boxes, this gives $\frac{2 \times 3}{8} = 3/4$.

Henry
  • 157,058
4

Let S be the number of ways to distribute m balls into n boxes with no restriction and T be number of ways to distribute m balls into n boxes with each boxes having at least one balls.

If we can calculate S and T, then the probability that all the boxes have at least one ball in it is simply $\frac T S$.

First, we count the number of ways to distribute m balls into n boxes with no restriction. In other words, the number of solutions to the equation:

$$x_1 + x_2 + x_3 + ... + x_n = m$$

We can calculate this with: $S = {m+n-1 \choose n-1}$

Second, we count the number of ways to distribute m balls into n boxes, with the restriction that all boxes have at least 1 balls. In other words, the number of solutions to the equation:

$$x_1 + x_2 + x_3 + ... + x_n = m \textrm{ where } x_i >= 1 \textrm { for all } i = 1..n$$

Let's reformulate this second question. Let's put a single ball into each boxes ($x_i = y_i + 1$) and then distribute the other $m-n$ balls:

$$(y_1 + 1) + (y_2 + 1) + (y_3 + 1) + ... + (y_n + 1) = m$$ $$y_1 + y_2 + y_3 + ... + y_n = m-n$$

So now, we can calculate $T = {(m-n)+n-1 \choose n-1} = {m-1 \choose n-1}$

Therefore, the probability of each box having at least one ball is

$$ \frac T S = \frac {m-1 \choose n-1} {m+n-1 \choose n-1} = \frac {(m-1)!m!} {(m-n)!(m+n-1)!} $$

Lie Ryan
  • 1,200
  • I'm not sure, but shouldn't $S = {n+m-1 \choose m}$? Lets take simple case where $m=2$ and $n=1$. There is only one way to put two balls into one box, but according to your solution it is equal to $S = {1+2-1 \choose 1}= {2 \choose 1}=2$ – Tomek Tarczynski Mar 12 '11 at 10:36
  • @Tomek Tarczynski: Well spotted, I've fixed it now. Thanks. Note that $S = \binom {m+n-1} {m} = \binom {m+n-1} {n-1}$, I've chosen the latter version for consistency with T. – Lie Ryan Mar 12 '11 at 11:34
  • @Lie Ryan: You can also simplify a bit the final result $\frac{T}{S}=\frac{(m-1)!m!}{(m-n)!(m+n-1)!}$ – Tomek Tarczynski Mar 12 '11 at 11:43
  • What does this give for 3 balls and 2 boxes? I think this formula gives 1/2 when it should be 3/4. An equivalent question is that with three random children, what is the chance they are not all the same gender? – Henry Mar 12 '11 at 15:01
  • @Henry: Under the assumptions I made in this answer, i.e. that the balls are indistinguishable, 1/2 is the correct answer. There are 4 ways to fill 3 balls into 2 boxes: (1) All in first box, (2) the first box have two balls and the second have one ball, (3) the first box have one item and the second box have two balls, (4) All in second box. Of those, only (2) and (3) fits the condition of no empty boxes, therefore the answer is 1/2. Your answer of 3/4 is also correct under the assumption that the balls are distinguishable. – Lie Ryan Mar 12 '11 at 15:25
  • @Lie Ryan: The problem is that your answer depends on you assuming your four possible patterns are of equal probability. But they are not: (2) and (3) are three times as likely as (1) and (4), and if you took that into account you would get the correct answer. This is a probability question, not a counting question. – Henry Mar 12 '11 at 16:01
  • 1
    @Henry: I suppose it depends on how you choose to insert the balls into the boxes (eg: see the question linked in Sivaram's answer). FWIW, I agree with your interpretation, the balls and boxes being distinguishable seems more natural to me and I interpret the process as: choose a random box for ball 1, then for ball 2 etc. The statement, "this is a probability question, not a counting question" is misleading, though. Your answer also uses a counting method to compute the probabilities :-) – Aryabhata Mar 14 '11 at 15:55
  • 1
    @Moron: I tried to suggest that if using counting methods to answer probability questions then you need to ensure each thing being counted is of equal probability, so you don't have the same freedom over distinuishable/indistinguishable issues. My apologies if this was not clear – Henry Mar 16 '11 at 13:29
3

I have provided the solution to a similar problem here. The solution has the general case worked out as well.