# If I randomly (uniformly) distribute n balls into k bags, what is the distribution of the number of empty bags?

If I uniformly distribute $$n$$ balls into $$k$$ bags, I am trying to work out the distribution of the number of bags which are empty.

Now I had thought that I could use that each bag has $$\text{Binomial}(n, \frac{1}{k})$$ balls and use this but these distributions are not independent so this doesn't work.

Any help will be greatly appreciated.

• How many ways are there of choosing two empty bags? How many ways are there of distributing the balls among the remaining bags, so that at least one ball is in each bag? – Peter Shor Mar 25 at 11:38

Define $$P_k^n(m)$$ as the probability, that there will be $$m$$ empty bags after $$n$$ balls were thrown into $$k$$ bags. Now, suppose, you have $$k$$ bags total and have already thrown $$n - 1$$ balls, and it resulted in $$m$$ bags remaining empty. Then, after the next ball is thrown, $$m$$ bags remain empty with probability $$\frac{k - m}{k}$$ and the number of empty bags will become $$m - 1$$ is $$\frac{m}{k}$$. So we have the following recurrence, that is sufficient to define all probabilities you search:
$$P_k^n(m) = \frac{k - m}{k}P_k^{n - 1}(m) + \frac{m}{k}P_k^{n-1}(m + 1)$$ $$P_k^0(k) = 1$$ $$P_k^0(m) = 0, \text{ if } m \neq k$$
$$\bbox[#EEE,6px,border:1.5px solid black]{\mathbb P\big(\text{# empty bags }=m\big)=\sum_{i=m}^k(-1)^{i-m}\binom{i}m\binom{k}{i}\left(1-{i\over k}\right)^n.}$$ This follows from the generalized inclusion exclusion principle. See Generalised inclusion-exclusion principle.