[Probability] m balls are thrown into n boxes, and n balls are placed in m boxes.
Problem description
There are m balls, which should be thrown into n boxes. Each ball is independent of each other. Q: How many boxes have balls on average?
Problem Analysis
This type of question is purely a mathematical question. Of course, you can use a computer to find the answer accurately.
Solution 1: Programming
- P (m, I): indicates that the first m balls are thrown into n boxes, which occupy the probability of I boxes.
So p (m, I) = p (m-1, I) * (I/n) + p (m-1, I-1) * (n-I + 1)/n
P (m, I) = 0, if I <= 0 | I> m | I> n
So we can solve the problem according to the sub-programming method described above. The complexity is O (m ^ 2)
Solution 2: Mathematical Analysis
- P (m): indicates the number of boxes occupied by the first m balls in n boxes on average (Note: The expected number is here)
P (m) = (m-1) * p (m-1) + (1-(m-1)/n) * (m-1) + 1)
The significance of the formula above is that when p (m) is obtained, we can think that the m-th ball falls in a box where M-1 ball is located, and the probability is m-1) /n; or the m-th ball falls into an empty box. The probability is 1-p (S-1)/n.
The simplification result is as follows: p (m) = 1 + (n-1)/n * p (S-1 ).
Further: p (m)-n = (n-1)/n * (m-1)-n)
Further: p (m)-n = (n-1)/n) ^ m * (-n)
So p (m) = n-n * (n-1)/n) ^ m.
(N-1)/n) ^ m approaches e ^ (-m/n) when m is relatively large ). When m = n, p (m) = n-n/e indicates that the average number of empty boxes is n/e.
Solution 3: Mathematical Analysis
There is also a more clever mathematical analysis.
The probability of every ball not falling into a specific box is (n-1)/n (obviously, the probability of a ball not falling into box 2 is (n-1)/n ). So the probability that m balls will not fall into a specific box is (n-1)/n) ^ m. This sentence can be understood from another angle: For a box, the probability that m balls do not fall into the box is (n-1)/n) ^ m.
Therefore, for n boxes, the average number of empty boxes is n * (n-1)/n) ^ m. This is consistent with the above analysis results.