0% found this document useful (0 votes)
58 views53 pages

Introduction to Randomized Algorithms

Uploaded by

Lê Bảo Khánh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views53 pages

Introduction to Randomized Algorithms

Uploaded by

Lê Bảo Khánh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AN INTRODUCTION TO

RANDOMIZED ALGORITHMS
Nguyen An Khuong, CSE-HCMUT

HCMUT Advanced Algorithms Course (CO5127), Lecture on February 13, 2025


(Materials drawn from CLRS’22, Chapters 5,7)

1/ 53
Outline
Introduction
Miller-Rabin PRIMARILY TEST
QUICKSORT
Karger’s MINIMUM CUT
SELECTION Problem
Introduction
Deterministic algorithm
Divide-and-conquer with random pivoting
Random sampling strategy for selection
Appendix: Discrete Random variables
References and Further Reading
2/ 53
1. Introduction

3/ 53
Deterministic algorithms vs randomized algorithms
▶ Deterministic:
input Algorithm output

Goal: To prove that the the algorithm solves the problem correctly (always)
and quickly (typically, the number of steps should be polynomial in the
size of the input.)
In other words, for all inputs, output is good.
▶ Randomized:
input Algorithm output

random bits
▶ In addition to input, the algorithm takes a source of random numbers and
makes random choices during execution. Behavior can vary even on a fixed
input. Output is good for all inputs with good probability. 4/ 53
Randomized Algorithms vs Probabilistic Analysis of Algorithms
input Algorithm output

random bits
Goal: Design algorithm + analysis to show that this behavior is likely to be
good on every input?
(The likelihood is over the random numbers only.)
▶ Not to be confused with the Probabilistic Analysis of Algorithms:

random input Algorithm output distribution

Here the input is assumed to be from a probability distribution.


Goal: To show that the algorithm works for most inputs.
5/ 53
Types of randomized algorithms: Monte Carlo vs Las Vegas
▶ A Monte Carlo (MC) algorithm runs for a fixed number of steps and
produces a correct answer with good probability, say ≥ 1/3. Example:
Karger’s min-cut algorithm
▶ A Las Vegas (LV) algorithm always produces the correct answer. Its
running time is a random (small time with good probability) variable whose
expectation is bounded (say by a poly.) Examples: Quicksort, Hashing,...
▶ These probabilities/expectations are only over the random choices made by
the algorithm - independent of the input.
▶ Thus, independent repetitions of Monte Carlo algorithms exponentially drive
down the failure probability.
▶ It’s easy to see the following:
1. LV =⇒ MC. Fix a time T . If the algorithm terminates before T , we output
the answer, otherwise, we output 1.
2. MC does not always imply LV. The implications hold when verifying a
solution can be done much faster than finding one. In that case, we test the
output of the MC algorithm and stop only when a correct solution is found. 6/ 53
Advantages of randomized algorithms
▶ The goals are simplicity, speed (performance), and sometimes other
objectives depending on the problem (e.g., for Nash Equilibrium, the
problem inherently requires randomization).
▶ For many probs, a randomized algorithm is the simplest, the fastest, or both.
▶ Themes:
▶ Avoiding adversarial inputs (“adversarial” may mean well-structured, i.e.
natural). Randomization makes your data look random, even if it is not
(think Quicksort).
▶ Fingerprinting (have a quick identifier for a complex structure)
▶ Load balancing (distribute workload across resources to optimize time
consumption or efficiency, or avoid overloads)
▶ Sampling (estimate properties of the whole population based on a subset)
▶ Symmetry breaking (e.g., what to do when two packets arrive
simultaneously?)
▶ Probabilistic existence proofs (Erdos, Lovasz... if a random object satisfies a
property with non-zero probability, we just proved that such an object exists.) 7/ 53
Scope of randomized algorithms
▶ Number theoretic algorithms: Primality testing (Monte Carlo)
▶ Data structures: Sorting, order statistics, searching, comp. geometry.
▶ Algebraic identities: Polynomial and matrix identity verification. Interactive
pro of systems.
▶ Mathematical programming: Faster algorithms for linear programming.
Rounding linear program solutions to integer program solutions.
▶ Graph algorithms: Minimum spanning trees, shortest paths, minimum cuts.
▶ Counting and enumeration. Matrix permanent. Counting combinatorial
structures.
▶ Parallel and distributed computing. Deadlock avoidance distributed
consensus.
▶ Probabilistic existence proofs: Show that a combinatorial object arises with
non-zero probability among objects drawn from a suitable probability space.
▶ Derandomization: First, devise a randomized algorithm, then argue that it
can be ”derandomized” to yield a deterministic algorithm. 8/ 53
2. Miller-Rabin PRIMARILY TEST

