# The Chernoff Bound

Suppose that we have a fair coin. If we toss it once, then the outcome is completely unpredictable. But if we toss it, say for 1000 times, then the number of HEADs is very likely to be around 500. This striking phenomenon, illustrated in the right figure, is called the concentration. The Chernoff bound captures the concentration of independent trials.

The Chernoff bound is also a tail bound for the sum of independent random variables which may give us exponentially sharp bounds.

Before proving the Chernoff bound, we should talk about the moment generating functions.

## Moment generating functions

The more we know about the moments of a random variable $\displaystyle{ X }$, the more information we would have about $\displaystyle{ X }$. There is a so-called moment generating function, which "packs" all the information about the moments of $\displaystyle{ X }$ into one function.

 Definition The moment generating function of a random variable $\displaystyle{ X }$ is defined as $\displaystyle{ \mathbf{E}\left[\mathrm{e}^{\lambda X}\right] }$ where $\displaystyle{ \lambda }$ is the parameter of the function.

By Taylor's expansion and the linearity of expectations,

\displaystyle{ \begin{align} \mathbf{E}\left[\mathrm{e}^{\lambda X}\right] &= \mathbf{E}\left[\sum_{k=0}^\infty\frac{\lambda^k}{k!}X^k\right]\\ &=\sum_{k=0}^\infty\frac{\lambda^k}{k!}\mathbf{E}\left[X^k\right] \end{align} }

The moment generating function $\displaystyle{ \mathbf{E}\left[\mathrm{e}^{\lambda X}\right] }$ is a function of $\displaystyle{ \lambda }$.

## The Chernoff bound

The Chernoff bounds are exponentially sharp tail inequalities for the sum of independent trials. The bounds are obtained by applying Markov's inequality to the moment generating function of the sum of independent trials, with some appropriate choice of the parameter $\displaystyle{ \lambda }$.

 Chernoff bound (the upper tail) Let $\displaystyle{ X=\sum_{i=1}^n X_i }$, where $\displaystyle{ X_1, X_2, \ldots, X_n }$ are independent Poisson trials. Let $\displaystyle{ \mu=\mathbf{E}[X] }$. Then for any $\displaystyle{ \delta\gt 0 }$, $\displaystyle{ \Pr[X\ge (1+\delta)\mu]\le\left(\frac{e^{\delta}}{(1+\delta)^{(1+\delta)}}\right)^{\mu}. }$
Proof.
 For any $\displaystyle{ \lambda\gt 0 }$, $\displaystyle{ X\ge (1+\delta)\mu }$ is equivalent to that $\displaystyle{ e^{\lambda X}\ge e^{\lambda (1+\delta)\mu} }$, thus \displaystyle{ \begin{align} \Pr[X\ge (1+\delta)\mu] &= \Pr\left[e^{\lambda X}\ge e^{\lambda (1+\delta)\mu}\right]\\ &\le \frac{\mathbf{E}\left[e^{\lambda X}\right]}{e^{\lambda (1+\delta)\mu}}, \end{align} } where the last step follows by Markov's inequality. Computing the moment generating function $\displaystyle{ \mathbf{E}[e^{\lambda X}] }$: \displaystyle{ \begin{align} \mathbf{E}\left[e^{\lambda X}\right] &= \mathbf{E}\left[e^{\lambda \sum_{i=1}^n X_i}\right]\\ &= \mathbf{E}\left[\prod_{i=1}^n e^{\lambda X_i}\right]\\ &= \prod_{i=1}^n \mathbf{E}\left[e^{\lambda X_i}\right]. & (\mbox{for independent random variables}) \end{align} } Let $\displaystyle{ p_i=\Pr[X_i=1] }$ for $\displaystyle{ i=1,2,\ldots,n }$. Then, $\displaystyle{ \mu=\mathbf{E}[X]=\mathbf{E}\left[\sum_{i=1}^n X_i\right]=\sum_{i=1}^n\mathbf{E}[X_i]=\sum_{i=1}^n p_i }$. We bound the moment generating function for each individual $\displaystyle{ X_i }$ as follows. \displaystyle{ \begin{align} \mathbf{E}\left[e^{\lambda X_i}\right] &= p_i\cdot e^{\lambda\cdot 1}+(1-p_i)\cdot e^{\lambda\cdot 0}\\ &= 1+p_i(e^\lambda -1)\\ &\le e^{p_i(e^\lambda-1)}, \end{align} } where in the last step we apply the Taylor's expansion so that $\displaystyle{ e^y\ge 1+y }$ where $\displaystyle{ y=p_i(e^\lambda-1)\ge 0 }$. (By doing this, we can transform the product to the sum of $\displaystyle{ p_i }$, which is $\displaystyle{ \mu }$.) Therefore, \displaystyle{ \begin{align} \mathbf{E}\left[e^{\lambda X}\right] &= \prod_{i=1}^n \mathbf{E}\left[e^{\lambda X_i}\right]\\ &\le \prod_{i=1}^n e^{p_i(e^\lambda-1)}\\ &= \exp\left(\sum_{i=1}^n p_i(e^{\lambda}-1)\right)\\ &= e^{(e^\lambda-1)\mu}. \end{align} } Thus, we have shown that for any $\displaystyle{ \lambda\gt 0 }$, \displaystyle{ \begin{align} \Pr[X\ge (1+\delta)\mu] &\le \frac{\mathbf{E}\left[e^{\lambda X}\right]}{e^{\lambda (1+\delta)\mu}}\\ &\le \frac{e^{(e^\lambda-1)\mu}}{e^{\lambda (1+\delta)\mu}}\\ &= \left(\frac{e^{(e^\lambda-1)}}{e^{\lambda (1+\delta)}}\right)^\mu \end{align} }. For any $\displaystyle{ \delta\gt 0 }$, we can let $\displaystyle{ \lambda=\ln(1+\delta)\gt 0 }$ to get $\displaystyle{ \Pr[X\ge (1+\delta)\mu]\le\left(\frac{e^{\delta}}{(1+\delta)^{(1+\delta)}}\right)^{\mu}. }$
