Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Recitation 10 - Reductions and P vs. NP
Orit MoskovichGal Rotem
Tel Aviv University
December 23, 2015
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 1 / 31
Overview
1 More Reductions. . .
2 P and NP
3 NP and verifiability
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 2 / 31
Example
Example 1
B =
{(n,m)
∣∣∣∣ Every n-state machine M either:(1) halts on ε in less than m steps
or (2) doesn’t halt on ε
}Prove that B /∈ R.
Proof.(∗) Note: Given n′, there exists some m′ such that (n′,m′) ∈ B (why?)
We show a reduction HTM,ε ≤ B.
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 3 / 31
Example
Proof (Cont.)Assume by contradiction that B ∈ R and let MB be a TM that decides it.
Pseudocode M deciding HTM,ε
On input 〈M〉1 m = 1, n = |QM |2 While(True):3 Run MB on (n,m): If MB accepts, break4 else, m = m + 15 Run M on ε for m steps6 If M halts, accept; Otherwise, reject
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 4 / 31
Example
CorrectnessBy (∗), the loops ends, and finds m such that (n,m) ∈ BSince M is an n-states TM, and (n,m) ∈ B, either:(1) M halts on ε in less than m stepsor (2) M doesn’t halt on ε
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 5 / 31
Computational Histories
Definition 2Let M be a TM and w an input string.An accepting (rejecting) computation history for M on w is a sequenceof configurations:
# −→︸ ︷︷ ︸C1
# ←−︸ ︷︷ ︸CR
2
# . . .# −→︸ ︷︷ ︸Cl
Where:1 C1 is the start configuration for M on w2 Each Ci+1 legally follows from Ci according to the rules of M3 Cl is an accepting (rejecting) configuation for M
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 6 / 31
Example - Computational Histories
Example 3Let WW = {ww | w ∈ Σ∗}.Let PWW = {〈P〉 | P is a PDA that accepts some string w ∈WW}.
Use computational histories to prove that PWW /∈ R.
Proof.We show a reduction ATM ≤m PWW .
How?Given 〈M,w〉 we build a PDA P such that:P accepts some string of the form h$h$⇐⇒ M accepts w .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 7 / 31
Example - Computational Histories
Mapping Reduction f from ATM to PWW
On input 〈M,w〉1 Construct the following PDA P:
P = “On input #C1#CR2 # . . .#Cl $ #C1#CR
2 # . . .#Cl $:1. Push C1 to stack while confirming that it is the initial
configuration for M(w)2. For each configuration C2i , until first $ sign:3. Pop C2i−1 from stack and verify that C2i legally
follows from C2i−14. Skip C1, Push C2 to stack5. For each configuration C2i+1, until second $ sign:6. Pop C2i from stack and verify that C2i+1 legally
follows from C2i7. Verify that Cl is an accepting configuration for M(w)8. If all tests passed, accept”
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 8 / 31
Example - Computational Histories
CorrectnessIf 〈M,w〉 ∈ ATM , then there exists an accepting computationhistory h of M on w .Therefore, P accepts h$h$, and thus, 〈P〉 ∈ PWW .
If 〈P〉 ∈ PWW , i.e., P accepts h$h$ for some string h.Then, h must be an accepting computation history of M on w(why?).Therefore, 〈M,w〉 ∈ ATM .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 9 / 31
Collatz Conjecture
Example 4Let
f (n) =
{3n + 1 if n ≡ 1 (mod 2)n/2 if n ≡ 0 (mod 2)
If you start with an integer n and iterate f , you obtain a sequencen, f (n), f (f (n)), .... Stop if you ever hit 1.For example, if n = 17, you get the sequence17,52,26,13,40,20,10,5,16,8,4,2,1.
Extensive computer tests have shown that every starting pointbetween 1 and a large integer gives a sequence that ends in 1.
Collatz Conjecture: all positive starting points end up at 1.
Suppose that ATM was decidable by a TM H. Use H to describe a TMthat prints the answer to the Collatz conjecture.In other words, show CC ≤ ATM .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 10 / 31
Collatz Conjecture
Pseudocode M deciding CC1 Construct the TM M1 (calculates the series):
M1 = “On input n:1. c = n2. While(True):3. If c == 1, accept4. c = f (c)”
2 Construct the TM M2 (finds n that contradicts the conjecture):M2 = “On input x :
1. For n = 2,3, . . .:2. If H(M1,n) rejects, accept”
3 Run H on M2, ε
4 If H accepts, the conjecture is wrong;If H rejects, the conjecture is correct
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 11 / 31
P vs. NP
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 12 / 31
P vs. NP
Definition 5P is the set of languages decidable in polynomial time ondeterministic TMs:
P =⋃c>0
DTIME(nc)
Definition 6NP is the set of languages decidable in polynomial time onnon-deterministic TMs:
NP =⋃c>0
NDTIME(nc)
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 13 / 31
Verifiability and NP
Definition 7Algorithm V is a verifier for a language L, if
x ∈ L⇒ ∃c ∈ {0,1}∗. V (x , c) = 1x /∈ L⇒6∃ c ∈ {0,1}∗. V (x , c) = 1
Theorem 8A language L ∈ NP ⇐⇒ it has a polynomial time verifier
(! ) We measure the time of the verifier only in terms of x , not c.
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 14 / 31
Boolean Formulas
Definition 9A Boolean formula is an expression built from:
Boolean variables, having one of two values:True 1False 0
Boolean operations:and ∧or ∨not ¬
Examples:1 ∧ 0 = 01 ∧ 0 = 11 ∨ 0 = 1φ = (x ∧ y) ∨ (y ∧ z)
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 15 / 31
Satisfiability
Definition 10A Boolean assignment, V , for a formula φ, is a function from the set ofvariables of φ to {0,1}.
Example:V (x) = 1,V (y) = 0,V (z) = 0
Definition 11A formula is satisfiable, if some Boolean assignment to its variables,makes the formula evaluate to 1.
Example: φ = (x ∧ y) ∨ (y ∧ z)
⇒ V (φ) = (V (x) ∧ V (y)) ∨ (V (y) ∧ V (z))= (1 ∧ 0) ∨ (0 ∧ 0) == (1 ∧ 0)︸ ︷︷ ︸
0
∨ (1 ∧ 1)︸ ︷︷ ︸1
= 1
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 16 / 31
Satisfiability
Example: φ = (x ∨ y) ∧ (x ∨ y) ∧ (x ∨ y) ∧ (x ∨ y)Is φ satisfiable?
Let’s try V (x) = 1,V (y) = 1.⇒ V (φ) = (1 ∨ 1) ∧ (1 ∨ 1) ∧ (1 ∨ 1) ∧ (1 ∨ 1) =
= (1 ∨ 1) ∧ (1 ∨ 1) ∧ (1 ∨ 1) ∧ (0 ∨ 0)︸ ︷︷ ︸0
= 0
For any assignment V (x) = vx ,V (y) = vy ⇒ V (φ) = 0.
QuestionI How many possible assignments exist for a Boolean formula φ
with n variables?
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 17 / 31
SAT
Definition 12
SAT = {〈φ〉 | φ is a satisfiable Boolean formula}
Theorem 13SAT ∈ NP
Proof.A polynomial time verifier, where the witness is the assignment:
Verifier VSAT for SATOn input 〈〈φ〉,V 〉
1 Replace each variable in φ according to V2 Evaluate V (φ)
3 If V (φ) = 1, accept; Otherwise, reject
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 18 / 31
SAT
CorrectnessVerifiability:
If φ is satisfiable, then there exists a witness V = (1,0,0, . . .) thatsatisfies φIf φ is not satisfiable, then no assignment V can satisfy φ
Polynomial time:Denote by m the number of clauses in φDenote by n the number of variables in φVSAT runs in O(n ·m) time
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 19 / 31
CNF
Definition 14A literal is a variable or negated variable: x or xA clause is several literals joined by ∨s: (x1 ∨ x2 ∨ x3)
Definition 15A Boolean formula is in conjunctive normal form (CNF) if it consists ofclauses, connected with ∧s.
Example:(x1 ∨ x2) ∧ (x2 ∨ x3 ∨ x4 ∨ x7)
Definition 16A Boolean formula is in k -CNF form, if it is a CNF formula, and allclauses have k literals.
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 20 / 31
3SAT
Definition 17
3SAT = {〈φ〉 | φ is a satisfiable 3CNF formula}
Theorem 183SAT ∈ NP
Proof.A polynomial time verifier, where the witness is the assignment:
Verifier V3SAT for 3SATOn input 〈〈φ〉,V 〉
1 Replace each variable in φ according to V2 Evaluate V (φ)
3 If V (φ) = 1, accept; Otherwise, reject
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 21 / 31
3SAT
QuestionsI 3SAT ∈ P?I What about 3SAT = {〈φ〉 | φ is not satisfiable}
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 22 / 31
Clique
Definition 19A clique in an undirected graph G = (V ,E) is a subgraph, where everytwo nodes are connected by an edge.
Formally, A ⊆ V is a clique if ∀v1 6= v2 ∈ A. (v1, v2) ∈ E .
Definition 20A k -clique is a clique of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique
Definition 19A clique in an undirected graph G = (V ,E) is a subgraph, where everytwo nodes are connected by an edge.
Formally, A ⊆ V is a clique if ∀v1 6= v2 ∈ A. (v1, v2) ∈ E .
Definition 20A k -clique is a clique of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique
Definition 19A clique in an undirected graph G = (V ,E) is a subgraph, where everytwo nodes are connected by an edge.
Formally, A ⊆ V is a clique if ∀v1 6= v2 ∈ A. (v1, v2) ∈ E .
Definition 20A k -clique is a clique of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique
Definition 19A clique in an undirected graph G = (V ,E) is a subgraph, where everytwo nodes are connected by an edge.
Formally, A ⊆ V is a clique if ∀v1 6= v2 ∈ A. (v1, v2) ∈ E .
Definition 20A k -clique is a clique of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique
Definition 21
CLIQUE = {〈G, k〉 | G is an undirected graph with a k -clique}
Theorem 22CLIQUE ∈ NP
Proof.A polynomial time verifier, where the witness is the clique:
Verifier VCLIQUE for CLIQUEOn input 〈〈G, k〉, c〉
1 Verify that c is a set of k nodes in G2 Verify that G contains all edges between nodes in c3 If both tests pass, accept; Otherwise, reject
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 24 / 31
Independent Set
Definition 23An independent set (IS) in a graph is a set of nodes, no two of whichare linked by an edge.
Formally, A ⊆ V is an IS if ∀v1 6= v2 ∈ A. (v1, v2) /∈ E .
Definition 24A k -IS is an independent set of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set
Definition 23An independent set (IS) in a graph is a set of nodes, no two of whichare linked by an edge.
Formally, A ⊆ V is an IS if ∀v1 6= v2 ∈ A. (v1, v2) /∈ E .
Definition 24A k -IS is an independent set of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set
Definition 23An independent set (IS) in a graph is a set of nodes, no two of whichare linked by an edge.
Formally, A ⊆ V is an IS if ∀v1 6= v2 ∈ A. (v1, v2) /∈ E .
Definition 24A k -IS is an independent set of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set
Definition 23An independent set (IS) in a graph is a set of nodes, no two of whichare linked by an edge.
Formally, A ⊆ V is an IS if ∀v1 6= v2 ∈ A. (v1, v2) /∈ E .
Definition 24A k -IS is an independent set of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set
Definition 25
IS = {〈G, k〉 | G is an undirected graph with a k -IS}
Theorem 26IS ∈ NP
Proof.A polynomial time verifier, where the witness is the independentset. . .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 26 / 31
Vertex Cover
Definition 27A vertex cover (VC) in a graph is a set of nodes, where every edge ofG touches one of those nodes.
Formally, A ⊆ V is a VC if ∀(v1, v2) ∈ E . v1 ∈ A or v2 ∈ A.
Definition 28A k -VC is a vertex cover of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover
Definition 27A vertex cover (VC) in a graph is a set of nodes, where every edge ofG touches one of those nodes.
Formally, A ⊆ V is a VC if ∀(v1, v2) ∈ E . v1 ∈ A or v2 ∈ A.
Definition 28A k -VC is a vertex cover of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover
Definition 27A vertex cover (VC) in a graph is a set of nodes, where every edge ofG touches one of those nodes.
Formally, A ⊆ V is a VC if ∀(v1, v2) ∈ E . v1 ∈ A or v2 ∈ A.
Definition 28A k -VC is a vertex cover of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover
Definition 27A vertex cover (VC) in a graph is a set of nodes, where every edge ofG touches one of those nodes.
Formally, A ⊆ V is a VC if ∀(v1, v2) ∈ E . v1 ∈ A or v2 ∈ A.
Definition 28A k -VC is a vertex cover of size k .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover
Definition 29
VC = {〈G, k〉 | G is an undirected graph with a k -VC}
Theorem 30VC ∈ NP
Proof.A polynomial time verifier, where the witness is the set of verticescovering G . . .
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 28 / 31
VC vs. IS
Theorem 31Let G = (V ,E) be an undirected graph. Let A ⊆ V.Then, A is a VC⇐⇒ V \ A is an IS.
Proof.Let A be a VC.Assume by contradiction that V \ A is not an IS.Therefore, ∃v1, v2 ∈ V \ A. (v1, v2) ∈ E .But v1, v2 /∈ A, and therefore (v1, v2) is not covered.Contradiction for A being a VC.Let V \ A be an IS.Assume by contradiction that A is not a VC.Therefore, ∃v1, v2 /∈ A. (v1, v2) ∈ E .But v1, v2 ∈ V \ A, and (v1, v2) ∈ E .Contradiction for V \ A being an IS.
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 29 / 31
Clique vs. IS
Theorem 32Let G = (V ,E) be an undirected graph.Define H = (V ,E ′) to be the complement of G iffE ′ = {(u, v) | u, v ∈ V and (u, v) /∈ E}.
Let A ⊆ V.Then, A is a Clique in G⇐⇒ A is an IS in H.
Proof.A is a Clique in G⇐⇒∀v1 6= v2 ∈ A. (v1, v2) ∈ E ⇐⇒∀v1 6= v2 ∈ A. (v1, v2) /∈ E ′ ⇐⇒A is an IS in H
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 30 / 31
The End
Courtesy ofhttps://www.facebook.com/GraphsofStuff/
Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 31 / 31