9/ 53
Introduction

▶ Proposed in 70’s.
▶ Miller and Rabin gave two versions of the same algorithm to test whether a
number n is prime or not.
▶ Whereas Rabin’s algorithm works with a randomly chosen a ∈ Zn , and is
therefore a randomized one, Miller’s version tests deterministically for all a’s,
where 1 ≤ a ≤ 4 log2 n.
▶ But the correctness of Miller’s algorithm depends on the correctness of
Extended Riemann Hypothesis.

10/ 53
Miller-Rabin Algorithm

▶ Let ψ be an automorphism in Zn .
▶ Let n − 1 = s × 2t for odd s.
▶ the ALGORITHM
1. Test if n = mj for j > 1. If yes, output COMPOSITE.
2. Randomly choose a ∈ Zn .
3. Test if an−1 = 1( mod n). If no, output COMPOSITE.
i
4. Compute ui = as×2 ( mod n) for 0 ≤ i < t.
5. If there is an i such that ui = 1 and ui−1 ̸= ±1, output COMPOSITE.
6. output PRIME.

11/ 53
Correctness of Miller-Rabin Algorithm

▶ Observation: Pr [test is correct | n is prime ] = 1.


a∈Zn
▶ THEOREM Pr [test outputs PRIME | n is composite ]
a∈Zn
≤ + =
1
4
1
4
1
2
▶ Hence the test is correct with probability ≥ 21 .
▶ The probability of success can be boosted further by repeating the test a
few times, where output will be COMPOSITE if any of the single test
output is COMPOSITE, else PRIME.

12/ 53
Time Complexity of Miller-Rabin Algorithm

▶ Computing u0 : O(log n) × O(log s) = O(log2 n)


▶ [ by repeated squaring O(log s) times, s ≤ n, then multiplying and taking
modulo n each time all with log n bits numbers using FFT takes Õ(log n)
time ]
▶ Computing u1 , u2 , · · · , ut : O(log2 n) [ t ≤ log n, squaring and taking
modulo n takes O(log n) time ].
▶ Testing if n = mj holds for some j > 1 can be done in O(log2 n) time.
▶ Hence the time complexity of the algorithm is O(log n).

13/ 53
3. QUICKSORT

14/ 53
The algorithm
Our goal is to sort of a sequence S = (x1 , ..., xn ) of n distinct real numbers in
increasing order. We use a recursive method known as Quicksort which
proceeds as follows:
Algorithm (Hoare, 1962)
1. If S has one or zero elements return S.
2. Pick some element x = xi in S called the pivot.
3. Reorder S in such a way that for every number xj ̸= x in S, if xj < x , then
xj is moved to a list S1 , else if xj > x then xj is moved to a list S2 .
4. Apply this algorithm recursively to the list of elements in S1 and to the list
of elements in S2 .
5. Return the sorted list S1 , x , S2 .

15/ 53
Quicksort Demonstration
Given

16/ 53
Quicksort’s Average Running Time Analysis
▶ To have a good “average performance,” one can randomize this algorithm
by assuming that each pivot is chosen at random.
▶ Let us compute the expectation of the number X of comparisons needed
when running the randomized version of Quicksort.
▶ Recall that the input is a sequence S = (x1 , ..., xn ) of distinct elements, and
that (y1 , ..., yn ) has the same elements sorted in increasing order.
▶ In order to compute E (X ), we decompose X as a sum of indicator variables
Xi,j , with Xi,j = 1 iff yi and yj are ever compared, and Xi,j = 0 otherwise.
j−1
n X j−1
n X
▶ Then, it is clear that X = Xi,j and E (X ) = E (Xi,j ).
X X

