Problem description
There are m balls to throw into N boxes. Each of these balls is thrown independently of each other. Q. How many boxes are there in the end with balls on average?
Problem resolution
This kind of problem is a more pure mathematical problem, of course, can also use the computer to accurately find the answer.
Scenario One: Programming Solutions
- P (M, i): The probability that the first m balls are thrown into n boxes and that they occupy the I box
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 can be based on the above-mentioned programming solution, the complexity of O (m^2)
Scenario Two: Mathematical analysis
- P (m): Indicates the average number of boxes occupied by the first m balls in n boxes (Note: This is the desired quantity)
P (m) = (p (m-1)/N) * p (m-1) + (1-(P (m-1)/N) * (P (m-1) + 1)
The meaning of this equation is that when it comes to P (m), it can be assumed that the first M ball falls exactly in a box where the first M-1 ball is located, the probability is P (m-1)/n, or the M ball falls in an empty box, the probability is 1-p (m-1)/n
Reduction is obtained: P (m) = 1 + (n-1)/n * p (m-1).
Further: P (m)-n = (n-1)/n * (P (m-1)-N)
Further: P (m)-n = ((n-1)/n) ^ M * (-N)
thus: P (m) = N-n * ((n-1)/n) ^m.
When M is larger, ((n-1)/n) ^ m approaches e ^ (-m/n). When M=n, there is P (m) = N-n/E, which means that at this point the average number of empty boxes is n/e.
Scenario Three: Mathematical analysis
There is also a more ingenious mathematical analysis.
The probability that each ball does not fall on a particular box is (n-1)/n (this is obviously the probability that a ball does not fall in box # 2nd, of course (n-1)/n). So the probability of the M-ball, which does not fall in a particular box, is ((n-1)/n) ^ M. This sentence can be understood in a different way: for a box, the probability that the M ball will not fall in 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 results of the above analysis.
[Probability]m a ball to n a box