CS154, Lecture 16: More NP-Complete Problems; PCPs
Is 3SAT solvable in O(n) time on a multitape TM? Are there logic circuits of size 6n for 3SAT? If yes, then not only is P=NP, but there would be a “dream machine” that could crank out short proofs of theorems, quickly optimize all aspects of life… recognizing quality work is all you need to produce
There are thousands of NP-complete problems Your favorite topic certainly has an NP-complete problem somewhere in it Even the other sciences are not safe: biology, chemistry, physics have NP-complete problems too!
Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: Take a problem that you know to be NP-hard (3-SAT) Prove that P Then for all A NP, A P and P We conclude that A P , and is NP-hard
is NP-Complete NP P
The Clique Problem Given a graph G and positive k, does G contain a complete subgraph on k nodes? CLIQUE = { (G,k) | G is an undirected graph with a k-clique } Theorem (Karp): CLIQUE is NP-complete
Proof Idea: 3SAT P CLIQUE Transform a 3-cnf formula into (G,k) such that 3SAT (G,k) CLIQUE Want transformation that can be done in time that is polynomial in the length of How can we encode a logic problem as a graph problem?
3SAT P CLIQUE We transform a 3-cnf formula into (G,k) such that 3SAT (G,k) CLIQUE Let C1, C2, …, Cm be clauses of . Assign k := m. Make a graph G with m groups of 3 nodes each. Group i corresponds to clause Ci of . Each node in group i is labeled with a literal of Ci Put edges between all pairs of nodes in different groups, except pairs of nodes with labels 𝑥 𝑖 and 𝑥 𝑖 Put no edges between nodes in the same group When done putting in all the edges, erase the labels
(x1 x1 x2) (x1 x2 x2) (x1 x2 x2) |V| = 9 k = 3
(x1 x1 x1) (x1 x1 x2) (x2 x2 x2) (x2 x2 x1)
Claim: 3SAT (G,m) CLIQUE Claim: If 3SAT then (G,m) CLIQUE Proof: Given a SAT assignment A of , for every clause C there is at least one literal in C that’s set true by A For each clause C, let vC be a vertex from group C whose label is a literal that is set true by A Claim: S = {vC : C } is an m-clique Proof: Let vC,vC’ be in S. Suppose (vC,vC’) ∉ E. Then vC and vC’ must label inconsistent literals, call them x and x But assignment A cannot satisfy both x and x Therefore (vC,vC’) E, for all vC, vC’ S. Hence S is an m-clique, and (G,m) CLIQUE
Claim: 3SAT (G,m) CLIQUE Claim: If (G,m) CLIQUE then 3SAT Proof: Let S be an m-clique of G. We construct a satisfying assignment A of . Claim: S contains exactly one node from each group. Now for each variable x of , make assignment A: Assign x to 1 There is a vertex v ϵ S with label x For all i = 1,…,m, at least one vertex from group i is in S. Therefore, for all i = 1,…,m. A satisfies at least one literal in the ith clause of . Therefore A is a satisfying assignment to
(G, k) CLIQUE iff (G’, k) IS Independent Set IS: Given a graph G = (V, E) and integer k, is there S V such that |S|=k and no two vertices in S have an edge? IS = {(G,k) | G is an undirected graph with an IS of size k} CLIQUE: Given G = (V, E) and integer k, is there S V such that |S|=k and every pair of vertices in S have an edge? CLIQUE ≤P IS: Given G = (V, E), output G’ = (V, E’) where E’ = {(u,v) | (u,v) ∉ E}. (G, k) CLIQUE iff (G’, k) IS
The Vertex Cover Problem a e c d b a e c d vertex cover = set of nodes C that cover all edges: For all edges, at least one endpoint is in C
VERTEX-COVER = { (G,k) | G is a graph with a vertex cover of size at most k} Theorem: VERTEX-COVER is NP-Complete (1) VERTEX-COVER NP (2) IS P VERTEX-COVER
IS P VERTEX-COVER Want to transform a graph G and integer k into G’ and k’ such that (G,k) IS (G’,k’) VERTEX-COVER
IS P VERTEX-COVER Claim: For every graph G = (V,E), and subset S V, S is an independent set if and only if (V – S) is a vertex cover Proof: S is an independent set (8 u, v V)[ (u S and v S) ) (u,v) ∉ E ] (8 u, v V)[ (u,v) E ) (u ∉ S or v ∉ S) ] (V – S) is a vertex cover Therefore (G,k) IS (G,|V| – k) VERTEX-COVER Our polynomial time reduction: f(G,k) := (G, |V| – k)
The Subset Sum Problem Given: Set S = {a1,…, an} of positive integers and a positive integer t Is there an A µ {1, … ,n} such that t = i 2 A ai ? SUBSET-SUM = {(S, t) | 9 A µ S s.t. t = i 2 A ai } A simple number-theoretic problem Theorem: SUBSET-SUM is NP-complete Note: There is an O(n ⋅ t) time algorithm for Subset Sum. Does this prove P=NP?
VC P SUBSET-SUM Want to reduce a graph to a set of numbers Given (G, k), let E = {e0,…,em-1} and V = {1,…,n} Our subset sum instance (S, t) will have |S| = n+m “Edge numbers”: For every ej 2 E, put bj = 4j in S “Node numbers”: For every i 2 V, put ai = 4m + j : i 2 ej 4j in S Set the target number: t = k ¢ 4m + j=0m-1 (2 ¢ 4j)
For every ej 2 E, put bj = 4j in S For every i 2 V, put ai = 4m + j : i 2 ej 4j in S Set the target number: t = k ¢ 4m + j=0m-1 (2 ¢ 4j) Claim: If (G,k) VC then (S,t) SUBSET-SUM Suppose C µ V is a VC with k vertices. Let S’ = {ai : i 2 C} {bj : |ej \ C| = 1} S’ = (node numbers corresponding to nodes in C) plus (edge numbers corresponding to edges covered only once by C) Claim: The sum of all numbers in S’ equals t Think of the numbers as being in “base 4”… as vectors with m+1 components
i 2 C ai + ej 2 F bj = t = k ¢ 4m + j=0m-1 (2 ¢ 4j) For every ej 2 E, put bj = 4j in S For every i 2 V, put ai = 4m + j : i 2 ej 4j in S Set the target number: t = k ¢ 4m + j=0m-1 (2 ¢ 4j) Claim: If (S,t) SUBSET-SUM then (G,k) VC Suppose C µ V and F µ E satisfy i 2 C ai + ej 2 F bj = t = k ¢ 4m + j=0m-1 (2 ¢ 4j) Claim: C is a vertex cover of size k. Proof: Subtract out the bj numbers from the above sum. What remains is a sum of the form: i 2 C ai = k ¢ 4m + j=0m-1 (cj ¢ 4j) where each cj > 0. But cj = number of nodes in C covering ej This implies C is a vertex cover!
Finding Paths - Two Problems Let G denote a graph, and s and t denote nodes. SHORTEST PATH = {(G, s, t, k) | G has a simple path of length < k from s to t } LONGEST PATH = {(G, s, t, k) | G has a simple path of length > k from s to t } Are either of these in P? Are both of them?
HAMPATH = { (G,s,t) | G is an directed graph with a Hamiltonian path from s to t} Theorem: HAMPATH is NP-Complete (1) HAMPATH NP (2) 3SAT P HAMPATH See Sipser for the proof
HAMPATH P LONGEST-PATH = {(G, s, t, k) | G has a simple path of length > k from s to t } Can reduce HAMPATH to LONGEST-PATH by observing: (G, s, t) 2 HAMPATH (G, s, t, |V|) 2 LONGEST-PATH Therefore LONGEST-PATH is NP-hard.
Coping with NP-Completeness [Advanced Topics] There are thousands of NP-complete problems Many are solved all the time !?! Average Case vs. Worst Case; Heuristics vs. Algorithms [Beyond Worst-Case Analysis (CS264)] Special cases/parameters that make a problem easy Approximation Algorithms
Approximating Vertex Cover Vertex Cover = set of nodes that cover all edges. Minimization problem: find the smallest VC A very simple (greedy) approximation algorithm A: finds a VC that is at most twice as large as the optimal (a 2-approximation). Algorithm: Set C= and while there exist uncovered edge e, add both endpoints of such e to C Why does it work?