j=2 i=1 j=2 i=1


▶ Furthermore, since Xi,j is an indicator variable, we have
E (Xi,j ) = P(yi and yj are ever compared).
17/ 53
Quicksort’s Average Running Time Analysis (cont’d)
▶ The crucial observation is that yi and yj are ever compared iff either yi OR
yj is chosen as the pivot when {yi , yi+1 , ..., yj } is a subset of the set of
elements of the (left or right) sublist considered for the choice of a pivot.
▶ It remains to compute the probability that the next pivot chosen in the
sublist Yi,j = {yi , yi+1 , ..., yj } is yi (or that the next pivot chosen is yj , but
the two probabilities are equal).
▶ Since the pivot is one of the values in {yi , yi+1 , ..., yj } and since each of
these is equally likely to be chosen (by hypothesis), we have
P(yi is chosen as the next pivot in Yi,j ) = j−i+1 1
.
▶ Consequently, since yi and yj are ever compared iff either yi is chosen as a
pivot or yj is chosen as a pivot, and since these two events are mutually
exclusive, we have
E (Xi,j ) = P(yi and yj are ever compared) = j−i+1 2
.
18/ 53
Quicksort’s Average Running Time Analysis (cont’d)
j−1
n X j−1
n X
2
▶ It follows that E (X ) = E (Xi,j ) =
X X

j=2 i=1 j=2 i=1 j −i +1


n j
1 n X
n
1
=2 , (set k = j − i + 1) = 2
X X X

j=2 k=2 k k=2 j=k k


n
n−k +1 n
1 n
=2 = 2(n + 1) + 2 (−1)
X X X

k=2 k k=2 k k=2


n
1
= 2(n + 1) − 4n.
X

k=1 k
▶ The quantity Hn = 1 + 1/2 + 1/3 + ... + 1/n is called the “nth harmonic
number”, and is in the range [ln n, 1 + ln n] (this can be seen by considering
the integral 1n x1 dx ).
R

▶ Therefore, E (X ) ∈ [2(n + 1) ln n − 4n, (2(n + 1) ln n − 4n) + (2 − 2n)].


▶ In other words, E (X ) ∈ Θ(n ln n).
19/ 53
Approximation of the nth harmonic number Hn
1 1 1
▶ The exact expression for Hn := 1 + + + · · · + is not known, but we
2 3 n
can estimate Hn as below.
▶ Let us consider the area under the curve x1 when x varies from 1 to n.
1 1 1 1
▶ We note that Hn − = 1 + + + · · · + is an overestimation of
n 2 3 n−1
this area by rectangles. See below.

▶ So, < Hn − n1 .
Rn 1
1 x dx 20/ 53
Approximation of the nth harmonic number Hn (cont’d)
1 1 1
▶ Moreover Hn − 1 = + + · · · + is an underestimation of the area:
2 3 n

▶ Hence, Hn − 1 < 1n x1 dx . Therefore, Hn − 1 < 1n x1 dx < Hn − n1 ,


R R

or, ln n + n1 < Hn < ln n + 1.


▶ Also, Euler discovered this beautiful property of Hn that
limn→∞ (Hn − ln n) = γ ≈ 0.57721. . . (called the Euler-Mascheroni
constant.) 21/ 53
4. Karger’s MINIMUM CUT