$\displaystyle{ \square }$

The idea of the proof is actually quite clear: we apply Markov's inequality to $\displaystyle{ e^{\lambda X} }$ and for the rest, we just estimate the moment generating function $\displaystyle{ \mathbf{E}[e^{\lambda X}] }$. To make the bound as tight as possible, we minimized the $\displaystyle{ \frac{e^{(e^\lambda-1)}}{e^{\lambda (1+\delta)}} }$ by setting $\displaystyle{ \lambda=\ln(1+\delta) }$, which can be justified by taking derivatives of $\displaystyle{ \frac{e^{(e^\lambda-1)}}{e^{\lambda (1+\delta)}} }$.

We then proceed to the lower tail, the probability that the random variable deviates below the mean value:

 Chernoff bound (the lower tail) Let $\displaystyle{ X=\sum_{i=1}^n X_i }$, where $\displaystyle{ X_1, X_2, \ldots, X_n }$ are independent Poisson trials. Let $\displaystyle{ \mu=\mathbf{E}[X] }$. Then for any $\displaystyle{ 0\lt \delta\lt 1 }$, $\displaystyle{ \Pr[X\le (1-\delta)\mu]\le\left(\frac{e^{-\delta}}{(1-\delta)^{(1-\delta)}}\right)^{\mu}. }$
Proof.
 For any $\displaystyle{ \lambda\lt 0 }$, by the same analysis as in the upper tail version, \displaystyle{ \begin{align} \Pr[X\le (1-\delta)\mu] &= \Pr\left[e^{\lambda X}\ge e^{\lambda (1-\delta)\mu}\right]\\ &\le \frac{\mathbf{E}\left[e^{\lambda X}\right]}{e^{\lambda (1-\delta)\mu}}\\ &\le \left(\frac{e^{(e^\lambda-1)}}{e^{\lambda (1-\delta)}}\right)^\mu. \end{align} } For any $\displaystyle{ 0\lt \delta\lt 1 }$, we can let $\displaystyle{ \lambda=\ln(1-\delta)\lt 0 }$ to get $\displaystyle{ \Pr[X\ge (1-\delta)\mu]\le\left(\frac{e^{-\delta}}{(1-\delta)^{(1-\delta)}}\right)^{\mu}. }$
$\displaystyle{ \square }$

Some useful special forms of the bounds can be derived directly from the above general forms of the bounds. We now know better why we say that the bounds are exponentially sharp.

 Useful forms of the Chernoff bound Let $\displaystyle{ X=\sum_{i=1}^n X_i }$, where $\displaystyle{ X_1, X_2, \ldots, X_n }$ are independent Poisson trials. Let $\displaystyle{ \mu=\mathbf{E}[X] }$. Then 1. for $\displaystyle{ 0\lt \delta\le 1 }$, $\displaystyle{ \Pr[X\ge (1+\delta)\mu]\lt \exp\left(-\frac{\mu\delta^2}{3}\right); }$ $\displaystyle{ \Pr[X\le (1-\delta)\mu]\lt \exp\left(-\frac{\mu\delta^2}{2}\right); }$ 2. for $\displaystyle{ t\ge 2e\mu }$, $\displaystyle{ \Pr[X\ge t]\le 2^{-t}. }$
