Wenxin Yiyan VS Xunfei Xinghuo VS chatgpt (42) -- Introduction to Algorithms 5.4 6 questions

6. Assume that n balls are thrown into n boxes, each ball is thrown independently, and each ball may fall into any box. What is the expected number of empty boxes? What is the expected number of boxes containing exactly one ball?

In a word:

This is a typical probability problem. First, we can understand the background of the problem through simple calculations. Suppose we have n balls and n boxes, and the probability of each ball being thrown into the box is equal, that is, each box has a 1/n probability of being selected.

Now let's answer the question.

1. What is the expected number of empty boxes?

We can use the total probability formula to solve this problem. First, consider the case of only one ball. In this case, we can get one of n bins, so the expectation of empty bins is n-1. Next, consider the case of two balls. In this case, we can get one of 2 bins, so the expectation of empty bins is n-2. By analogy, with k balls, the expectation of an empty box is nk.

Therefore, the number of empty bins is expected to be:

n-1 + n-2 + … + n-n = n(n-1)/2

2. What is the expected number of boxes containing exactly one ball?

We can use the same method as above to solve this problem. In the case of only one ball, the expectation of a bin with exactly one ball is 1. With two balls, the expectation of a bin with exactly one ball is 2. By analogy, given k balls, the expectation of a bin with exactly one ball is k.

Thus, the expected number of bins with exactly one ball is:

1 + 2 + … + n = n(n+1)/2 - 1

Note that this expected value is a quadratic function of n, so it increases rapidly as n increases.

insert image description here

Xunfei Spark:

We can use the definition of expectation to solve this problem. Let X i X_iXiIndicates throwing a ball into the iiWhen there are i boxes, there is exactly one ball in the number of boxes. Then, we can get the following equation:

P ( X i = 1 ) = n − i n P(X_i=1)=\frac{n-i}{n} P(Xi=1)=nni

where i = 1 , 2 , ⋯ , ni=1,2,\cdots,ni=1,2,,n . Now we need to calculate the expected number of empty boxes and the expected number of boxes with exactly one ball.

Number of empty boxes expected:

Let Υ \UpsilonΥ represents the number of empty boxes after throwing n balls. Then, we can get the following equation:

P ( Υ = k ) = C n − 1 k − 1 ⋅ 1 nn − k P(\Upsilon =k)=C_{n-1}^{k-1}\cdot\frac{1}{n^{ nk}}P ( Y=k)=Cn1k1nnk1

Among them, k = 0 , 1 , 2 , ⋯ , n − 1 k=0,1,2,\cdots,n-1k=0,1,2,,n1. We need to calculateΥ \UpsilonExpected value of Υ :

$\begin{align*}E(\Upsilon )&=\sum_{k=0}^{n-1}k\cdot P(\Upsilon =k)\ &=0\cdot C_{n-1}0\cdot\frac{1}{n{n}}+\frac{1}{n}\cdot C_{n-1}1\cdot\frac{1}{n{n-1}}+\cdots+\frac{n-1}{n}\cdot C_{n-1}{n-1}\cdot\frac{1}{n{0}}\ &=\frac{1}{n}\cdot\sum_{k=1}{n-1}C_{n-1}k\cdot\frac{1}{n^{n-k}}\ &=\frac{1}{n}\cdot 2^{n-1}\end{align*}

So, the expected number of empty boxes is 2 n − 1 n \frac{2^{n-1}}{n}n2n1.

Expect the number of boxes with exactly one ball:

Let Z denote the number of boxes containing exactly one ball after throwing n balls. Then, we can get the following equation:

P ( Z = k ) = 1 n ⋅ C n − 1 k − 1 ⋅ 1 n n − k P(Z=k)=\frac{1}{n}\cdot C_{n-1}^{k-1}\cdot\frac{1}{n^{n-k}} P(Z=k)=n1Cn1k1nnk1

Among them, k = 1 , 2 , ⋯ , nk=1,2,\cdots,nk=1,2,,n . We need to calculate the expected value of Z:

$\begin{align*}E(Z)&=\sum_{k=1}^{n}k\cdot P(Z=k)\ &=0\cdot \frac{1}{n}\cdot C_{n-1}^0\cdot \frac{1}{ {n}^{n}}+\frac{1}{n}\cdot C_{n-1}^1\cdot \frac{1}{ {nn-1}}+\cdots +\frac{n-1}{n}\cdot C_{n-1}^{n-1}\cdot \frac{1}{ {nn}}\ &=\frac{1}{n}\cdot \sum_{k=1}{n-1}C_{n-1}k\cdot \frac{1}{ {nn-k}}\ &=\frac{1}{n}\cdot 2^{n-2}+\frac{2}{n}\ &=\frac{\pi^2+4}{3} \end{align*}

insert image description here

Huawei Pangu:

insert image description here

360 Smart Brain:

Title description:

Assume that n balls are thrown into n boxes, and each throw falls into any box independently and with equal probability. Find the expected number of hollow boxes and the expected number of boxes containing exactly one ball.

Problem-solving ideas:

The expected number of hollow boxes is the expected number of all boxes minus the expected number of balled boxes. And the expected number of boxes with exactly one ball is the expected number of boxes minus the expected number of boxes without balls.

The problem-solving steps are as follows:

1. The desired number of hollow boxes is equal to the total number of boxes multiplied by the proportion of hollow boxes.