22/ 53
Introduction
▶ Given a graph G = (V , E ) with n vertices and m edges, find a global
minimum cut?
▶ That is to find a set of vertices S ⊂ V , with 1 ≤ |S| ≤ n − 1, which
minimizes the number of edges going from this subset S to the rest of the
vertices.
▶ We denote the cut value for set S by |E (S, S̄)| (where S̄ = V \ S).
▶ The problem of finding a minimum cut with a given source and sink (s − t
min cut) is probably more familiar.
▶ Dinic’s algorithm or Ford-Fulkerson algorithm leads to a solution.
▶ We can compute a s − t minimum cut in O(n3 ).
▶ By running this algorithm for all (s, t) pairs, we get a solution for the global
minimum cut in O(n5 ).
23/ 53
The Algorithm
Algorithm It looks “stupid”, but actually it’s not that stupid.
1: function Algo1
2: while n > 2 do
3: Choose an edge e = (u, v ) randomly from the remaining edges
4: Contract that edge
5: end while
6: return the two last vertices
7: end function
▶ Contracting an edge means we remove that edge and combine the two
vertices into a super-node.
▶ We note that self-loops thus formed are removed, but any resulting parallel
edges are not removed. This means at every step, we have a multi-graph
without any self-loops.
▶ This algorithm will yield a cut. The minimum cut? Probably not. But maybe!
▶ If the graph is somewhat dense, then choosing an edge in the minimum cut
is rather unlikely at the beginning... and very likely at the end. 24/ 53
Analyzing the probability of the correct answer
▶ Let’s say that the algorithm “fails” in step i if, in that step, we choose to
contract an edge in the minimum cut (here, we suppose that there is only
one minimum cut).
▶ For all u ∈ V , let d(u) be the degree of u. We have
1 X 2·m
|E (S, S̄)| ≤ min d(u) ≤ d(u) = .
u n u∈V n
▶ So, |E (S,
m
S̄)|
≤ n2 .
▶ We fail in the first step if we pick an edge in the minimum cut, an event
|E (S, S̄)| 2
that occurs with probability: P(fail in 1st step) = ≤ .
m n
2
P(fail in 2nd step | success in 1st step) ≤
n−1
···
2
P(fail in i th step | success till (i − 1)th step) ≤ .
n−i +1 25/ 53
Analyzing the probability of the correct answer (cont’d)
▶ Let Zi be the event that the algorithm succeeds in step i. Thus, we have
n−2
P(Z1 ) ≥
n
n−3
P(Z2 |Z1 ) ≥
n−1
···
n−i −1
P(Zi |Zi−1 ∩ · · · ∩ Z1 ) ≥
n−i +1
▶ , Therefore, P(Success) = P(Z1 ∩ Z2 ∩ · · · ∩ Zn−2 )
= P(Z1 ) · P(Z2 |Z1 ) · · · P(Zn−2 |Z1 ∩ Z2 ∩ · · · ∩ Zn−3 )
n−2 n−3 n−4 n−5 2 1
≥ · · · ··· ·
n n−1 n−2 n−3 4 3
1 1 2 1 2
= · · · ≥ 2.
n n−1 1 1 n 26/ 53
Analyzing the probability of the correct answer (cont’d)
▶ If n is too large, this is a very poor guarantee.
▶ So what we do instead is run the algorithm several times and choose the
best min-cut we find. If we run this algorithm k times, we then have:

2
 k
P(Success at least once) ≥ 1 − 1 − 2 .
n
1
▶ A classical inequality yields (1 − z) z ≤ 1e .
▶ We hence choose to run the algorithm k times, with k = n2
2
log 1δ .
▶ We get:
 log δ1
1
P(Success) ≥ 1 − = 1 − δ.
e
▶ After running all these k trials, we choose the one with the min. cut value.
27/ 53
Complexity

▶ At every step of the algorithm, we have to contract an edge. This takes at


most O(n) time.
▶ We do at most n such contractions. Thus, we need O(n2 ) time for every
run.
2
▶ We can choose δ to be, say 1/4, and thus k = n2 log 4 and this will ensure
that within O(n4 ) time the algorithm succeeds with probability at least 3/4.