Proof.
 To obtain the bounds in (1), we need to show that for $\displaystyle{ 0\lt \delta\lt 1 }$, $\displaystyle{ \frac{e^{\delta}}{(1+\delta)^{(1+\delta)}}\le e^{-\delta^2/3} }$ and $\displaystyle{ \frac{e^{-\delta}}{(1-\delta)^{(1-\delta)}}\le e^{-\delta^2/2} }$. We can verify both inequalities by standard analysis techniques. To obtain the bound in (2), let $\displaystyle{ t=(1+\delta)\mu }$. Then $\displaystyle{ \delta=t/\mu-1\ge 2e-1 }$. Hence, \displaystyle{ \begin{align} \Pr[X\ge(1+\delta)\mu] &\le \left(\frac{e^\delta}{(1+\delta)^{(1+\delta)}}\right)^\mu\\ &\le \left(\frac{e}{1+\delta}\right)^{(1+\delta)\mu}\\ &\le \left(\frac{e}{2e}\right)^t\\ &\le 2^{-t} \end{align} }
$\displaystyle{ \square }$

## Balls into bins, revisited

Throwing $\displaystyle{ m }$ balls uniformly and independently to $\displaystyle{ n }$ bins, what is the maximum load of all bins with high probability? In the last class, we gave an analysis of this problem by using a counting argument.

Now we give a more "advanced" analysis by using Chernoff bounds.

For any $\displaystyle{ i\in[n] }$ and $\displaystyle{ j\in[m] }$, let $\displaystyle{ X_{ij} }$ be the indicator variable for the event that ball $\displaystyle{ j }$ is thrown to bin $\displaystyle{ i }$. Obviously

$\displaystyle{ \mathbf{E}[X_{ij}]=\Pr[\mbox{ball }j\mbox{ is thrown to bin }i]=\frac{1}{n} }$

Let $\displaystyle{ Y_i=\sum_{j\in[m]}X_{ij} }$ be the load of bin $\displaystyle{ i }$.

Then the expected load of bin $\displaystyle{ i }$ is

$\displaystyle{ (*)\qquad \mu=\mathbf{E}[Y_i]=\mathbf{E}\left[\sum_{j\in[m]}X_{ij}\right]=\sum_{j\in[m]}\mathbf{E}[X_{ij}]=m/n. }$

For the case $\displaystyle{ m=n }$, it holds that $\displaystyle{ \mu=1 }$

Note that $\displaystyle{ Y_i }$ is a sum of $\displaystyle{ m }$ mutually independent indicator variable. Applying Chernoff bound, for any particular bin $\displaystyle{ i\in[n] }$,

$\displaystyle{ \Pr[Y_i\gt (1+\delta)\mu] \le \left(\frac{e^{\delta}}{(1+\delta)^{1+\delta}}\right)^\mu. }$

### When $\displaystyle{ m=n }$

When $\displaystyle{ m=n }$, $\displaystyle{ \mu=1 }$. Write $\displaystyle{ c=1+\delta }$. The above bound can be written as

$\displaystyle{ \Pr[Y_i\gt c] \le \frac{e^{c-1}}{c^c}. }$

Let $\displaystyle{ c=\frac{e\ln n}{\ln\ln n} }$, we evaluate $\displaystyle{ \frac{e^{c-1}}{c^c} }$ by taking logarithm to its reciprocal.

\displaystyle{ \begin{align} \ln\left(\frac{c^c}{e^{c-1}}\right) &= c\ln c-c+1\\ &= c(\ln c-1)+1\\ &= \frac{e\ln n}{\ln\ln n}\left(\ln\ln n-\ln\ln\ln n\right)+1\\ &\ge \frac{e\ln n}{\ln\ln n}\cdot\frac{2}{e}\ln\ln n+1\\ &\ge 2\ln n. \end{align} }

Thus,

$\displaystyle{ \Pr\left[Y_i\gt \frac{e\ln n}{\ln\ln n}\right] \le \frac{1}{n^2}. }$

Applying the union bound, the probability that there exists a bin with load $\displaystyle{ \gt 12\ln n }$ is

