Download presentation
Presentation is loading. Please wait.
1
More on NP-completeness
The Chinese University of Hong Kong Fall 2011 CSCI 3130: Formal languages and automata theory More on NP-completeness Andrej Bogdanov
2
NP problems clique independent set vertex cover
1 2 1 2 1 2 3 4 3 4 3 4 clique independent set vertex cover CLIQUE = {〈G, k〉: G is a graph with a clique of k vertices} IS = {〈G, k〉: G is a graph with an independent set of k vertices} VC = {〈G, k〉: G is a graph with a vertex cover of k vertices}
3
SAT and 3SAT SAT = {〈f〉: f is a satisfiable Boolean formula}
((x1∨x2 ) ∧ (x1∨x2)) ∨ ((x1∨(x2 ∧ x3)) ∧ x3) 3SAT = {〈f〉: f is a satisfiable 3CNF formula} (x1∨x2∨x2 ) ∧ (x2∨x3∨x4) ∧ (x2∨x3∨x5) ∧ (x1∨x5∨x5)
4
P, NP, and reductions reduction from CLIQUE to IS (G, k) (G’, k’)
SAT IS CLIQUE VC 3SAT reduces to (G, k) (G’, k’) G has a k-clique G’ has a k’-ind set NP P (easy to verify solution) (easy to solve)
5
The plan for today Why? Because everything in NP reduces to SAT
IS reduces to VC CLIQUE Because everything in NP reduces to SAT 3SAT SAT NP-complete (the Cook-Levin theorem) NP P … so all these are NP-complete (easy to verify solution) (easy to solve)
6
Reducing IS to VC Proof: We describe a reduction from IS to VC Example
(G, k) (G’, k’) G has an IS of size k G’ has a VC of size k’ vertex covers independent sets 1 2 3 4 {2, 4}, {3, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4} ∅, {1}, {2}, {3}, {4}, {1, 2}, {1, 3}
7
Reducing IS to VC Claim S is an independent set of G if and Proof
1 2 3 4 S is an independent set of G if and only if S is a vertex cover of G ∅ {1} {2} {3} {4} {1, 2} {1, 3} {2, 4} {3, 4} {1, 2, 3} {1, 2, 4} {1, 3, 4} {2, 3, 4} {1, 2, 3, 4} IS VC S is an independent set of G no edge has both endpoints in S every edge has an endpoint in S S is a vertex cover of G
8
Reducing IS to VC ✓ R (G, k) (G’, k’) ✓ On input (G, k), R:
SAT 3SAT IS CLIQUE VC ✓ R (G, k) (G’, k’) ✓ On input (G, k), R: Output (G, n – k). G has a VC of size n – k G has an IS of size k
9
Reducing 3SAT to CLIQUE Proof: We give a reduction from 3SAT to CLIQUE
3SAT = {f: f is a satisfiable Boolean formula in 3CNF} CLIQUE = {(G, k): G is a graph with a clique of k vertices} 3CNF formula f R (G, k) G has a clique of size k f is satisfiable
10
Reducing 3SAT to CLIQUE Example: f =
(x1∨x1∨x2 ) ∧ (x1∨x2∨x2) ∧ (x1∨x2∨x3) x1 x2 x1 x2 x1 x2 x3 Put a vertex for every literal Put an edge for every consistent pair
11
Reducing 3SAT to CLIQUE 3CNF formula f R (G, k) R:
On input f, where f is a 3CNF formula with m clauses Construct the following graph G: G has 3m vertices, divided into m groups, one for each literal in f If a and b are in different groups and a ≠ b, put an edge (a, b) Output (G, m)
12
Reducing 3SAT to CLIQUE 3CNF formula f R (G, m)
G has a clique of size m f is satisfiable x1 x1 x1 x1 x2 x2 x2 x2 x3 f = (x1∨x1∨x2 ) ∧ (x1∨x2∨x2) ∧ (x1∨x2∨x3) T T F F F T F F T
13
Reducing 3SAT to CLIQUE 3CNF formula f R (G, m)
G has a clique of size m f is satisfiable x1 x1 x1 x1 x2 x2 x2 x2 x3 f = (x1∨x1∨x2 ) ∧ (x1∨x2∨x2) ∧ (x1∨x2∨x3) F F T T F F T T T
14
Reducing 3SAT to CLIQUE 3CNF formula f R (G, m) f is satisfiable G has a clique of size m SAT 3SAT IS CLIQUE VC ✓ Every satisfying assignment of f gives a clique of size m in G Conversely, every clique of size m in G gives a consistent satisfying assignment of f. ✓
15
SAT and 3SAT SAT = {〈f〉: f is a satisfiable Boolean formula}
((x1∨x2 ) ∧ (x1∨x2)) ∨ ((x1∨(x2 ∧ x3)) ∧ x3) 3SAT = {〈f〉: f is a satisfiable 3CNF formula} (x1∨x2∨x2 ) ∧ (x2∨x3∨x4) ∧ (x2∨x3∨x5) ∧ (x1∨x5∨x5)
16
Reducing SAT to 3SAT Example: f = (x2∨(x1∧x2 ))∧(x1∧(x1∨x2 )) x4 x5 x7
AND OR NOT x2 x1 T T T T T T F F T F T F T F F T F T T F F T F T F F T F F F F T (x4∨x5∨x7) (x4∨x5∨x7) (x4∨x5∨x7) ∧(x4∨x5∨x7) We add extra variables for every “wire”
17
Turning gates into 3CNFs
z z z Gj: AND OR NOT x y x y x x y z z = y ∧ x x y z z = y ∨ x x z z = x T T T T T T F F T F T F T F F T F T T F F T F T F F T F F F F T T T T T T T F F T F T T T F F F F T T T F T F F F F T F F F F T T T F T F T F T T F F F (x∨z)∧(x∨z) (x∨y∨z)∧(x∨y∨z) ∧(x∨y∨z)∧(x∨y∨z) (x∨y∨z)∧(x∨y∨z) ∧(x∨y∨z)∧(x∨y∨z) fj: (x∨x∨z)∧(x∨x∨z)
18
Reducing SAT to 3SAT Boolean formula f R 3CNF formula f’ R:=
On input f, where f is a boolean formula Construct and output the following 3CNF formula f’: f’ has extra variables xn+1, ..., xn+t one for each gate Gj in f For each gate Gj, construct the formula fj Output f’ = fn+1 ∧ fn+2 ∧ ... ∧ ft ∧ (xn+t ∨xn+t ∨xn+t ) requires that output of f is true
19
Reducing SAT to 3SAT Boolean formula f R 3CNF formula f’ ✔ f’ is satisfiable f is satisfiable Every satisfying assignment of f extends uniquely to a satisfying assignment of f’ In the other direction, in every satisfying assignment of f’ the part x1, ..., xn is satisfies f
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.