1 What Is A Randomized Algorithm?: Lecture Notes CS:5360 Randomized Algorithms
1 What Is A Randomized Algorithm?: Lecture Notes CS:5360 Randomized Algorithms
• Monte Carlo algorithms: these algorithms make errors, but with some probability that can be
1 1
controlled. For example, we can say that a certain algorithm has a 10 or maybe a 100 proba-
bility of making an error. The runtime of Monte Carlo algorithms can either be deterministic
or a random variable.
In order to solve this problem, we can try to find an approximate median of L by using a randomized
step.
FUNCTION: randomizedPartition(L=[1..n])
p <- index chosen uniformly at random from {1,2,...,n}
for i<- 1 to n do:
if L[i] <= L[p]:
L_1 <- L_1 append L[i]
else:
L_2 <- L_2 append L[i]
return (L_1, L_2)
Notice that this does not always return a partition that satisfies both requirements above. In fact,
it has a 23 chance of error.
Lemma 1 The function randomizedPartition runs in O(n) time with an error probability of 2/3.
1
Using randomizedPartition as a subroutine we can design a Las Vegas algorithm for the
BalancedPartition problem and we can also design a Monte Carlo algorithm with a much
smaller error probability. First, we state the Las Vegas algorithm.
FUNCTION: randomizedPartitionLV(L[1..n])
repeat:
(L_1,L_2) <- randomizedPartition(L)
until: |L|/3 <= |L_1| <= 2|L|/3
return (L_1, L_2)
This algorithm will not make any errors, but its runtime is a random variable. This is because
with probability 1/3, the algorithm performs one iteration of the repeat-until loop, with probability
(2/3)(1/3) the algorithm performs two iterations of the repeat-until loop, etc.
FUNCTION: randomizedPartitionMC(L[1..n])
for i <- 1 to k do:
(L_1, L_2) <- randomizedPartition(L)
if (|L|/3 <= |L_1| <= 2|L|/3) then:
return (L_1, L_2)
endfor
return "Failed"
Notice that we are independently repeating the randomizedPartition algorithm k times. This
process of increasing the probability of correctness is called probability amplification.
Theorem 2 BalancedPartition can be solved by a Las Vegas algorithm in expected O(n) time.
Theorem 3 BalancedPartition can be solved by a Monte Carlo algorithm in O(kn) time with
k
2
probability 1 − 3 .
• To improve memory usage. Random sampling as a way to sparsifying input and then working
with this smaller input is a common technique.
• To make algorithms simpler. For example, see Karger’s min-cut algorithm in the next lecture.
2
4 Classification of Problems Based on Randomization
• P = the class of decision problems (problems with boolean answers) that can be solved in
polynomial time. We typically say that these can be solved efficiently.
• RP (randomized polynomial) = the class of decision problems L such that L can be solved
by a polynomial time algorithm A with the property:
Note that in this definition the algorithm A has one-sided error, only for “yes” instances.
Also, we clearly see that P ⊆ RP . Finally, the choice of the constant 1/2 in the above
definition is somewhat arbitrary. By using probability amplification (see below), we can
drive the error probability down quite efficiently.
FUNCTION: amplifiedA(x)
for i <- 1 to k do
if A(x) = 1, then
return 1
return 0
In this use of probability amplification, when we input a “yes” instance, the probability of
the output begin incorrect is 2−k . So then P r(amplifiedA(x) = 1) ≥ 1 − 2−k .
• CoRP = {L|L ∈ RP } = the class of decision problems such that L can be solved by a
polynomial time algorithm A with the property:
– If x ∈ L, then P r(A(x) = 1) = 1.
– If x 6∈ L, then P r(A(x) = 0) ≥ 1/2.
• BPP (bounded error probabalistic polynomial) = the class of decision problems L such that
L has a polynomial time algorithm A with the property:
Notice that for problems in BPP, we can make errors for both positive and negative instances
of L.
Not much is known about the relationship between P , RP , coRP , and BP P . However – maybe
somewhat surprisingly at first glance – many theoretical computer scientists believe the following
conjecture.
Conjecture 4 BPP = P.
3
Figure 1: A venn diagram detailing various complexity classes.
The point here is that randomization is not expected to help in a “gross” sense, i.e., it will not help
us solve in polynomial time a problem that cannot be solved in polynomial time by deterministic
means. However, it can improve a running time that is a high degree polynomial, e.g., O(n8 ), to a
running time that is a low degree polynomial, e.g., O(n2 ). This conjecture is a major open problem
in theoretical computer science.
There are at least one well known problem that is not known to be in P , but is in coRP . This
is the Polynomial Identity Testing problem.
4
Lecture Notes CS:5360 Randomized Algorithms
Lecture 2: Aug 23, 2018
Scribe: Geoff Converse
Randomized PIT
(1) Pick a number t uniformly at random from {1,...,100d}
(2) Evaluate P(t), Q(t)
(3) If P(t) = Q(t)
return YES
else
return NO
The runtime of this algorithm is O(d) because it takes O(d) to evaluate P (t) and Q(t). Note that
t can be generated by looking at O(log2 (100d)) = O(log d) bits. If we assume that each random
bit can be generated in O(1) time, then Step (1) takes only O(log d) time.
To analyze the error probability of this algorithm, just look at the two possible cases.
5
• If P 6≡ Q, the analysis is slightly more involved. Note that P (t) = Q(t) iff t is a root of
P (x) − Q(x) = 0. Since P (x) − Q(x) has degree at most d, by the Fundamental Theorem
d 1
of Algebra, P (x) − Q(x) has at most d roots. Then P r(P (t) = Q(t)) ≤ 100d = 100 . So for
99
P 6≡ Q, the algorithm returns NO with a probability ≥ 100 .
Definition 6 Events E1 , ..., Ek are mutually independent iff for any subset I ⊆ {1, 2, ..., k}, P r(
T
i∈I Ei ) =
Q
i∈I P r(Ei ).
We have already used the notion of mutual independence in analyzing algorithms that amplify cor-
rectness probability by independent repititions. In some situations, requiring or expecting mutual
independence is too much and a weaker notion of independence suffices.
Definition 7 Events E1 , ..., Ek exhibit p-wise independence iff for any subset I ⊆ {1, 2, ..., k} such
that |I| ≤ p, P r( i∈I Ei ) = i∈I P r(Ei ).
T Q
When p = 2, the independence we get is called pairwise independence. We will encounter this later.
P r(E1 ∩ E2 )
P r(E1 |E2 ) = if P r(E2 ) 6= 0
P r(E2 )
This implies that if P r(E2 ) 6= 0, then P r(E1 ∩ E2 ) = P r(E1 |E2 ) · P r(E2 ). More generally,
k
\ k
\
P r(E1 ∩ E2 ∩ · · · ∩ Ek ) = P r E1 | Ej · P r E2 | Ej · · · P r (Ek−1 |Ek ) · P r(Ek )
j=2 j=3
We will now use the above formula in the analysis of Karger’s min-cut algorithm. There are many
ways of solving the min-cut problem in polynomial time, but Karger’s algorithm showcases the
simplicity and elegance one gets by using randomization.
6
Figure 2: An example of partition which solves the mincut problem. Here the size of the mincut
is 2. Notice that the size of the mincut is always ≤ the minimum degree, as we can always choose
S to contain just one vertex.
Note that after each contract operation, the number of vertices decreases by 1. Therefore, the final
graph Gn−2 only has two vertices. This algorithm does not always return the optimal solution, as
demonstrated in Figure 4.
7
Figure 3: An example of the contract operation in action. Notice that contracting a simple graph
can return a multigraph.
Figure 4: Karger’s Mincut Algorithm is not always correct. The original graph has a mincut size
equal to 2, but after one iteration, the min-cut size equals 3.