[Probability] m balls are thrown into n boxes, and n balls are placed in m boxes.

Source: Internet
Author: User

[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.