# Randomized Algorithms (Spring 2010)/Tail inequalities

When applying probabilistic analysis, we often want a bound in form of for some random variable (think that is a cost such as running time of a randomized algorithm). We call this a **tail bound**, or a **tail inequality**.

In principle, we can bound by directly estimating the probability of the event that . Besides this *ad hoc* way, we want to have some general tools which estimate tail probabilities based on certain information regarding the random variables.

## The Moment Methods

### Markov's inequality

One of the most natural information about a random variable is its expectation, which is the first moment of the random variable. Markov's inequality draws a tail bound for a random variable from its expectation.

**Theorem (Markov's Inequality)**- Let be a random variable assuming only nonnegative values. Then, for all ,

- Let be a random variable assuming only nonnegative values. Then, for all ,

**Proof.**Let be the indicator such that It holds that . Since is 0-1 valued, . Therefore,

- Example (from Las Vegas to Monte Carlo)

Let be a Las Vegas randomized algorithm for a decision problem , whose expected running time is within on any input of size . We transform to a Monte Carlo randomized algorithm with bounded one-sided error as follows:

- :
- Run for long where is the size of .
- If returned within time, then return what just returned, else return 1.

Since is Las Vegas, its output is always correct, thus only errs when it returns 1, thus the error is one-sided. The error probability is bounded by the probability that runs longer than . Since the expected running time of is at most , due to Markov's inequality,

thus the error probability is bounded.

This easy reduction implies that **ZPP****RP**.

#### Generalization

For any random variable , for an arbitrary non-negative real function , the is a non-negative random variable. Applying Markov's inequality, we directly have that

This trivial application of Markov's inequality gives us a powerful tool for proving tail inequalities. With the function which extracts more information about the random variable, we can prove sharper tail inequalities.

### Variance

**Definition (variance)**- The
**variance**of a random variable is defined as - The
**standard deviation**of random variable is

- The

We have seen that due to the linearity of expectations, the expectation of the sum of variable is the sum of the expectations of the variables. It is natural to ask whether this is true for variances. We find that the variance of sum has an extra term called covariance.

**Definition (covariance)**- The
**covariance**of two random variables and is

- The

We have the following theorem for the variance of sum.

**Theorem**- For any two random variables and ,
- Generally, for any random variables ,

- For any two random variables and ,

**Proof.**The equation for two variables is directly due to the definition of variance and covariance. The equation for variables can be deduced from the equation for two variables.

We will see that when random variables are independent, the variance of sum is equal to the sum of variances. To prove this, we first establish a very useful result regarding the expectation of multiplicity.

**Theorem**- For any two independent random variables and ,

- For any two independent random variables and ,

**Proof.**

With the above theorem, we can show that the covariance of two independent variables is always zero.

**Theorem**- For any two independent random variables and ,

- For any two independent random variables and ,

**Proof.**

We then have the following theorem for the variance of the sum of pairwise independent random variables.

**Theorem**- For
**pairwise**independent random variables ,

- For

- Remark
- The theorem holds for
**pairwise**independent random variables, a much weaker independence requirement than the**mutual**independence. This makes the variance-based probability tools work even for weakly random cases. We will see what it exactly means in the future lectures.

#### Variance of binomial distribution

For a Bernoulli trial with parameter .

The variance is

Let be a binomial random variable with parameter and , i.e. , where 's are i.i.d. Bernoulli trials with parameter . The variance is

### Chebyshev's inequality

With the information of the expectation and variance of a random variable, one can derive a stronger tail bound known as Chebyshev's Inequality.

**Theorem (Chebyshev's Inequality)**- For any ,

- For any ,

**Proof.**Observe that Since is a nonnegative random variable, we can apply Markov's inequality, such that

### Higher moments

The above two inequalities can be put into a general framework regarding the **moments** of random variables.

**Definition (moments)**- The th moment of a random variable is .

The more we know about the moments, the more information we have about the distribution, hence in principle, we can get tighter tail bounds. This technique is called the th moment method.

We know that the th moment is . More generally, the th moment about is . The central moment of , denoted , is defined as . So the variance is just the second central moment .

The th moment method is stated by the following theorem.

**Theorem (the th moment method)**- For even , and any ,

- For even , and any ,

**Proof.**Apply Markov's inequality to .

How about the odd ? For odd , we should apply Markov's inequality to , but estimating expectations of absolute values can be hard.

## Select the Median

The selection problem is the problem of finding the th smallest element in a set . A typical case of selection problem is finding the **median**.

**Definition**- The median of a set is the th element in the sorted order of .

The median can be found in time by sorting. There is a linear-time deterministic algorithm, "median of medians" algorithm, which is quite sophisticated. Here we introduce a much simpler randomized algorithm which also runs in linear time.

### Randomized median selection algorithm

We introduce a randomized median selection algorithm called **LazySelect**, which is a variant on a randomized algorithm due to Floyd and Rivest

The idea of this algorithm is random sampling. For a set , let denote the median. We observe that if we can find two elements satisfying the following properties:

- The median is between and in the sorted order, i.e. ;
- The total number of elements between and is small, specially for , .

Provided and with these two properties, within linear time, we can compute the ranks of in , construct , and sort . Therefore, the median of can be picked from in linear time.

So how can we select such elements and from ? Certainly sorting would give us the elements, but isn't that exactly what we want to avoid in the first place?

Observe that and are only asked to roughly satisfy some constraints. This hints us maybe we can construct a *sketch* of which is small enough to sort cheaply and roughly represents , and then pick and from this sketch. We construct the sketch by randomly sampling a relatively small number of elements from . Then the strategy of algorithm is outlined by:

- Sample a set of elements from .
- Sort and choose and somewhere around the median of .
- If and have the desirable properties, we can compute the median in linear time, or otherwise the algorithm fails.

The parameters to be fixed are: the size of (small enough to sort in linear time and large enough to contain sufficient information of ); and the order of and in (not too close to have between them, and not too far away to have sortable in linear time).

We choose the size of as , and and are within range around the median of .

**LazySelect****Input:**a set of elements over totally ordered domain.- Pick a multi-set of elements in , chosen independently and uniformly at random with replacement, and sort .
- Let be the -th smallest element in , and let be the -th smallest element in .
- Construct and compute the ranks and .
- If or or then return FAIL.
- Sort and return the th element in the sorted order of .

"Sample with replacement" (有放回采样) means that after sampling an element, we put the element back to the set. In this way, each sampled element is independently and identically distributed (*i.i.d*) (独立同分布). In the above algorithm, this is for our convenience of analysis.

### Analysis

The algorithm always terminates in linear time because each line of the algorithm costs at most linear time. The last three line guarantees that the algorithm returns the correct median if it does not fail.

We then only need to bound the probability that the algorithm returns a FAIL. Let be the median of . By Line 4, we know that the algorithm returns a FAIL if and only if at least one of the following events occurs:

- ;
- ;
- .

directly follows the third condition in Line 4. and are a bit tricky. The first condition in Line 4 is that , which looks not exactly the same as , but both and that are equivalent to the same event: the -th smallest element in is greater than , thus they are actually equivalent. Similarly, is equivalent to the second condition of Line 4.

We now bound the probabilities of these events one by one.

**Lemma 1**- .

**Proof.**Let be the th sampled element in Line 1 of the algorithm. Let be a indicator random variable such that It is obvious that , where is as defined in . For every , there are elements in that are less than or equal to the median. The probability that is

which is within the range of . Thus

The event is defined as that .

Note that 's are Bernoulli trials, and is the sum of Bernoulli trials, which follows binomial distribution with parameters and . Thus, the variance is

Applying Chebyshev's inequality,

By a similar analysis, we can obtain the following bound for the event .

**Lemma 2**- .

We now bound the probability of the event .

**Lemma 3**- .

**Proof.**The event is defined as that , which by the Pigeonhole Principle, implies that at leas one of the following must be true: - : at least elements of is greater than ;
- : at least elements of is smaller than .

We bound the probability that occurs; the second will have the same bound by symmetry.

Recall that is the region in between and . If there are at least elements of greater than the median of , then the rank of in the sorted order of must be at least and thus has at least samples among the largest elements in .

Let indicate whether the th sample is among the largest elements in . Let be the number of samples in among the largest elements in . It holds that

- .

is a binomial random variable with

and

Applying Chebyshev's inequality,

Symmetrically, we have that .

Applying the union bound

Combining the three bounds. Applying the union bound to them, the probability that the algorithm returns a FAIL is at most

Therefore the algorithm always terminates in linear time and returns the correct median with high probability.

## 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 , the more information we would have about . There is a so-called **moment generating function**, which "packs" all the information about the moments of into one function.

**Definition**- The moment generating function of a random variable is defined as where is the parameter of the function.

By Taylor's expansion and the linearity of expectations,

The moment generating function is a function of .

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

**Chernoff bound (the upper tail)**- Let , where are independent Poisson trials. Let .
- Then for any ,

**Proof.**For any , is equivalent to that , thus where the last step follows by Markov's inequality.

Computing the moment generating function :

Let for . Then,

- .

We bound the moment generating function for each individual as follows.

where in the last step we apply the Taylor's expansion so that where . (By doing this, we can transform the product to the sum of , which is .)

Therefore,

Thus, we have shown that for any ,

- .

For any , we can let to get

The idea of the proof is actually quite clear: we apply Markov's inequality to and for the rest, we just estimate the moment generating function . To make the bound as tight as possible, we minimized the by setting , which can be justified by taking derivatives of .

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

**Chernoff bound (the lower tail)**- Let , where are independent Poisson trials. Let .
- Then for any ,

**Proof.**For any , by the same analysis as in the upper tail version, For any , we can let to get

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 , where are independent Poisson trials. Let . Then
- 1. for ,
- 2. for ,

**Proof.**To obtain the bounds in (1), we need to show that for , and . We can verify both inequalities by standard analysis techniques. To obtain the bound in (2), let . Then . Hence,

### Balls into bins, revisited

Throwing balls uniformly and independently to 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 and , let be the indicator variable for the event that ball is thrown to bin . Obviously

Let be the load of bin .

Then the expected load of bin is

For the case , it holds that

Note that is a sum of mutually independent indicator variable. Applying Chernoff bound, for any particular bin ,

#### When

When , . Write . The above bound can be written as

Let , we evaluate by taking logarithm to its reciprocal.

Thus,

Applying the union bound, the probability that there exists a bin with load is

- .

Therefore, for , with high probability, the maximum load is .

#### For larger

When , then according to ,

We can apply an easier form of the Chernoff bounds,

By the union bound, the probability that there exists a bin with load is,

- .

Therefore, for , with high probability, the maximum load is .