$\displaystyle{ n\cdot \Pr\left[Y_1\gt \frac{e\ln n}{\ln\ln n}\right] \le \frac{1}{n} }$.

Therefore, for $\displaystyle{ m=n }$, with high probability, the maximum load is $\displaystyle{ O\left(\frac{e\ln n}{\ln\ln n}\right) }$.

### For larger $\displaystyle{ m }$

When $\displaystyle{ m\ge n\ln n }$, then according to $\displaystyle{ (*) }$, $\displaystyle{ \mu=\frac{m}{n}\ge \ln n }$

We can apply an easier form of the Chernoff bounds,

$\displaystyle{ \Pr[Y_i\ge 2e\mu]\le 2^{-2e\mu}\le 2^{-2e\ln n}\lt \frac{1}{n^2}. }$

By the union bound, the probability that there exists a bin with load $\displaystyle{ \ge 2e\frac{m}{n} }$ is,

$\displaystyle{ n\cdot \Pr\left[Y_1\gt 2e\frac{m}{n}\right] = n\cdot \Pr\left[Y_1\gt 2e\mu\right]\le \frac{1}{n} }$.

Therefore, for $\displaystyle{ m\ge n\ln n }$, with high probability, the maximum load is $\displaystyle{ O\left(\frac{m}{n}\right) }$.

# Packet Routing

The problem raises from parallel computing. Consider that we have $\displaystyle{ N }$ processors, connected by a communication network. The processors communicate with each other by sending and receiving packets through the network. We consider the following packet routing problem:

• Every processor is sending a packet to a unique destination. Therefore for $\displaystyle{ [N] }$ the set of processors, the destinations are given by a permutation $\displaystyle{ \pi }$ of $\displaystyle{ [N] }$, such that for every processor $\displaystyle{ i\in[N] }$, the processor $\displaystyle{ i }$ is sending a packet to processor $\displaystyle{ \pi(i) }$.
• The communication is synchronized, such that for each round, every link (an edge of the graph) can forward at most one packet.

With a complete graph as the network. For any permutation $\displaystyle{ \pi }$ of $\displaystyle{ [N] }$, all packets can be routed to their destinations in parallel with one round of communication. However, such an ideal connectivity is usually not available in reality, either because they are too expensive, or because they are physically impossible. We are interested in the case the graph is sparse, such that the number of edges is significantly smaller than the complete graph, yet the distance between any pair of vertices is small, so that the packets can be efficiently routed between pairs of vertices.

## Routing on a hypercube

A hypercube (sometimes called Boolean cube, Hamming cube, or just cube) is defined over $\displaystyle{ N }$ nodes, for $\displaystyle{ N }$ a power of 2. We assume that $\displaystyle{ N=2^d }$. A hypercube of $\displaystyle{ d }$ dimensions, or a $\displaystyle{ d }$-cube, is an undirected graph with the vertex set $\displaystyle{ \{0,1\}^d }$, such that for any $\displaystyle{ u,v\in\{0,1\}^d }$, $\displaystyle{ u }$ and $\displaystyle{ v }$ are adjacent if and only if $\displaystyle{ h(u,v)=1 }$, where $\displaystyle{ h(u,v) }$ is the Hamming distance between $\displaystyle{ u }$ and $\displaystyle{ v }$.

A $\displaystyle{ d }$-cube is a $\displaystyle{ d }$-degree regular graph over $\displaystyle{ N=2^d }$ vertices. For any pair $\displaystyle{ (u,v) }$ of vertices, the distance between $\displaystyle{ u }$ and $\displaystyle{ v }$ is at most $\displaystyle{ d }$. (How do we know this? Since it takes at most $\displaystyle{ d }$ steps to fix any binary string of length $\displaystyle{ d }$ bit-by-bit to any other.) This directly gives us the following very natural routing algorithm.

 Bit-Fixing Routing Algorithm For each packet: Let $\displaystyle{ u, v\in\{0,1\}^d }$ be the origin and destination of the packet respectively. For $\displaystyle{ i=1 }$ to $\displaystyle{ d }$, do: if $\displaystyle{ u_i\neq v_i }$ then traverse the edge $\displaystyle{ (v_1,\ldots,v_{i-1},u_i,\ldots,u_d)\rightarrow (v_1,\ldots,v_{i-1},v_i,u_{i+1}\ldots,u_d) }$.
