# 随机算法 (Fall 2011)/Balls-into-balls Occupancy Problem

Now we ask about the loads of bins. Assuming that ${\displaystyle m}$ balls are uniformly and independently assigned to ${\displaystyle n}$ bins, for ${\displaystyle 1\leq i\leq n}$, let ${\displaystyle X_{i}}$ be the load of the ${\displaystyle i}$th bin, i.e. the number of balls in the ${\displaystyle i}$th bin.

An easy analysis shows that for every bin ${\displaystyle i}$, the expected load ${\displaystyle \mathbf {E} [X_{i}]}$ is equal to the average load ${\displaystyle m/n}$.

Because there are totally ${\displaystyle m}$ balls, it is always true that ${\displaystyle \sum _{i=1}^{n}X_{i}=m}$.

Therefore, due to the linearity of expectations,

{\displaystyle {\begin{aligned}\sum _{i=1}^{n}\mathbf {E} [X_{i}]&=\mathbf {E} \left[\sum _{i=1}^{n}X_{i}\right]=\mathbf {E} \left[m\right]=m.\end{aligned}}}

Because for each ball, the bin to which the ball is assigned is uniformly and independently chosen, the distributions of the loads of bins are identical. Thus ${\displaystyle \mathbf {E} [X_{i}]}$ is the same for each ${\displaystyle i}$. Combining with the above equation, it holds that for every ${\displaystyle 1\leq i\leq m}$, ${\displaystyle \mathbf {E} [X_{i}]={\frac {m}{n}}}$. So the average is indeed the average!

Next we analyze the distribution of the maximum load. We show that when ${\displaystyle m=n}$, i.e. ${\displaystyle n}$ balls are uniformly and independently thrown into ${\displaystyle n}$ bins, the maximum load is ${\displaystyle O\left({\frac {\log n}{\log \log n}}\right)}$ with high probability.

 Theorem Suppose that ${\displaystyle n}$ balls are thrown independently and uniformly at random into ${\displaystyle n}$ bins. For ${\displaystyle 1\leq i\leq n}$, let ${\displaystyle X_{i}}$ be the random variable denoting the number of balls in the ${\displaystyle i}$th bin. Then ${\displaystyle \Pr \left[\max _{1\leq i\leq n}X_{i}\geq {\frac {3\ln n}{\ln \ln n}}\right]<{\frac {1}{n}}.}$
Proof.
 Let ${\displaystyle M}$ be an integer. Take bin 1. For any particular ${\displaystyle M}$ balls, these ${\displaystyle M}$ balls are all thrown to bin 1 with probability ${\displaystyle (1/n)^{M}}$, and there are totally ${\displaystyle {n \choose M}}$ distinct sets of ${\displaystyle M}$ balls. Therefore, applying the union bound, {\displaystyle {\begin{aligned}\Pr \left[X_{1}\geq M\right]&\leq {n \choose M}\left({\frac {1}{n}}\right)^{M}\\&={\frac {n!}{M!(n-M)!n^{M}}}\\&={\frac {1}{M!}}\cdot {\frac {n(n-1)(n-2)\cdots (n-M+1)}{n^{M}}}\\&={\frac {1}{M!}}\cdot \prod _{i=0}^{M-1}\left(1-{\frac {i}{n}}\right)\\&\leq {\frac {1}{M!}}.\end{aligned}}} According to Stirling's approximation, ${\displaystyle M!\approx {\sqrt {2\pi M}}\left({\frac {M}{e}}\right)^{M}}$, thus ${\displaystyle {\frac {1}{M!}}\leq \left({\frac {e}{M}}\right)^{M}.}$ Figure 1 Due to the symmetry. All ${\displaystyle X_{i}}$ have the same distribution. Apply the union bound again, {\displaystyle {\begin{aligned}\Pr \left[\max _{1\leq i\leq n}X_{i}\geq M\right]&=\Pr \left[(X_{1}\geq M)\vee (X_{2}\geq M)\vee \cdots \vee (X_{n}\geq M)\right]\\&\leq n\Pr[X_{1}\geq M]\\&\leq n\left({\frac {e}{M}}\right)^{M}.\end{aligned}}} When ${\displaystyle M=3\ln n/\ln \ln n}$, {\displaystyle {\begin{aligned}\left({\frac {e}{M}}\right)^{M}&=\left({\frac {e\ln \ln n}{3\ln n}}\right)^{3\ln n/\ln \ln n}\\&<\left({\frac {\ln \ln n}{\ln n}}\right)^{3\ln n/\ln \ln n}\\&=e^{3(\ln \ln \ln n-\ln \ln n)\ln n/\ln \ln n}\\&=e^{-3\ln n+3\ln \ln \ln n\ln n/\ln \ln n}\\&\leq e^{-2\ln n}\\&={\frac {1}{n^{2}}}.\end{aligned}}} Therefore, {\displaystyle {\begin{aligned}\Pr \left[\max _{1\leq i\leq n}X_{i}\geq {\frac {3\ln n}{\ln \ln n}}\right]&\leq n\left({\frac {e}{M}}\right)^{M}&<{\frac {1}{n}}.\end{aligned}}}
${\displaystyle \square }$

When ${\displaystyle m>n}$, Figure 1 illustrates the results of several random experiments, which show that the distribution of the loads of bins becomes more even as the number of balls grows larger than the number of bins.

Formally, it can be proved that for ${\displaystyle m=\Omega (n\log n)}$, with high probability, the maximum load is within ${\displaystyle O\left({\frac {m}{n}}\right)}$, which is asymptotically equal to the average load.