随机算法 (Spring 2014)/Random Variables
Random Variable
Definition (random variable) - A random variable
on a sample space is a real-valued function . A random variable X is called a discrete random variable if its range is finite or countably infinite.
- A random variable
For a random variable
.
The independence can also be defined for variables:
Definition (Independent variables) - Two random variables
and are independent if and only if - for all values
and . Random variables are mutually independent if and only if, for any subset and any values , where ,
- Two random variables
Note that in probability theory, the "mutual independence" is not equivalent with "pair-wise independence", which we will learn in the future.
Expectation
Let
Definition (Expectation) - The expectation of a discrete random variable
, denoted by , is given by - where the summation is over all values
in the range of .
- The expectation of a discrete random variable
Linearity of Expectation
Perhaps the most useful property of expectation is its linearity.
Theorem (Linearity of Expectations) - For any discrete random variables
, and any real constants ,
- For any discrete random variables
Proof. By the definition of the expectations, it is easy to verify that (try to prove by yourself): for any discrete random variables
and , and any real constant , ; .
The theorem follows by induction.
The linearity of expectation gives an easy way to compute the expectation of a random variable if the variable can be written as a sum.
- Example
- Supposed that we have a biased coin that the probability of HEADs is
. Flipping the coin for n times, what is the expectation of number of HEADs? - It looks straightforward that it must be np, but how can we prove it? Surely we can apply the definition of expectation to compute the expectation with brute force. A more convenient way is by the linearity of expectations: Let
indicate whether the -th flip is HEADs. Then , and the total number of HEADs after n flips is . Applying the linearity of expectation, the expected number of HEADs is: .
The real power of the linearity of expectations is that it does not require the random variables to be independent, thus can be applied to any set of random variables. For example:
However, do not exaggerate this power!
- For an arbitrary function
(not necessarily linear), the equation does not hold generally. - For variances, the equation
does not hold without further assumption of the independence of and .
Conditional Expectation
Conditional expectation can be accordingly defined:
Definition (conditional expectation) - For random variables
and , - where the summation is taken over the range of
.
- For random variables
There is also a law of total expectation.
Theorem (law of total expectation) - Let
and be two random variables. Then
- Let
Distributions of Coin Flips
We introduce several important probability distributions induced by independent coin flips (independent trials), including: Bernoulli trial, geometric distribution, binomial distribution.
Bernoulli trial (Bernoulli distribution)
Bernoulli trial describes the probability distribution of a single (biased) coin flip. Suppose that we flip a (biased) coin where the probability of HEADS is
.
Geometric distribution
Suppose we flip the same coin repeatedly until HEADS appears, where each coin flip is independent and follows the Bernoulli distribution with parameter
For geometric
Binomial distribution
Suppose we flip the same (biased) coin for
A binomial random variable
As we saw above, by applying the linearity of expectations, it is easy to show that
Balls into Bins
Consider throwing
We are concerned with the following three questions regarding the balls into bins model:
- birthday problem: the probability that every bin contains at most one ball (the mapping is 1-1);
- coupon collector problem: the probability that every bin contains at least one ball (the mapping is on-to);
- occupancy problem: the maximum load of bins.
Birthday Problem
There are
Due to the pigeonhole principle, it is obvious that for
We can model this problem as a balls-into-bins problem.
: there is no bin with more than one balls (i.e. no two students share birthday).
We first analyze this by counting. There are totally
Thus the probability is given by:
Recall that
There is also a more "probabilistic" argument for the above equation. To be rigorous, we need the following theorem, which holds generally and is very useful for computing the AND of many events.
By the definition of conditional probability, . Thus, . This hints us that we can compute the probability of the AND of events by conditional probabilities. Formally, we have the following theorem:Theorem:
- Let
be any events. Then
Proof: It holds that
. Thus, let and , thenRecursively applying this equation to
until there is only left, the theorem is proved.- Let
Now we are back to the probabilistic analysis of the birthday problem, with a general setting of
The first student has a birthday (of course!). The probability that the second student has a different birthday is
which is the same as what we got by the counting argument.