Oblivious routing algorithms
This algorithm is blessed with a desirable property: at each routing step, the choice of link depends only on the the current node and the destination. We call the algorithms with this property oblivious routing algorithms. (Actually, the standard definition of obliviousness allows the choice also depends on the origin. The bit-fixing algorithm is even more oblivious than this standard definition.) Compared to the routing algorithms which are adaptive to the path that the packet traversed, oblivious routing is more simple thus can be implemented by smaller routing table (or simple devices called switches).
Queuing policies
When routing $\displaystyle{ N }$ packets in parallel, it is possible that more than one packets want to use the same edge at the same time. We assume that a queue is associated to each edge, such that the packets to be delivered through an edge are put into the queue associated with the edge. With some queuing policy (e.g. FIFO, or furthest to do), the queued packets are delivered through the edge by at most one packet per each round.

For the bit-fixing routing algorithm defined above, regardless of the queuing policy, there always exists a bad permutation $\displaystyle{ \pi }$ which specifies the destinations, such that it takes $\displaystyle{ \Omega(\sqrt{N}) }$ steps by the bit-fixing algorithm to route all $\displaystyle{ N }$ packets to their destinations. (You can prove this by yourself.)

This is pretty bad, because we expect that the routing time is comparable to the diameter of the network, which is only $\displaystyle{ d=\log N }$ for hypercube.

The lower bound actually applies generally for any deterministic oblivious routing algorithms:

 Theorem [Kaklamanis, Krizanc, Tsantilas, 1991] In any $\displaystyle{ N }$-node communication network with maximum degree $\displaystyle{ d }$, any deterministic oblivious algorithm for routing an arbitrary permutation requires $\displaystyle{ \Omega(\sqrt{N}/d) }$ parallel communication steps in the worst case.

The proof of the lower bound is rather technical and complicated. However, the intuition is quite clear: for any oblivious rule for routing, there always exists a permutation which causes a very high congestion, such that many packets have to be delivered through the same edge, thus no matter what queuing policy is used, the maximum delay must be very high.

## Average-case analysis for independent destinations

We analyze the average-case performance of the bit-fixing routing algorithm. We relax the problem to non-permutation destinations. That is, instead of restricting that every processor has a distinct destination, we now allow each processor choose an arbitrary destination in $\displaystyle{ \{0,1\}^d }$.

For the average case, for each node $\displaystyle{ v\in\{0,1\}^d }$, its destination is a uniformly and independently random node from $\displaystyle{ \{0,1\}^d }$.

For each node $\displaystyle{ v\in\{0,1\}^d }$, let $\displaystyle{ P_v }$ denote the route for $\displaystyle{ v }$ to its random destination $\displaystyle{ r }$. $\displaystyle{ P_v }$ is a sequence of edges along the bit-fixing route from $\displaystyle{ v }$ to $\displaystyle{ r }$.

### Reduce the delay of a route to the number of packets that pass through the route

We consider the delay incurred by each node, which is the total time that its packet is waiting in the queue. The total running time of the algorithm is bounded by the maximum delay plus $\displaystyle{ d }$.

We assume that the queueing policy satisfies a very natural requirement:

Natural queuing assumption
If a queue is not empty at the beginning of a time step, some packet is sent along the edge associated with that queue during that time step.
 Lemma 2.1 With the above assumption of the queuing policy, the delay inccured by $\displaystyle{ u }$ is at most the number of packets whose routes pass through at least one edge in $\displaystyle{ P_u }$.
Proof.
 See Lemma 4.5 in the textbook [MR].
$\displaystyle{ \square }$

### Represent the delay as the sum of independent trials

Let the random variable $\displaystyle{ H_{uv} }$ indicate whether $\displaystyle{ P_u }$ and $\displaystyle{ P_v }$ share at least one edge. That is,

$\displaystyle{ H_{uv} = \begin{cases} 1 & \text{if }P_u\text{ and }P_v\text{ share at least one edge},\\ 0 & \text{otherwise}. \end{cases} }$

Fix a node $\displaystyle{ u\in\{0,1\}^d }$ and the corresponding route $\displaystyle{ P_u }$. The random variable $\displaystyle{ H_u=\sum_{v\in\{0,1\}^d}H_{uv} }$ gives the total number of packets whose routes pass through $\displaystyle{ P_u }$. Due to Lemma 2.1, $\displaystyle{ H_u }$ gives an upper bound on the delay inccured by $\displaystyle{ u }$.