2. The expectation of the number of boxes with exactly one ball is equal to the ratio of the total number of boxes multiplied by one ball box.

3. According to the definition of expected value, calculate the expected number of hollow boxes and the expected number of boxes with exactly one ball.

insert image description here

chatglm:

For the first problem, we can use conditional probability to solve this problem. Let E1 denote the number of empty boxes and E2 the number of boxes containing exactly one ball.

According to the meaning of the question, each pitch is independent, and each ball, etc., may fall into any box. Therefore, for each box, the probability of success is 1/n, and the probability of failure is 1-1/n.

Our goal is to calculate the expected value of E1 and E2. Since P(E1)=P(E1|successfully falling into the box)×probability of successfully falling into the box+P(E1|failure falling into the box)×failure of falling into the box, P(E2)=P(E2|success Falling into the box)×probability of successfully falling into the box-P(E2|failing into the box)×probability of failing into the box.

We can combine the above two equations to get the expected value of E1 and E2.

Specifically, we can list all possible cases and calculate the corresponding expected value as follows:

  • The expected value of the empty box is E 1 = n ( 1 / n ) n E1=n(1/n)^nAnd 1=n(1/n)n

  • The expected value of a box with exactly one ball is E 2 = n ( 1 − 1 / n ) n E2=n(1-1/n)^nE2 _=n(11/n)n

Therefore, the number of empty bins is expected to be n ( 1 / n ) nn(1/n)^nn(1/n)n , the number of boxes with exactly one ball is expected to ben ( 1 − 1 / n ) nn(1-1/n)^nn(11/n)n

For the second question, we can use a similar method to calculate. Let E3 denote the number of boxes with only one ball, and E4 denote the number of boxes with two or more balls.

According to the meaning of the question, each ball is independent, and each ball may fall into any box. Therefore, for each box, the probability of success is 1/n, and the probability of failure is 1 − 1 / n 1-1 /n11/n

Our goal is to compute the expected values ​​of E3 and E4. Since P(E3)=P(E3|successfully falling into the box)×probability of successfully falling into the box+P(E3|failure falling into the box)×failure of falling into the box, P(E4)=P(E4|success Falling into the box)×probability of successfully falling into the box-P(E4|failing into the box)×probability of failing into the box.

We can combine the above two equations to get the expected value of E3 and E4.

Specifically, we can list all possible cases and calculate the corresponding expected value as follows:

  • The expected value of a box with only one ball is $E3=n(1/n)^n $

  • The expected value of a box with two or more balls is E 4 = n ( 1 − 1 / n ) n E4=n(1-1/n)^nE 4=n(11/n)n

Therefore, the expected number of boxes with only one ball is n ( 1 / n ) nn(1/n)^nn(1/n)n , the number of boxes with two or more balls is expected to ben ( 1 − 1 / n ) nn(1-1/n)^nn(11/n)n

insert image description here

insert image description here

chatgpt:

Assume that nnn balls are thrown intonnIn n boxes, the falling boxes of each ball are independent of each other, and the probability of each box being dropped by any ball is1 / n 1/n1/n

Therefore, the binomial distribution model can be used to describe the empty and non-empty conditions of a box, let XXX is whether the box is empty, according to the additive formula of probability, thenP ( X = 0 ) + P ( X = 1 ) = 1 P(X=0)+P(X=1) = 1P(X=0)+P(X=1)=1 , at the same time, from the expectation formula of the binomial distribution:

E ( X ) = n p E(X) = np E ( X )=np

V a r ( X ) = n p ( 1 − p ) Var(X) = np(1-p) there is ( X )=np(1p)

Among them, ppp is the probability that each ball falls into the box, ie1 / n 1/n1/n

According to the above formula, P ( X = 0 ) = ( 1 − 1 / n ) n P(X=0) = (1-1/n)^nP(X=0)=(11/n)n , the probability that the box is not empty.

Therefore, the probability that the box is empty is: P ( X = 1 ) = 1 − P ( X = 0 ) = 1 − ( 1 − 1 / n ) n P(X=1)=1-P(X=0) =1-(1-1/n)^nP(X=1)=1P(X=0)=1(11/n)n

The probability that a box contains exactly one ball is equal to the expected number of boxes with one and only one ball, which can be solved by calculating the probability that any two balls cannot fall into the same box. The probability that the first ball falls into any box is 1 11 , the second ball cannot fall into the box where the first ball is located, that is( n − 1 ) / n (n-1)/n(n1 ) The probability of n/ n does not fall into the box where the first ball is located, and so on, to get thekkthk balls cannot fall into the firstk − 1 k-1kThe probability of the box where 1 ball is located is( n − k + 1 ) / n (n-k+1)/n(nk+1 ) / n . Therefore, the probability that any two balls cannot land in the same box is:

P = 1 × ( 1 − 1 / n ) × ( 1 − 2 / n ) × . . . × ( 1 − ( n − 1 ) / n ) = n ! nn P = 1×(1-1/n)×(1-2/n)×...×(1-(n-1)/n) = \dfrac{n!}{n^n}P=1×(11/n)×(12/n)×...×(1(n1)/n)=nnn!

Thus, the expected number of boxes with exactly one ball is:

E = np ⋅ P = n ! nn − 1 E= np \cdot P = \dfrac{n!}{n^{n-1}}E=npP=nn1n!

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/weixin_48502062/article/details/131235767