SLIDE 1 Shanghai Jiao Tong University
Chihao Zhang
Advanced Algorithms (I)
March 2nd, 2020
SLIDE 2
Information
Every Monday, 10:00 am - 11:40 am Zoom @ 123363659 Instructor: 张驰豪 (chihao@sjtu.edu.cn) TA: 杨凤麟 (yangfl@sjtu.edu.cn) Office Hour: via Canvas or WeChat Group
SLIDE 3 References
Probability and Computing Randomized Algorithms The Probabilistic Method
- M. Mitzenmacher & E. Upfal
- R. Motwani & P
. Raghavan
SLIDE 4
Polynomial Identity Testing
SLIDE 5 Polynomial Identity Testing
Given two polynomials and
F(x) =
d
∏
i=1
(x − ai) G(x) =
d
∑
i=0
bixi
SLIDE 6 Polynomial Identity Testing
Given two polynomials and
F(x) =
d
∏
i=1
(x − ai) G(x) =
d
∑
i=0
bixi
Is F(x) ≡ G(x)?
SLIDE 7 Polynomial Identity Testing
Given two polynomials and
F(x) =
d
∏
i=1
(x − ai) G(x) =
d
∑
i=0
bixi
Is F(x) ≡ G(x)?
- Example. F(x) = (x − 1)(x − 2)(x + 3); G(x) = x3 − 7x + 6
SLIDE 8
SLIDE 9
One can expand and compare the coefficients…
F(x)
SLIDE 10
One can expand and compare the coefficients…
F(x)
It takes arithmetic operations.
O(d2)
SLIDE 11
One can expand and compare the coefficients…
F(x)
It takes arithmetic operations.
O(d2)
Can be improved to using FFT.
O(d log d)
SLIDE 12
One can expand and compare the coefficients…
F(x)
It takes arithmetic operations.
O(d2)
Can be improved to using FFT.
O(d log d)
If random coins are allowed…
SLIDE 13 One can expand and compare the coefficients…
F(x)
It takes arithmetic operations.
O(d2)
Can be improved to using FFT.
O(d log d)
If random coins are allowed…
- The problem can be solved much faster
SLIDE 14 One can expand and compare the coefficients…
F(x)
It takes arithmetic operations.
O(d2)
Can be improved to using FFT.
O(d log d)
If random coins are allowed…
- The problem can be solved much faster
- at the cost of making error.
SLIDE 15
SLIDE 16
Choosing a uniform number s ∈ {1,2,…,100d}
SLIDE 17
Choosing a uniform number s ∈ {1,2,…,100d} Test whether F(s) = G(s)
SLIDE 18 Choosing a uniform number s ∈ {1,2,…,100d} Test whether F(s) = G(s)
, then it always holds that
F(x) ≡ G(x) F(s) = G(s)
SLIDE 19 Choosing a uniform number s ∈ {1,2,…,100d} Test whether F(s) = G(s)
, then it always holds that
F(x) ≡ G(x) F(s) = G(s)
, how likely is that ?
F(x) ≢ G(x) F(s) ≠ G(s)
SLIDE 20 Choosing a uniform number s ∈ {1,2,…,100d} Test whether F(s) = G(s)
, then it always holds that
F(x) ≡ G(x) F(s) = G(s)
, how likely is that ?
F(x) ≢ G(x) F(s) ≠ G(s)
- Theorem. (Fundamental Theorem of Algebra)
A polynomial of degree has at most roots in
d d ℂ
SLIDE 21
SLIDE 22
Our algorithm outputs wrong answer only when
SLIDE 23 Our algorithm outputs wrong answer only when
F(x) ≢ G(x)
SLIDE 24 Our algorithm outputs wrong answer only when
F(x) ≢ G(x)
s F(x) − G(x)
SLIDE 25 Our algorithm outputs wrong answer only when
F(x) ≢ G(x)
s F(x) − G(x)
This happens with probability at most .
1 100
SLIDE 26 Our algorithm outputs wrong answer only when
F(x) ≢ G(x)
s F(x) − G(x)
This happens with probability at most .
1 100
It only costs
and .
O(d) F(s) G(s)
SLIDE 27 Our algorithm outputs wrong answer only when
F(x) ≢ G(x)
s F(x) − G(x)
This happens with probability at most .
1 100
It only costs
and .
O(d) F(s) G(s)
One can repeat the algorithm times:
t
;
100−t
.
O(td)
SLIDE 28
Multi-variable Polynomials
SLIDE 29
Multi-variable Polynomials
The idea applies to a more general setting.
SLIDE 30
Multi-variable Polynomials
The idea applies to a more general setting. Let for some field ,
F, G ∈ 𝔾(x1, …, xn) 𝔾
SLIDE 31
Multi-variable Polynomials
The idea applies to a more general setting. Let for some field ,
F, G ∈ 𝔾(x1, …, xn) 𝔾
Is F(x1, …, xn) ≡ G(x1, …, xn)?
SLIDE 32
- Theorem. (Schwartz-Zippel Theorem)
Let be a non-zero multivariate polynomial of degree at most . For any set , it holds that
Q ∈ 𝔾[x1, …, xn] d U ⊆ 𝔾 Pr
r1,…,rn∈RU[Q(r1, …, rn) = 0] ≤
d |U|
SLIDE 33
Proof of Schwartz-Zippel
SLIDE 34 Proof of Schwartz-Zippel
Induction on , case is Fundamental Theorem
n n = 1
SLIDE 35 Proof of Schwartz-Zippel
Induction on , case is Fundamental Theorem
n n = 1
Assuming it holds for smaller …
n
SLIDE 36 Proof of Schwartz-Zippel
Induction on , case is Fundamental Theorem
n n = 1
Assuming it holds for smaller …
n
Q(x1, …, xn) =
k
∑
i=0
xi
1 ⋅ Qi(x2, …, xn)
SLIDE 37 Proof of Schwartz-Zippel
Induction on , case is Fundamental Theorem
n n = 1
Assuming it holds for smaller …
n
Q(x1, …, xn) =
k
∑
i=0
xi
1 ⋅ Qi(x2, …, xn)
Pr [Q = 0] ≤ Pr [Qk = 0] + Pr [Q = 0|Qk ≠ 0] ≤ d − k |U| + k |U|
SLIDE 38
SLIDE 39
Our randomized algorithm generalizes to the multi- variable setting by Schwartz-Zippel theorem.
SLIDE 40
Our randomized algorithm generalizes to the multi- variable setting by Schwartz-Zippel theorem. If the polynomials are given in product form, one scan of and is sufficient to evaluate them.
F G
SLIDE 41
Our randomized algorithm generalizes to the multi- variable setting by Schwartz-Zippel theorem. If the polynomials are given in product form, one scan of and is sufficient to evaluate them.
F G
Linear time algorithm with at most error!
1 %
SLIDE 42
Our randomized algorithm generalizes to the multi- variable setting by Schwartz-Zippel theorem. If the polynomials are given in product form, one scan of and is sufficient to evaluate them.
F G
Linear time algorithm with at most error!
1 %
It is a wide open problem in the complexity theory that whether this can be done in deterministic polynomial time.
SLIDE 43
Some Complexity Theory
SLIDE 44 Some Complexity Theory
Problems solvable in deterministic polynomial-time:
P
SLIDE 45 Some Complexity Theory
Problems solvable in deterministic polynomial-time:
P
Problems solvable in randomized polynomial-time: BPP
SLIDE 46 Some Complexity Theory
Problems solvable in deterministic polynomial-time:
P
Problems solvable in randomized polynomial-time: BPP
Is ?
BPP = P
SLIDE 47
Min-Cut in a Graph
SLIDE 48
Min-Cut in a Graph
A cut in a graph is a set of edges whose removal disconnects .
G = (V, E) C ⊆ E G
SLIDE 49
Min-Cut in a Graph
A cut in a graph is a set of edges whose removal disconnects .
G = (V, E) C ⊆ E G
How to find the minimum cut?
SLIDE 50
Min-Cut in a Graph
A cut in a graph is a set of edges whose removal disconnects .
G = (V, E) C ⊆ E G
How to find the minimum cut? It can be solved using max-flow techniques
SLIDE 51
Min-Cut in a Graph
A cut in a graph is a set of edges whose removal disconnects .
G = (V, E) C ⊆ E G
How to find the minimum cut? It can be solved using max-flow techniques With the fastest max-flow algorithm, it takes time.
O(n × mn)
SLIDE 52
Karger’s Min-Cut Algorithm
SLIDE 53 Karger’s Min-Cut Algorithm
David Karger
SLIDE 54 Karger’s Min-Cut Algorithm
David Karger
Using random bits, Karger found a much simpler algorithm
SLIDE 55 Karger’s Min-Cut Algorithm
David Karger
Using random bits, Karger found a much simpler algorithm The only operation required is edge contraction
SLIDE 56
Edge Contraction
SLIDE 57 Edge Contraction
1 2 3
SLIDE 58 Edge Contraction
1 2 3 1 2 3
SLIDE 59 Edge Contraction
1 2 3 1 2 3
SLIDE 60 Edge Contraction
1 2 3 1 2 3 1/2 3
SLIDE 61 Edge Contraction
1 2 3 1 2 3 1/2 3
SLIDE 62 Edge Contraction
1 2 3 1 2 3 1/2 3
SLIDE 63 Edge Contraction
1 2 3 1 2 3 1/2 3
- parallel edges may exist
- no self-loop
SLIDE 64
The Algorithm
SLIDE 65 The Algorithm
Karger’s Min-cut Algorithm
- 1. Randomly choose an edge and contract it
until only two vertices remains.
- 2. Output remaining edges.
SLIDE 66
Analysis
SLIDE 67
Analysis
The algorithm contracts pair of vertices in total.
n − 2
SLIDE 68
Analysis
The algorithm contracts pair of vertices in total.
n − 2
Fix an minimum cut , we bound the probability that it survives.
C
SLIDE 69
Analysis
The algorithm contracts pair of vertices in total.
n − 2
Fix an minimum cut , we bound the probability that it survives.
C
Assume the removal of separates and .
C S ⊆ V ¯ S = V∖S
SLIDE 70
Analysis
The algorithm contracts pair of vertices in total.
n − 2
Fix an minimum cut , we bound the probability that it survives.
C
Assume the removal of separates and .
C S ⊆ V ¯ S = V∖S
All contractions happen within or .
S ¯ S
SLIDE 71
SLIDE 72
For , let be the event that “ -th contraction avoids ”
i = 1,…, n − 2 Ai i C
SLIDE 73
For , let be the event that “ -th contraction avoids ”
i = 1,…, n − 2 Ai i C
We need to bound
SLIDE 74 For , let be the event that “ -th contraction avoids ”
i = 1,…, n − 2 Ai i C
We need to bound Pr [
n−2
⋂
i=1
Ai] =
n−2
∏
i=1
Pr Ai
i−1
⋂
j=1
Aj
SLIDE 75 For , let be the event that “ -th contraction avoids ”
i = 1,…, n − 2 Ai i C
We need to bound Pr [
n−2
⋂
i=1
Ai] =
n−2
∏
i=1
Pr Ai
i−1
⋂
j=1
Aj We assume |C| = k
SLIDE 76
SLIDE 77
In -th contraction,
i
SLIDE 78 In -th contraction,
i
vertices;
- each vertex is of degree at least .
n − i + 1 k
SLIDE 79 In -th contraction,
i
vertices;
- each vertex is of degree at least .
n − i + 1 k
Therefore, conditional on that still survives,
C
SLIDE 80 In -th contraction,
i
vertices;
- each vertex is of degree at least .
n − i + 1 k
Therefore, conditional on that still survives,
C
Pr Ai
i−1
⋂
j=1
Aj ≥ 1 − 2k k(n − i + 1) = n − i − 1 n − i + 1
SLIDE 81
SLIDE 82
Therefore
SLIDE 83 Therefore Pr [
n−2
⋂
i=1
Ai] =
n−2
∏
i=1
Pr Ai
i−1
⋂
j=1
Aj ≥
n−2
∏
i=1
n − i − 1 n − i + 1 = n − 2 n ⋅ n − 3 n − 1 ⋯ 1 3 = 2 n(n − 1)
SLIDE 84
SLIDE 85
So if we repeat the algorithm times, the minimum cut survives with probability at least
50n2
SLIDE 86 So if we repeat the algorithm times, the minimum cut survives with probability at least
50n2
1 − (1 − 2 n(n − 1))
50n2
≥ 1 − e−100
SLIDE 87 So if we repeat the algorithm times, the minimum cut survives with probability at least
50n2
1 − (1 − 2 n(n − 1))
50n2
≥ 1 − e−100 How about the time cost?
SLIDE 88 So if we repeat the algorithm times, the minimum cut survives with probability at least
50n2
1 − (1 − 2 n(n − 1))
50n2
≥ 1 − e−100 How about the time cost? If we store the graph in a adjacency matrix, one needs to contract an edge…
O(n)
SLIDE 89
Karger-Stein’s Trick
SLIDE 90 Karger-Stein’s Trick
Recall Pr [
n−2
⋂
i=1
Ai] = n − 2 n ⋅ n − 3 n − 1 ⋯ 1 3
SLIDE 91 Karger-Stein’s Trick
Recall Pr [
n−2
⋂
i=1
Ai] = n − 2 n ⋅ n − 3 n − 1 ⋯ 1 3 The more we contracts, the easier gets hit
C
SLIDE 92 Karger-Stein’s Trick
Recall Pr [
n−2
⋂
i=1
Ai] = n − 2 n ⋅ n − 3 n − 1 ⋯ 1 3 The more we contracts, the easier gets hit
C
Idea: Make a copy before it becomes too bad!
SLIDE 93 Karger-Stein’s Trick
Recall Pr [
n−2
⋂
i=1
Ai] = n − 2 n ⋅ n − 3 n − 1 ⋯ 1 3 The more we contracts, the easier gets hit
C
Idea: Make a copy before it becomes too bad! The success probability can be improved to Ω (
1 log n )