We will then bound $\displaystyle{ H_u }$. Note that for $\displaystyle{ v\neq u }$, $\displaystyle{ H_{uv} }$ are independent trials (because the destinations of $\displaystyle{ u }$ and $\displaystyle{ v }$ are independent), thus we can apply the Chernoff bound. To do so, we must estimate the expectation $\displaystyle{ \mathbf{E}[H_u] }$.

### Estimate the expectation of the sum

For any edge $\displaystyle{ e }$ in the hypercube, let the random variable $\displaystyle{ T(e) }$ denote the number of routes that pass through $\displaystyle{ e }$. As we argued above that $\displaystyle{ H_u }$ is the number of packets that pass though the route $\displaystyle{ P_u }$, then obviously

$\displaystyle{ H_u\le \sum_{e\in P_u}T(e), }$

where we abuse the notation $\displaystyle{ e\in P_u }$ to denote the edge $\displaystyle{ e }$ appeared in the route $\displaystyle{ P_u }$.

Therefore,

$\displaystyle{ \mathbf{E}[H_u]\le\sum_{e\in P_u}\mathbf{E}[T(e)].\qquad\qquad(*) }$

For every node $\displaystyle{ v\in\{0,1\}^d }$, the length of the route $\displaystyle{ P_v }$, denoted $\displaystyle{ |P_v| }$, is the number of different bits between $\displaystyle{ v }$ and the last node in the route (because of the "bit-fixing"). For the uniformly random destination, $\displaystyle{ \mathbf{E}[|P_v|]=d/2 }$ (a random node in $\displaystyle{ \{0,1\}^d }$ expectedly flips $\displaystyle{ d/2 }$ bits in any fixed $\displaystyle{ v\in\{0,1\}^d }$). Thus,

$\displaystyle{ \sum_{v\in\{0,1\}^d}\mathbf{E}[|P_v|]=\frac{dN}{2}. }$

It is obvious that we can count the sum of lengths of a set of routes by accumulating their passes through edges, that is

$\displaystyle{ \sum_{v\in\{0,1\}^d}|P_v|=\sum_{e}T(e), }$

Therefore,

$\displaystyle{ \sum_{e}\mathbf{E}[T(e)] =\sum_{v\in\{0,1\}^d}\mathbf{E}[|P_v|]=\frac{dN}{2}, }$

where the sum $\displaystyle{ \sum_{e}\mathbf{E}[T(e)] }$ is taken over all edges in the hypercube.

An important observation is that the distribution of $\displaystyle{ T(e) }$'s are all symmetric, thus all $\displaystyle{ \mathbf{E}[T(e)] }$'s are equal. The number of edges in the hypercube is $\displaystyle{ \frac{dN}{2} }$. Therefore, for every edge $\displaystyle{ e }$ in the hupercube,

$\displaystyle{ \mathbf{E}[T(e)]=\frac{2}{dN}\cdot\frac{dN}{2}=1. }$

The length of $\displaystyle{ P_u }$ is at most $\displaystyle{ d }$. Due to $\displaystyle{ (*) }$, the expectation of $\displaystyle{ H_u }$ is $\displaystyle{ \mathbf{E}[H_u]\le\sum_{e\in P_u}\mathbf{E}[T(e)]\le d }$.

### Apply the Chernoff bound

We apply the following form of the Chernoff bound:

 Chernoff bound Let $\displaystyle{ X=\sum_{i=1}^n X_i }$, where $\displaystyle{ X_1, X_2, \ldots, X_n }$ are independent Poisson trials. Let $\displaystyle{ \mu=\mathbf{E}[X] }$. Then for $\displaystyle{ t\ge 2e\mu }$, $\displaystyle{ \Pr[X\ge t]\le 2^{-t}. }$

It holds that $\displaystyle{ 6d\gt 2e\mathbf{E}[H_u]=2ed }$. By applying the Chernoff bound,

$\displaystyle{ \Pr[H_u\gt 6d]\lt 2^{-6d} }$.

Note that $\displaystyle{ H_u }$ only gives the bound on the delay incurred by a particular node $\displaystyle{ u }$. By the union bound,

\displaystyle{ \begin{align} \Pr[\text{the maximum delay of Phase I}\gt 6d] &\le \Pr[\max_{u\in\{0,1\}^d}H_u\gt 6d]\\ &\le N\Pr[H_u\gt 6d]\\ &\lt N\cdot 2^{-6d}\\ &=2^{-5d}. \end{align} }

The running time is the maximum delay plus the length of a route, thus is $\displaystyle{ \gt 7d }$ with probability $\displaystyle{ \lt 2^{-5d} }$.