28/ 53
Min-Cut: Can we do better?
▶ Initial stages of the algorithm are very likely to be correct.
▶ In particular, the first step is wrong with probability at most 2/n.
▶ As we contract more edges, failure probability goes up.
▶ Moreover, earlier stages take more time compared to later ones.
▶ Idea: Let us redistribute our iterations. Since earlier ones are more accurate
and slower, why not do less at the beginning and increasingly more as the
number of edges decreases?
▶ Let us formalize this idea. After t steps:
n−2 n−3 n−3 n−t −1 (n − t)2
P(Success) ≥ · · ··· ≈ .
n n−1 n−1 n−t +1 n2
▶ We equate this to 12 to get t = n − √n . Thus, we have the following
2
algorithm:...
29/ 53
A better MIN-CUT
Algorithm Getting better
1:function Algo2
2: Repeat Twice: √
3: Run contraction from n → n/ √ 2
4: Recursively call Algo2 on n/ 2 set
5: return the last two vertices for the best cut among the two
6:end function
Runtime analysis:
!!
n
T (n) = 2 O(n2 ) + T √
2
!2
n
= 2cn2 + 2 · 2 · c · √ + ···
2
= O(n log n).
2
30/ 53
Success Probability

p(n) = 1 − (1 − success in one branch)2


!!2
1 n
=1− 1− p √
2 2
!!2
1 n
=1− 1− p √
2 2
!2
1
!
n n
=p √ − p √
2 4 2
▶ To solve this recursion, we let x = log√2 n. Thus, setting f (x ) = p(n), we
get f (x ) = f (x − 1) − f (x − 1)2 .
▶ We observe that setting f (x ) = x1 gives:
1 1 1 1
f (x − 1) − f (x ) = − = ≈ = f (x − 1)2 .
x −1 x x (x − 1) (x − 1)2 31/ 53
Extension: The number of MIN-CUT
▶ Question: What is the maximum number of global min-cuts an undirected
graph G can have?
▶ Not obvious. Consider a directed graph as follows: s together with any
subset of v1 , ..., vn constitutes a minimum s − t cut. ( 2n cuts in total.)

Theorem. An undirected graph G on n nodes has at most Cn2 global


min-cuts.
Proof:
▶ Suppose there are r global min-cut c1 , ..., cr ; Let Ci denote the event that ci
is reported, and C denote the success of Contraction algo;
▶ For each i, we have Pr [Ci ] ≥ 12 .
Cn
▶ Thus Pr [C ] = Pr [C1 ∪ ... ∪ Cr ]= i Pr [Ci ] ≥ r 12 . (Note: = since all Ci are
P
Cn
disjoint. )
▶ We get r ≤ Cn2 . (r 12 ≤ 1.)
C n 32/ 53
5. SELECTION Problem

33/ 53
Selection problem

INPUT: Given a set of number S = {a1 , a2 , ..., an }, and a number k ≤ n;


OUTPUT: the k-th smallest item in general case (or the median of S as a
special case).
For example, given a set S = {18, 15, 27, 13, 1, 7, 25}, the objective is the
median of S. Note:
▶ Brute-force: polynomial time;
▶ Divide-and-conquer: reduce the running time to a lower polynomial;
▶ A feasible strategy is to sort S first, and then report the k-th one, which
takes O(n log n) time.
▶ Divide-and-conquer becomes more powerful when combined with
randomization: It is possible to develop a faster algorithm, say the
deterministic linear algorithm (16n comparisons) by Blum et al.
34/ 53
A general divide-and-conquer paradigm
Algorithm Select(S, k)
1: Choose an item si from S as a pivot;
2: S + = {};
3: S − = {};
4: for j = 1 to n do
5: if sj > si then
6: S + = S + ∪ {sj };
7: else
8: S − = S − ∪ {sj };
9: end if
10: end for
11: if |S − | = k − 1 then
12: return si ;
13: else if |S − | > k − 1 then
14: return Select(S − , k);
15: else
16: return Select(S + , k − 1 − |S − |);
17: end if
35/ 53
Perform iteration on ONLY one subset.

Intuition:
1. At first, an element ai is chosen to split S into two parts
S + = {aj : aj ≥ ai }, and S − = {aj : aj < ai }.
2. We can determine whether the k-th median is in S + or S − .
3. Thus, we perform iteration on ONLY one subset.

