Lecture 22 NPHard Problems Outline NP NPhard NPcomplete
Lecture 22 NP-Hard Problems
Outline • NP, NP-hard, NP-complete • Cook-Levin Theorem, first NP-hard problems • Reductions • INDEPENDENT SET to CLIQUE • 3 -SAT to INDEPENDENT SET
Polynomial time reductions • Recall: General Reduction • Polynomial time reduction A(X) { } do something call B do something else spend polynomial time to prepare an input Y for problem B return B(Y) • Can only spend polynomial time • Cannot do any post-processing.
Polynomial time reductions • Reduce A to B: if there is a polynomial time algorithm that can transform an instance X of problem A to an instance Y of problem B in polynomial time, such that the answers are the same, then this is called a polynomial time reduction. X: instance of A reduction Y: instance of B • If answer to X is YES, answer to Y is also YES • If answer to X is NO, answer to Y is also NO • A is easier, if B can be solved in polynomial time, then A can also be solved in polynomial time.
Hard problems: NP complete • Hardest problems in NP. • If A is in NP, and B is a NP complete problem, then A can be reduced to B. • Corollary: If any of the NP complete problems can be solved in polynomial time, then P = NP. • Theorem: Cook-Levin: Circuit-SAT is NP-complete.
Harder problems? • There are problems that are not in NP. • Example 1: Halting Problem: given the code of a program, check if it will terminate or not. • This problem is not even solvable. • Example 2: Playing chess: given a chess board with n*n size, with 4 n chess pieces, decide whether the first player can always win. • This is believed to be PSPACE complete, and very unlikely to be in NP.
NP-hard problems • A problem A is NP-hard, if for all problem B in NP, B can be reduced to A in polynomial time. • A is “harder” than all problems in NP, hence NP-hard. • A problem A is NP-complete, if it is in NP and also NP-hard. • NP-hard but not NP-complete? • May not be a decision problem, e. g. longest path. • May be even harder than NP-complete problems.
Relationships NP-hard NP-complete NP P
NP-complete problems • Claim: All NP-complete problems are equally hard. For any two NP-complete problems A, B, A can be reduced to B and B can be reduced to A. • Claim: If any NP-complete problem has a polynomial time algorithm, then P = NP. • Claim: If A can be reduced to B, B can be reduced to C, then A can be reduced to C. • How do we prove a problem is NP-complete?
Outline • NP, NP-hard, NP-complete • Cook-Levin Theorem, first NP-hard problems • Reductions • INDEPENDENT SET to CLIQUE • 3 -SAT to INDEPENDENT SET
The first NP-complete problem • Gates • Circuits
CIRCUIT-SAT problem • Given a circuit with n inputs and 1 output, is there a possible input (represented by n-bit binary string) that makes the output 1? • Clearly in NP: • Prover gives the input as an n-bit string, • Verifier follows the circuit and computes the output, check that it is indeed 1. • Theorem[Cook-Levin] CIRCUIT-SAT is NP-complete.
Proof idea of Cook-Levin Verify(color[]) //color[] is an array with 0, 1, 2 FOR each edge (u, v) IF color[u]<>color[v] THEN RETURN FALSE RETURN TRUE NP-hard problem Verifier
Proof idea of Cook-Levin Verify(color[]) //color[] is an array with 0, 1, 2 FOR each edge (u, v) IF color[u]<>color[v] THEN RETURN FALSE RETURN TRUE Compiler Input: binary Output: instance! encoding. CIRCUIT-SAT of True/False color[] 01010101 0010101011 Machine code
Outline • NP, NP-hard, NP-complete • Cook-Levin Theorem, first NP-hard problems • Reductions • INDEPENDENT SET to CLIQUE • 3 -SAT to INDEPENDENT SET
Other NP-hard Problems A NP-Hard • • Reduction B NP-Hard A is NP-hard For any problem C in NP, C is easier than A. A can be reduced to B A is easier than B For any problem C in NP, C is easier than B B is NP-hard
General Recipe for reductions • In order to prove B is NP-hard, given that we know A is NP hard. • Reduce A to B. • What is a complete reduction? 1. Given an instance X of A, construct an instance Y of B. 2. Prove that if answer to X is YES, answer to Y is also YES. 3. Prove that if answer to X is NO, answer to Y is also NO. (Usually: prove the contrapositive: if answer to Y is YES, answer to X is also YES)
INDEPENDENT SET • Given a graph, decide whethere is a set of k vertices, such that no two vertices in the set are connected by an edge.
CLIQUE • Given a graph, decide whethere is a set of k vertices, such that all pairs of vertices in the set are connected by an edge. • Claim: INDEPENDENT SET can be reduced to CLIQUE.
Reduction from INDEPENDENT SET to CLIQUE • Step 1: Given an instance X of INDEPENDENT SET, construct an instance Y of CLIQUE. • Idea: Find similarities/differences of the problems. • INDEP. SET: find vertices such that they are not connected. • CLIQUE: find vertices such that they are connected.
3 -SAT •
Reductions • Claim: CIRCUIT-SAT can be reduced to 3 -SAT. (therefore 3 -SAT is also NP-complete). • Claim: 3 -SAT can be reduced to INDEPENDENT SET. CIRCUIT -SAT NP-complete 3 -SAT NP-complete INDSET NP-complete CLIQUE NP-complete
Reduction from 3 -SAT to INDEPENDENT SET • Step 1: Given an instance X of 3 -SAT, construct an instance Y of INDEPENDENT SET. • Problem: the two problems look totally different. • Idea: Construct “Gadgets”: for each concept in 3 SAT (variables, clauses), construct a part of instance of INDEP. SET (some vertices/edges) so that we can connect the two problems.
Gadget for variables • Variable xi: either true or false • Gadget: A graph with two different independent sets, corresponding to xi = true or false. • Many constructions, but easiest one ui vi • Hope: ui in independent set xi = true vi in independent set xi = false
Gadget for Clauses •
Gadget for Clauses Goal: When clause is not satisfied, cannot select any vertex in gadget. v 1 v 3 u 5 Gadget When clause is satisfied, can select exactly one vertex in gadget This encourages all the clauses to be satisfied.
Gadget for Clauses v 1 v 3 u 5 w 1 w 2 w 3 Goal: When clause is not satisfied, cannot select any vertex in gadget. When clause is satisfied, can select exactly one vertex in gadget This encourages all the clauses to be satisfied.
- Slides: 27