## A two-phase randomized routing algorithm

The above analysis of the performance of bit-fixing for independent random destinations hints us that we can first route the packets to random "relay"s to avoid the high congestion. This was first discovered by Leslie Valiant who uses the idea to give a simple and elegant randomized routing algorithm for permutation routing.

The algorithm works in two phases.

 Two-Phase Routing Algorithm For each packet: Phase I: Route the packet to a random destination using the bit-fixing algorithm. Phase II: Route the packet from the random location to its final destination using the bit-fixing algorithm.

It looks counter-intuitive that first routing the packets to irrelevant intermediate nodes actually improves the overall performance.

To simplify the analysis, we assume that no packet is sent in Phase II before all packets have finished Phase I.

Phase I is exactly the bit-fixing routing for uniformly and independently random destinations, which as we analyzed in the last section, has a running time within $\displaystyle{ 7d }$ for probability at least $\displaystyle{ 1-2^{-5d} }$.

The Phase II is a "backward" running of Phase I. All the analysis of Phase I can be directly applied to Phase II. Thus, the running time of Phase II is $\displaystyle{ \gt 7d }$ with probability $\displaystyle{ \lt 2^{-5d} }$. By the union bound, the total running time of the randomized routing algorithm is no more than $\displaystyle{ 14d=O(\log N) }$ with high probability.

# Set Balancing

Supposed that we have an $\displaystyle{ n\times m }$ matrix $\displaystyle{ A }$ with 0-1 entries. We are looking for a $\displaystyle{ b\in\{-1,+1\}^m }$ that minimizes $\displaystyle{ \|Ab\|_\infty }$.

Recall that $\displaystyle{ \|\cdot\|_\infty }$ is the infinity norm (also called $\displaystyle{ L_\infty }$ norm) of a vector, and for the vector $\displaystyle{ c=Ab }$,

$\displaystyle{ \|Ab\|_\infty=\max_{i=1,2,\ldots,n}|c_i| }$.

We can also describe this problem as an optimization:

\displaystyle{ \begin{align} \mbox{minimize } &\quad \|Ab\|_\infty\\ \mbox{subject to: } &\quad b\in\{-1,+1\}^m. \end{align} }

This problem is called set balancing for a reason.

 The problem arises in designing statistical experiments. Suppose that we have $\displaystyle{ m }$ subjects, each of which may have up to $\displaystyle{ n }$ features. This gives us an $\displaystyle{ n\times m }$ matrix $\displaystyle{ A }$: $\displaystyle{ \begin{array}{c} \mbox{feature 1:}\\ \mbox{feature 2:}\\ \vdots\\ \mbox{feature n:}\\ \end{array} \left[ \begin{array}{cccc} a_{11} & a_{12} & \cdots & a_{1m}\\ a_{21} & a_{22} & \cdots & a_{2m}\\ \vdots & \vdots & \ddots & \vdots\\ a_{n1} & a_{n2} & \cdots & a_{nm}\\ \end{array} \right], }$ where each column represents a subject and each row represent a feature. An entry $\displaystyle{ a_{ij}\in\{0,1\} }$ indicates whether subject $\displaystyle{ j }$ has feature $\displaystyle{ i }$. By multiplying a vector $\displaystyle{ b\in\{-1,+1\}^m }$ $\displaystyle{ \left[ \begin{array}{cccc} a_{11} & a_{12} & \cdots & a_{1m}\\ a_{21} & a_{22} & \cdots & a_{2m}\\ \vdots & \vdots & \ddots & \vdots\\ a_{n1} & a_{n2} & \cdots & a_{nm}\\ \end{array} \right] \left[ \begin{array}{c} b_{1}\\ b_{2}\\ \vdots\\ b_{m}\\ \end{array} \right] = \left[ \begin{array}{c} c_{1}\\ c_{2}\\ \vdots\\ c_{n}\\ \end{array} \right], }$ the subjects are partitioned into two disjoint groups: one for -1 and other other for +1. Each $\displaystyle{ c_i }$ gives the difference between the numbers of subjects with feature $\displaystyle{ i }$ in the two groups. By minimizing $\displaystyle{ \|Ab\|_\infty=\|c\|_\infty }$, we ask for an optimal partition so that each feature is roughly as balanced as possible between the two groups. In a scientific experiment, one of the group serves as a control group (对照组). Ideally, we want the two groups are statistically identical, which is usually impossible to achieve in practice. The requirement of minimizing $\displaystyle{ \|Ab\|_\infty }$ actually means the statistical difference between the two groups are minimized.