36/ 53
How to choose a splitter?
We have the following options:
▶ Bad choice: select the smallest element at each iteration.
T (n) = T (n − 1) + O(n) = O(n2 )
▶ Ideal choice: select the median at each iteration. T (n) = T ( n2 ) + O(n) = O(n)
▶ Good choice: select a “centered” element ai , i.e., |S + | ≥ ϵn, and |S − | ≥ ϵn for a
fixed ϵ > 0.
▶ T (n) ≤ T ((1 − ϵ)n) + O(n) ≤ cn + c(1 − ϵ)n + c(1 − ϵ)2 n + .... = O(n).
▶ e.g.: ϵ = 14 :

37/ 53
BFPRT algorithm: a linear deterministic algorithm

▶ Still using the idea of choosing a splitter. The ideal splitter is the median;
however, finding the median is precisely our objective.
▶ Thus, just try to get “something close to the median”, say within n4 from
the median.
▶ How can we get something close to the median? Instead of finding the
median of the “whole set”, find a median of a “sample”.
▶ But how to choose a sample? Medians again!

38/ 53
Median of medians algorithm [Blum, 1973]
Algorithm “Median of medians”
1: Line up elements in groups of 5 elements;
2: Find the median of each group; (takes O( 6n 5
) time)
3: Find the median of medians (denoted as M); (takes T ( n5 ) time)
4: Use M as a splitter to partition the input and call the algorithm recursively on
one of the partitions.

Analysis: T (n) = T ( n5 ) + T ( 7n
10
) + 6n
5
at most 24n comparisons (here, 7n10
comes
from the fact that at least 3n
10
can be deleted by using M as the splitter.) 39/ 53
Randomized divide-and-conquer
Algorithm RandomSelect(n, k)
1: Choose an element si from S uniformly at random;
2: S + = {};
3: S − = {};
4: for j = 1 to n do
5: if sj > si then
6: S + = S + ∪ {sj };
7: else
8: S − = S − ∪ {sj };
9: end if
10: end for
11: if |S − | = k − 1 then
12: return si ;
13: else if |S − | > k − 1 then
14: return RandomSelect(S − , k);
15: else
16: return RandomSelect(S + , k − 1 − |S − |);
17: end if
40/ 53
Randomized divide-and-conquer cont’d

e.g.: ϵ = 14 :

Key observation: if we choose a splitter ai ∈ S uniformly at random, it is easy to


get a good splitter since a fairly large fraction of the elements is ”centered.”

41/ 53
Randomized divide-and-conquorer cont’d
Theorem. The expected running time of Select(n,k) is O(n).
Proof.
▶ Let ϵ = 14 . We’ll say that the algorithm is in phase j when the size of set under
consideration is in [n( 34 )j−1 , n( 34 )j ].
▶ Let X be the number of steps. And Xj be the number of steps in phase j. Thus,
X = X0 + X1 + ....
▶ Consider the j-th phase. The probability of finding a centered splitter is ≥ 1
2 since
at least half of the elements are centered. Thus, the expected number of
iterations to find a centered splitter is 2.
▶ Each iteration costs cn( 34 )j steps since there are at most n( 34 )j elements in phase
j. Thus, E (Xj ) ≤ 2cn( 43 )j .
▶ E (X ) = E (X0 + X1 + ....) ≤ 2cn( 34 )j ≤ 8cn.
P
j
42/ 53
A “random sampling” algorithm [Floyd & Rivest, 1975]
Basic idea: randomly sample a subset to represent the whole set.

Algorithm Random sampling


1: randomly sample r elements (with replacement) from S = {s1 , s2 , ..., sn }. De-
note the r elements as R.
2: take the (1 − δ) 2r -th smallest element of R (denoted as a), and the (1 + δ) 2r -th
smallest element of R (denoted as b);
3: divide S into three disjoint subsets:

L = {si : si < a};


M = {si : a ≤ si ≤ b};
H = {si : si > b};

4: check |L| ≤ n2 , |H| ≤ n2 , and |M| ≤ cδn. If not, go to Step 1.


5: return the ( n2 − |L|)-th smallest of M;
43/ 53
Example

Two requirements of M:
▶ On one side, M should be LARGE enough such that the median is covered
by M with a high probability;
▶ On the other side, M should be SMALL enough such that Step 4 will not
take a long time; 44/ 53
Time-complexity analysis

