280 likes | 482 Views
NP Completeness. Piyush Kumar. Today. Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete Problems Average Case / Heuristics / Approx. Alg. Convex Hulls and Sorting. What are convex hulls?
E N D
NP Completeness Piyush Kumar
Today • Reductions • Proving Lower Bounds revisited • Decision and Optimization Problems • SAT and 3-SAT • P Vs NP • Dealing with NP-Complete Problems • Average Case / Heuristics / Approx. Alg.
Convex Hulls and Sorting • What are convex hulls? • Given a program for computing convex hulls, can we use it to sort ?
Reduction from Sorting to CH • Given n real values xi , generate n 2D points on a parabola, e.g. (xi,xi2). • Compute the (ordered) convex hull of the points. • The order of the convex hull points is the numerical order of the xi.
Reduction from Sorting to CH • Does this imply a lower bound on computation of convex hulls? • (nlgn) ? • Sorting p CH • p : Can also be read as • “No harder to solve than”
Polynomial time reductions • If P is polynomial-time reducible to Q, we will use the notation P p Q • P p Q and Q p R • Implies P p R
Review : P, NP • Set of problems : P, NP • P = Can be solved in polynomial time • NP = You can verify the solution in polynomial time • PNP ? • P=NP ? (Probably not?)
definitions • NP-Hard : For all R in NP, R p T • Implies T is NP-Hard • NP-Complete • T is both in NP and NP-Hard
Definitions : Revisited • NP-Hard • If you can solve it, you can solve everything in NP • NP-Complete • NP-Hard and in NP • NP : Non-Deterministic Polynomial time. ( Guess and verify )
Assuming P NP Halting Problem NP-hard NP-complete Hamilton cycle, Independent Set, Vertex Cover,Graph 3-coloring,Satisfiability… NP Factoring … P Primality testingSemidefinite programming…
Decision Vs Optimization • Decision Problem: computational problem with intended output of “yes” or “no”, 1 or 0 • Optimization Problem: computational problem where we try to maximize or minimize some value • Introduce parameter k and ask if the optimal value for the problem is a most or at least k. Turn optimization into decision
Decision Vs Optimization • Optimization Problem: TSP • Decision problem • Is their a tour of length < k? • Simplification: Worry only about decision problems. The class P, NP, NPC, NPH all constitute of only decision problems.
Cook’s Theorem • Theorem (Cook 1970) SAT is NP-Complete. • CNF-SAT is also NP-Complete. • Corollary3-SAT is NP-Complete. • Proof of Corollary • How do we prove it? • Recall the defn of NP-Complete
Proving NP Completeness • What steps do we have to take to prove a problem Pis NP-Complete? • A problem P is NP-complete if 1. it is in NP 2. B NP, B p P (it is NP-Hard) • Idea for condition 2 : • Use a known NP-Complete problem Q. • Show Q p P. • By transitivity of p, we are done • B NP, B p Q p P • Hence : B NP, B p P
Reduction revisited: (Q P) x Input for Q R(x) Input for P Output for P yes/no Output for Q Algorithm for P Reduction R Algorithm for solving Q
3-SAT is NP-Complete • 3-SAT is in NP (Trivial) • We will pick Q to be CNF-SAT • To show : CNF-SAT P3-SAT. • Let ∏ be the given CNF formula. We want to transform ∏ to an instance of 3-CNF. • Idea: Transform each clause of ∏ so that it is 3-CNF
CNF-SAT to 3-SAT • If less than 3 literals, repeat them. • Replace (a1 a2) by (a1 ∨ a2 ∨ a2) • If 3 literals, leave it as it is.
CNF-SAT to 3-SAT • 4 literals : Replace(a1 a2 a3 a4) by (a1 a2 z) (z a3 a4) • In general, replace (a1 a2 ak) by (a1 a2 z1) (z1 a3 z2) (z2 a4 z3) (zk-3 ak-1 ak) • z1 , , zk-3:new variables • This is analogous to the 4 literal case, just applied multiple times with more variables.
3-SAT is NP-Complete • 3-SAT is in NP • CNF-SAT P3-SAT • Since we can transform an input to the CNF-SAT problem in polynomial time to the 3-SAT problem solver and get a solution to CNF-SAT. Hence CNF-SAT is ‘no harder to solve than’ 3-SAT.
Other NP-Complete Problems • Hamiltonian Cycle • Of size k? • Vertex cover : A vertex cover of G is a set C V such that all edges of E have at least one endpoint in C. • Clique : Find in a given graph G, if there is a size k clique?
Other NP-Complete Problems • Set Cover : Given n sets, are there k sets out of these whose union is the same as the union of n sets? • Subset Sum : Given a set of integers, and another integer k; Is there a subset of them that sum upto k?
Toy Problem • TSP is NP-Complete • Decision Version: Does a TSP with cost < k ? • Is TSP in NP? • What problem should we pick to prove this?
Approximation Algorithms • For some NP-Complete problems, there are polynomial time algorithms that give near optimal solutions.
Vertex cover • VC is NP-Complete • (can be reduced from 3-SAT)
Approximation Alg for VC • S • E E[G] • while E • let (u,v) be am arbitrary edge in E • S S {u,v} • remove from E every edge incident on either u or v • return S
2-Factor : Proof • The vertex cover output by the approximation algorithm is no more than twice the size of the optimal vertex cover. • Why?