# 随机算法 (Fall 2011)/Problem set 2

## Problem 1

Some known facts:

• Balls-into-bins: ${\displaystyle m}$ balls are uniformly and independently thrown to ${\displaystyle n}$ bins. If ${\displaystyle m=\Theta (n)}$, then the maximum load is ${\displaystyle \Theta \left({\frac {\ln n}{\ln \ln n}}\right)}$ with high probability.
• Power of two choices: ${\displaystyle m}$ balls are sequentially thrown to ${\displaystyle n}$ bins. For each ball, uniformly and independently choose random bins ${\displaystyle i}$ and ${\displaystyle j}$ (might be the same bin), and throw the ball to the currently less loaded bin among bin ${\displaystyle i}$ and bin ${\displaystyle j}$. Assuming that ${\displaystyle m=\Theta (n)}$, after all ${\displaystyle m}$ balls are thrown to bins, the maximum load is ${\displaystyle \Theta \left(\ln \ln n\right)}$ with high probability.

Questions: Assume ${\displaystyle n}$ balls and ${\displaystyle n}$ bins. We throw the ${\displaystyle n}$ balls sequentially.

1. If we throw the first ${\displaystyle {\frac {n}{2}}}$ balls uniformly and then throw the rest balls as the way of power-of-two-choices, what is the asymptotic maximum load with high probability?
2. For the ${\displaystyle k}$th ball, if ${\displaystyle k}$ is even, we throw the ball to a uniform bin; and if ${\displaystyle k}$ is odd, we throw the ball as the way of power-of-two-choices. What is the asymptotic maximum load with high probability?

## Problem 2

1. Generalize the LazySelect algorithm for the general selection problem: finding the ${\displaystyle k}$th smallest element in an array. Choose appropriate parameters to do the job.
2. Use the Chernoff bounds instead of Chebyshev's inequality in the analysis of the above algorithm and try to use a smaller number of random samples.

## Problem 3

The Monte Carlo method for computing ${\displaystyle \mathrm {e} }$

Suppose there are ${\displaystyle n}$ peoples, each wearing a hat. We collect all their hats and randomly distribute the hats back to them, with each people receiving exactly one hat. We ask for the probability that none of the people receives his/her own hat. We denote this probability by ${\displaystyle p(n)}$

Formally, a permutation is a bijection ${\displaystyle \pi :[n]{\xrightarrow[{\text{1-1}}]{\text{onto}}}[n]}$. A fixed point for permutation ${\displaystyle \pi }$ is an ${\displaystyle i\in [n]}$ such that ${\displaystyle \pi (i)=i}$. Then ${\displaystyle p(n)}$ is the probability that a uniformly random permutation has no fixed point. Such permutations are called derangements.

The derangement problem is taught in the undergraduate class Combinatorics at Nanjing University. See the lecture notes for details. By the Principle of Inclusion-Exclusion (容斥原则), we know that ${\displaystyle p(n)=\sum _{k=0}^{n}{\frac {(-1)^{k}}{k!}}}$.

Recall that due to Taylor's expansion ${\displaystyle \mathrm {e} ^{-1}=\sum _{k=0}^{\infty }{\frac {(-1)^{k}}{k!}}=p(\infty )}$.

Now suppose you are given access to a balckbox ${\displaystyle derange(n)}$ which given as input a number ${\displaystyle n}$, samples a uniform and independent permutation ${\displaystyle \pi }$ of ${\displaystyle [n]}$, and returns true if ${\displaystyle \pi }$ has no fixed point and false if otherwise.

Give a randomized algorithm ${\displaystyle randE(\epsilon ,\delta )}$, whose inputs are ${\displaystyle 0<\epsilon <0.1}$ and ${\displaystyle 0<\delta <{\frac {1}{2}}}$. The returned value of the algorithm should satisfy that

${\displaystyle \Pr[\mathrm {e} -\epsilon \leq randE(\epsilon ,\delta )\leq \mathrm {e} +\epsilon ]\geq 1-\delta }$.
• Your algorithm should call ${\displaystyle derange(n)}$ as subroutine. Try to make both ${\displaystyle n}$ and the number of times calling ${\displaystyle derange(n)}$ as small as possible.