Running time:
▶ Step 2: O(r log r ) = o(n); (sorting R)
▶ Step 3: 2n steps. (O(n) + O(|M| + |H|))
▶ Step 4: O(δn log(δn)).
3 1
Setting r = n 4 , and δ = n− 4 . The time bound of Step 4 changes to:
▶ Step 4: O(δn log(δn)) = o(n).
Total steps: 2n + o(n).
▶ The best-known deterministic algorithm 3n. But too complicated.
▶ A lower bound: 2n.

45/ 53
Error probability analysis I
Theorem 1
With probability 1 − O(n− 4 ), the RandomSamplingSelect algorithm reports the
median in the first pass. Thus, the running time is only 2n + o(n).

Three cases of failure in Step 4:


Case 1:
Define index variable xi = 1 when the i-th sample is less than the median, and
xi = 0 otherwise. Let X = x1 + ... + xr be the number of samples less than the
median. We have: E (xi ) = 12 and σ 2 (xi ) = 14 .
46/ 53
Error probability analysis II

E (X ) = 12 r and σ 2 (X ) = 41 r .

Pr(|L| ≥ n2 ) = Pr(X ≤ 1−δ2


r) (1)
= Pr(|X − E (X )| ≥ 2δ r ) (2)
σ 2 (X )
≤ (3)
( 2δ r )2
1
= n− 4 (4)

Case 2 and Case 3 are similar and thus omitted.

47/ 53
6. Appendix: Discrete Random variables

48/ 53
Random Variables
▶ When looking at independent replications of a binary experiment, we would
not usually be interested in whether each case is a success or a failure but
rather in the total number of successes (or failures).
▶ Obviously, this number is random since it depends on the individual random
outcomes,
▶ , and it is consequently called a random variable.
▶ In this case it is a discrete-valued random variable that can take values
0, 1, ..., n, where n is the number of replications.
▶ A random variable X has a probability distribution that can be described
using point probabilities fX (x ) = p(X = x ),
▶ or the cumulative distribution function F (x ) = p(X ≤ x ).
▶ Expected value (giá tr kỳ vng): µ = E (X ) = x · p(X = x ).
P

▶ Variance (phng sai ): σ 2 = V (X ) = (x − E (X ))2 · p(X = x ).


P
q
▶ Standard deviation ( lch chun): σ = SD(X ) = V (X ).
49/ 53
Expected Value: An Example
An insurance company charges $50 a year. Can a company make a profit?
Assuming that it made research on 1000 people and have following table:

Outcome Payroll x Probability p(X = x )


Death 10,000 1
1000

Disability 5000 2
1000

Neither 0 997
1000

X : amount of payment, is a discrete random variable (bin ngu nhiên ri rc). The
company expects that they have to pay each customer:
1 2 997
E (X ) = $10, 000( ) + $5000( ) + $0( ) = $20.
1000 1000 1000
50/ 53
Variance: An Example

▶ Of course, the expected value $20 will not always happen in reality.
▶ There will be variability. Let’s calculate!
▶ So V (X ) = 99802 ( 1000
1
) + 49802 ( 1000
2
) + (−20)2 ( 1000
997
) = 149, 600.

▶ and SD(X ) = 149, 600 ≈ $386.78

Comment
The company expects to pay out $20 and make $30. However, the standard
deviation of $386.78 indicates that it’s no sure thing. That’s a pretty big spread
(and risk) for an average profit of $30.

51/ 53
7. References and Further Reading

52/ 53
Cormen, T.H., Leiserson, C.E., Rivest, R.L., and Stein, C. Introduction to
Algorithms, 4th ed. The MIT Press, 2022.
Dasgupta, S., Papadimitriou, C.H., and Vazirani, U.V. Algorithms. McGraw
Hill, 2006.
Motwani, R and Prabhakar Raghavan, R. Randomized Algorithms,
Cambridge University Press, 1995.
Ross, S.M. Probability Models for Computer Science. Academic Press 2008.

53/ 53

You might also like