There are several ways of analyzing this formular. Here is a convenient one: Due to Taylor's expansion,
The quality of this approximation is shown in the Figure.
Therefore, for
Coupon Collector
Suppose that a chocolate company releases
The coupon collector problem can be described in the balls-into-bins model as follows. We keep throwing balls one-by-one into
Theorem - Let
be the number of balls thrown uniformly and independently to bins until no bin is empty. Then , where is the th harmonic number.
- Let
Proof. Let be the number of balls thrown while there are exactly nonempty bins, then clearly .When there are exactly
nonempty bins, throwing a ball, the probability that the number of nonempty bins increases (i.e. the ball is thrown to an empty bin) is is the number of balls thrown to make the number of nonempty bins increases from to , i.e. the number of balls thrown until a ball is thrown to a current empty bin. Thus, follows the geometric distribution, such thatFor a geometric random variable,
.Applying the linearity of expectations,
where
is the th Harmonic number, and . Thus, for the coupon collectors problem, the expected number of coupons required to obtain all types of coupons is .
Only knowing the expectation is not good enough. We would like to know how fast the probability decrease as a random variable deviates from its mean value.
Theorem - Let
be the number of balls thrown uniformly and independently to bins until no bin is empty. Then for any .
- Let
Proof. For any particular bin , the probability that bin is empty after throwing balls isBy the union bound, the probability that there exists an empty bin after throwing
balls is
Stable Marriage
We now consider the famous stable marriage problem or stable matching problem (SMP). This problem captures two aspects: allocations (matchings) and stability, two central topics in economics.
An instance of stable marriage consists of:
men and women;- each person associated with a strictly ordered preference list containing all the members of the opposite sex.
Formally, let
A matching is a one-one correspondence
Definition (stable matching) - A pair
of a man and woman is a blocking pair in a matching if and are not partners in but prefers to , and prefers to .
- A matching
is stable if there is no blocking pair in it.
- A pair
It is unclear from the definition itself whether stable matchings always exist, and how to efficiently find a stable matching. Both questions are answered by the following proposal algorithm due to Gale and Shapley.
The proposal algorithm (Gale-Shapley 1962) - Initially, all person are not married;
- in each step (called a proposal):
- an arbitrary unmarried man
proposes to the woman who is ranked highest in his preference list among all the women who has not yet rejected ; - if
is still single then accepts the proposal and is married to ; - if
is married to another man who is ranked lower than in her preference list then divorces (thus becomes single again and considers himself as rejected by ) and is married to ; - if otherwise
rejects ;
- an arbitrary unmarried man
The algorithm terminates when the last single woman receives a proposal. Since for every pair
It is obvious to see that the algorithm retruns a macthing, and this matching must be stable. To see this, by contradiction suppose that the algorithm resturns a macthing
We are interested in the average-case performance of this algorithm, that is, the expected number of proposals if everyone's preference list is a uniformly and independently random permutation.
The following principle of deferred decisions is quite useful in analysing performance of algorithm with random input.
Principle of deferred decisions - The decision of random choice in the random input can be deferred to the running time of the algorithm.
Apply the principle of deferred decisions, the deterministic proposal algorithm with random permutations as input is equivalent to the following random process:
- At each step, a man
choose a woman uniformly and independently at random to propose, among all the women who have not rejected him yet. (sample without replacement)
We then compare the above process with the following modified process:
- The man
repeatedly samples a uniform and independent woman to propose among all women, until he successfully samples a woman who has not rejected him and propose to her. (sample with replacement)
It is easy to see that the modified process (sample with replacement) is no more efficient than the original process (sample without replacement) because it simulates the original process if at each step we only count the last proposal to the woman who has not rejected the man. Such comparison of two random processes by forcing them to be related in some way is called coupling.
Note that in the modified process (sample with replacement), each proposal, no matter from which man, is going to a uniformly and independently random women. And we know that the algorithm terminated once the last single woman receives a proposal, i.e. once all
Occupancy Problem
Now we ask about the loads of bins. Assuming that
An easy analysis shows that for every bin
Because there are totally
Therefore, due to the linearity of expectations,
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
Next we analyze the distribution of the maximum load. We show that when
Theorem - Suppose that
balls are thrown independently and uniformly at random into bins. For , let be the random variable denoting the number of balls in the th bin. Then
- Suppose that
Proof. Let be an integer. Take bin 1. For any particular balls, these balls are all thrown to bin 1 with probability , and there are totally distinct sets of balls. Therefore, applying the union bound,According to Stirling's approximation,
, thusFigure 1 Due to the symmetry. All
have the same distribution. Apply the union bound again,When
,Therefore,
When
Formally, it can be proved that for