We propose an extremely simple "randomized algorithm" for computing a $\displaystyle{ b\in\{-1,+1\}^m }$: for each $\displaystyle{ i=1,2,\ldots, m }$, let $\displaystyle{ b_i }$ be independently chosen from $\displaystyle{ \{-1,+1\} }$, such that

$\displaystyle{ b_i= \begin{cases} -1 & \mbox{with probability }\frac{1}{2}\\ +1 &\mbox{with probability }\frac{1}{2} \end{cases}. }$

This procedure can hardly be called as an "algorithm", because its decision is made disregard of the input $\displaystyle{ A }$. We then show that despite of this obliviousness, the algorithm chooses a good enough $\displaystyle{ b }$, such that for any $\displaystyle{ A }$, $\displaystyle{ \|Ab\|_\infty=O(\sqrt{m\ln n}) }$ with high probability.

 Theorem Let $\displaystyle{ A }$ be an $\displaystyle{ n\times m }$ matrix with 0-1 entries. For a random vector $\displaystyle{ b }$ with $\displaystyle{ m }$ entries chosen independently and with equal probability from $\displaystyle{ \{-1,+1\} }$, $\displaystyle{ \Pr[\|Ab\|_\infty\gt 2\sqrt{2m\ln n}]\le\frac{2}{n} }$.
Proof.
 Consider particularly the $\displaystyle{ i }$-th row of $\displaystyle{ A }$. The entry of $\displaystyle{ Ab }$ contributed by row $\displaystyle{ i }$ is $\displaystyle{ c_i=\sum_{j=1}^m a_{ij}b_j }$. Let $\displaystyle{ k }$ be the non-zero entries in the row. If $\displaystyle{ k\le2\sqrt{2m\ln n} }$, then clearly $\displaystyle{ |c_i| }$ is no greater than $\displaystyle{ 2\sqrt{2m\ln n} }$. On the other hand if $\displaystyle{ k\gt 2\sqrt{2m\ln n} }$ then the $\displaystyle{ k }$ nonzero terms in the sum $\displaystyle{ c_i=\sum_{j=1}^m a_{ij}b_j }$ are independent, each with probability 1/2 of being either +1 or -1. Thus, for these $\displaystyle{ k }$ nonzero terms, each $\displaystyle{ b_i }$ is either positive or negative independently with equal probability. There are expectedly $\displaystyle{ \mu=\frac{k}{2} }$ positive $\displaystyle{ b_i }$'s among these $\displaystyle{ k }$ terms, and $\displaystyle{ c_i\lt -2\sqrt{2m\ln n} }$ only occurs when there are less than $\displaystyle{ \frac{k}{2}-\sqrt{2m\ln n}=\left(1-\delta\right)\mu }$ positive $\displaystyle{ b_i }$'s, where $\displaystyle{ \delta=\frac{2\sqrt{2m\ln n}}{k} }$. Applying Chernoff bound, this event occurs with probability at most \displaystyle{ \begin{align} \exp\left(-\frac{\mu\delta^2}{2}\right) &= \exp\left(-\frac{k}{2}\cdot\frac{8m\ln n}{2k^2}\right)\\ &= \exp\left(-\frac{2m\ln n}{k}\right)\\ &\le \exp\left(-\frac{2m\ln n}{m}\right)\\ &\le n^{-2}. \end{align} } The same argument can be applied to negative $\displaystyle{ b_i }$'s, so that the probability that $\displaystyle{ c_i\gt 2\sqrt{2m\ln n} }$ is at most $\displaystyle{ n^{-2} }$. Therefore, by the union bound, $\displaystyle{ \Pr[|c_i|\gt 2\sqrt{2m\ln n}]\le\frac{2}{n^2} }$. Apply the union bound to all $\displaystyle{ n }$ rows. $\displaystyle{ \Pr[\|Ab\|_\infty\gt 2\sqrt{2m\ln n}]\le n\cdot\Pr[|c_i|\gt 2\sqrt{2m\ln n}]\le\frac{2}{n} }$.
$\displaystyle{ \square }$

How good is this randomized algorithm? In fact when $\displaystyle{ m=n }$ there exists a matrix $\displaystyle{ A }$ such that $\displaystyle{ \|Ab\|_\infty=\Omega(\sqrt{n}) }$ for any choice of $\displaystyle{ b\in\{-1,+1\}^n }$.