28
NP Completeness Piyush Kumar

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

Embed Size (px)

DESCRIPTION

Convex Hulls and Sorting What are convex hulls? Given a program for computing convex hulls, can we use it to sort ?

Citation preview

Page 1: 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

NP CompletenessPiyush Kumar

Page 2: 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

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.

Page 3: 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

Convex Hulls and Sorting• What are convex hulls?

• Given a program for computing convex hulls, can we use it to sort ?

Page 4: 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

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.

Page 5: 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

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”

Page 6: 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

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

Page 7: 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

Review : P, NP• Set of problems : P, NP• P = Can be solved in polynomial

time• NP = You can verify the solution

in polynomial time• P NP ?• P = NP ? (Probably not?)

Page 8: 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

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

Page 9: 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

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 )

Page 10: 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

P

NP

NP-complete

NP-hard

Primality testingSemidefinite programming…

Hamilton cycle, Independent Set, Vertex Cover,Graph 3-coloring,Satisfiability…

Factoring …

Halting Problem

Assuming P NP

Page 11: 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

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

Page 12: 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

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.

Page 13: 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

Cook’s Theorem• Theorem (Cook 1970) SAT is NP-Complete.

– CNF-SAT is also NP-Complete.

• Corollary 3-SAT is NP-Complete.

• Proof of Corollary

– How do we prove it?

– Recall the defn of NP-Complete

Page 14: 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

Proving NP Completeness• What steps do we have to take to

prove a problem P is NP-Complete?– A problem P is NP-complete if

1. it is in NP2. 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

Page 15: 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

Algorithm for P

Reduction R R(x)

Input for P

Output for P

yes/no

Output for Q

x

Input for Q

Reduction revisited: (Q P)

Algorithm for solving Q

Page 16: 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

3-SAT is NP-Complete• 3-SAT is in NP (Trivial)

• We will pick Q to be CNF-SAT

• To show : CNF-SAT P 3-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

Page 17: 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

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.

Page 18: 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

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.

Page 19: 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

3-SAT is NP-Complete• 3-SAT is in NP• CNF-SAT P 3-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.

Page 20: 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

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?

Page 21: 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

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?

Page 22: 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

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?

Page 23: 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

Approximation Algorithms• For some NP-Complete problems,

there are polynomial time algorithms that give near optimal solutions.

Page 24: 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

Vertex cover

Page 25: 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

Vertex cover• VC is NP-Complete

– (can be reduced from 3-SAT)

Page 26: 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

Approximation Alg for VC1. S 2. E E[G]3. while E 4. let (u,v) be am arbitrary edge in E5. S S {u,v}6. remove from E every edge

incident on either u or v7. return S

Page 27: 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

example

Page 28: 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

2-Factor : Proof• The vertex cover output by the

approximation algorithm is no more than twice the size of the optimal vertex cover.

• Why?