np-complete problemscrystal.uta.edu/~kumar/cse5311_10fldaa/cse5311m9new.pdfnp-complete problems p...

21
11/8/2010 1 NP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability Problem, Clique Problem, Vertex Cover, and Dominating Set Polynomial Algorithms Problems encountered so far are polynomial time algorithms The worst-case running time of most of these algorithms is O(n k ) time for some constant k time, for some constant k. All problems cannot be solved in polynomial time There are problems that cannot be solved at all – Unsolvable There are problems that can be solved but not in O(n k ) time for some constant k. Note that most useful algorithms are of complexity O(n 3 ) or better. Problems that are solvable in polynomial time by polynomial- time algorithms are said to be tractable (or easy or efficient). Problems that require superpolynomial time are said to be 11/8/2010 CSE 5311 FALL 2010 KUMAR 2 Problems that require superpolynomial time are said to be intractable or hard.

Upload: others

Post on 05-Jun-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

1

NP-Complete Problems

P and NP

Polynomial time reductions

11/8/2010 CSE 5311 FALL 2010 KUMAR 1

Satisfiability Problem, Clique Problem, Vertex Cover, and

Dominating Set

Polynomial Algorithms

Problems encountered so far are polynomial time algorithms The worst-case running time of most of these algorithms is O(nk)

time for some constant ktime, for some constant k. All problems cannot be solved in polynomial time There are problems that cannot be solved at all – Unsolvable There are problems that can be solved but not in O(nk) time for

some constant k. Note that most useful algorithms are of complexity O(n3) or better.

Problems that are solvable in polynomial time by polynomial-time algorithms are said to be tractable (or easy or efficient).

Problems that require superpolynomial time are said to be

11/8/2010 CSE 5311 FALL 2010 KUMAR 2

Problems that require superpolynomial time are said to be intractable or hard.

Page 2: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

2

P and NP Class P problems are solvable in polynomial time. Class NP problems are verifiable in polynomial time. Class NP is the class of decision problems that can be solved

by non-deterministic polynomial algorithms. For example, given a problem, we can verify the solution in

polynomial time

Any problem in P is also in NP P NP It is NOT KNOWN whether P is a proper subset of NP. An NP-complete problem is in NP

As diffic lt as an other problem in NP

11/8/2010 CSE 5311 FALL 2010 KUMAR 3

As difficult as any other problem in NP An instance of this problem can be reduced to an instance of a

known NP-Complete problem in polynomial time

NP

What are NP-complete Problems?A problem is said to be NP-Complete if it is as ‘hard’

bl i NPas any problem in NP. No polynomial time algorithm has yet been

discovered for a NP-Complete problem. However, it has not been proven that NO polynomial

time algorithm can exist for a NP-Complete problem. This problem was first posed by Cook in 1971. The issue of, P=NP or P NP is an open research

11/8/2010 CSE 5311 FALL 2010 KUMAR 4

problem In 2002, a problem that known to be in NP was

shown to have a polynomial time algorithm. Whether a given integer is a prime or composite

Page 3: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

3

Examples of NP-Complete problems

Shortest vs. longest simple paths

Finding the shortest paths from a single source in a directed graph G =(V,E) can be completed in O(V + E) time. Even with negative edge weights.

However, finding the longest simple path between two vertices is NP-complete. It is NP-Complete even if each of edge weights is equal to one.

An Euler tour of a connected directed graph G=(V,E), can be

11/8/2010 CSE 5311 FALL 2010 KUMAR 5

g p ( , ),completed in O(E) time.

However, the Hamiltonian Cycle is a NP-Complete problem.The traveling salesman problem is a variation of the Hamiltonian cycle.

NP- Complete problems Given a problem X

Prove that the problem is in NP

A solution to the problem is verifiable in polynomial time

Choose a problem Y that is already known to be NP Complete Choose a problem, Y that is already known to be NP-Complete

Consider an arbitrary instance Sy of Y and show how to construct an instance Sx of X in polynomial time that satisfies:

If Sy is a ‘Yes’ instance of Y then Sx is a ‘Yes’ instance in X

11/8/2010 CSE 5311 FALL 2010 KUMAR 6

Page 4: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

4

Polynomial Time Reductions

Decision Problems: Problems whose answer is yes or no!!Most problems can be converted to decision problems.

Language recognition problem is a decision problem. Suppose L U is the set of all inputs for which the answer

to the problem is yes – L is called the language corresponding to the problem

(Turing machines).The terms language and problem are used interchangeably.

11/8/2010 CSE 5311 FALL 2010 KUMAR 7

g y Given a problem, with an input language X, Now the decision problem can be defined as the problem

to recognize whether or not X belongs to L.

Reductions Contd.

Definition: Let L1 and L2 be two languages from input spaces U1 and U2. We say that L1 is polynomially reducible to L2 if there exists a polynomial time algorithm that converts each inputthere exists a polynomial-time algorithm that converts each input u1 U1 to another input u2U2 such that u1 L1 iff u2 L2. The algorithm is polynomial in the size of the input u1.

If we have an algorithm for L2 then we can compose an algorithm for L1.

If L1 is polynomially reducible to L2 and if there is a polynomial-time algorithm for L2, then there is a polynomial time algorithm for L1.

11/8/2010 CSE 5311 FALL 2010 KUMAR 8

Reducibility is not symmetric L1 is polynomially reducible to L2 does not imply L2 is polynomially

reducible to L1

Page 5: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

5

The Satisfiability (SAT) Problem

S – Boolean expression in Conjunctive Normal Form (CNF)(Product (AND) of Sums (ORs)

For example The SAT problem is to determine whether a given Boolean expression

is Satisfiable (without necessarily finding a satisfying assignment) We can guess a truth assignment and check that it satisfies the

expression in polynomial time. SAT is NP hard A Turing machine and all of its operations on a given input can be

d ib d b B l E i Th i ill b ti fi bl

)()()( zyxzyxzyxS

11/8/2010 CSE 5311 FALL 2010 KUMAR 9

described by a Boolean Expression. The expression will be satisfiableiff the Turing machine will terminate at an accepting state for the given input.

http://www.nada.kth.se/~viggo/problemlist/compendium.html

Clique Problem

)()()( zyxzyxzyx

x

y y

x

x

y

11/8/2010 CSE 5311 FALL 2010 KUMAR 10

z

y

zz

Page 6: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

6

Clique Problem: a clique in an undirected graph is a subset of its vertices such that every two vertices in the subset are connected by an edge; The problem of finding whether there is a clique of a given size in a graph is NP-complete

)()()( zyxzyxzyx

x

y y

x

x

y

11/8/2010 CSE 5311 FALL 2010 KUMAR 11

z

y

zz

Clique Problem

)()()( zyxzyxzyx

x

y y

x

x

y

11/8/2010 CSE 5311 FALL 2010 KUMAR 12

z

y

zz

Page 7: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

7

Clique Problem

)()()( zyxzyxzyx

x

y y

x

x

y

11/8/2010 CSE 5311 FALL 2010 KUMAR 13

z

y

zz

Clique Problem

)()()( zyxzyxzyx

x

y y

x

x

y

11/8/2010 CSE 5311 FALL 2010 KUMAR 14

z

y

zz

Page 8: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

8

Vertex Cover problem

A

A vertex cover of G = (V,E) is a set of vertices such that every edge in E is incident to at least one of the vertices in the vertex cover.

ED

CB

11/8/2010 CSE 5311 FALL 2010 KUMAR 15

Vertex Cover problem

A A

A vertex cover of G = (V,E) is a set of vertices such that every edge in E is incident to at least one of the vertices in the vertex cover.

ED

CB

ED

CB

11/8/2010 CSE 5311 FALL 2010 KUMAR 16

G G’

complement of G

Page 9: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

9

Vertex Cover problem

A

A vertex cover of G = (V,E) is a set of vertices such that every edge in E is incident to at least one of the vertices in the vertex cover.

ED

CB

11/8/2010 CSE 5311 FALL 2010 KUMAR 17

G has a maximum clique of size V-k

Vertex Cover problem

A A

A vertex cover of G = (V,E) is a set of vertices such that every edge in E is incident to at least one of the vertices in the vertex cover.

ED

CB

ED

CB

11/8/2010 CSE 5311 FALL 2010 KUMAR 18

G’ has a minimum vertex cover of size k if and only if G has a maximum clique of size V-k

G’

complement of G

Page 10: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

10

Vertex Cover problem

A A

A vertex cover of G = (V,E) is a set of vertices such that every edge in E is incident to at least one of the vertices in the vertex cover.

ED

CB

ED

CB

11/8/2010 CSE 5311 FALL 2010 KUMAR 19

G G’

complement of G

Dominating Set

G = (V,E) is an undirected graph. A dominating set D of G is a set of vertices (a subset of V) such that every vertex of G is either in D or is adjacent to at least one vertex from D.

A BA

11/8/2010 CSE 5311 FALL 2010 KUMAR 20

DC

G has a vertex cover of size m

Page 11: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

11

Dominating Set

G = (V,E) is an undirected graph. A dominating set D of G is a set of vertices (a subset of V) such that every vertex of G is either in D or is adjacent to at least one vertex from D.

AB

A BA A BA

ACBD

AD

11/8/2010 CSE 5311 FALL 2010 KUMAR 21

DC DC

CD

Dominating Set

G = (V,E) is an undirected graph. A dominating set D of G is a set of vertices (a subset of V) such that every vertex of G is either in D or is adjacent to at least one vertex from D.

AB

A BA A BA

ACBD

AD

11/8/2010 CSE 5311 FALL 2010 KUMAR 22

DC DC

CDG has a vertex cover of size m

Page 12: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

12

Dominating Set

G = (V,E) is an undirected graph. A dominating set D of G is a set of vertices (a subset of V) such that every vertex of G is either in D or is adjacent to at least one vertex from D.

AB

A BA A BA

ACBD

AD

11/8/2010 CSE 5311 FALL 2010 KUMAR 23

DC DC

CDG’ has a dominating set of size m if and only if G has a vertex cover of size m

Dominating Set

G = (V,E) is an undirected graph. A dominating set D of G is a set of vertices (a subset of V) such that every vertex of G is either in D or is adjacent to at least one vertex from D.

AB

A BA A BA

ACBD

AD

11/8/2010 CSE 5311 FALL 2010 KUMAR 24

DC DC

CDG’ has a dominating set of size m if and only if G has a vertex cover of size m

Page 13: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

13

NP Complete Problems Hamiltonian Circuit Problem

Determine whether a given graph has a Hamiltonian circuit. Travelling Salesman

Find the shortest tour through n cities with known positive integer distances between them.

Knapsack Problem Find the most valuable subset of n items of given positive integer weights and

values that fit into a knapsack of a given positive integer capacity. Partition Problem

Given n positive integers, determine whether it is possible to partition them into two disjoint subsets with the same sum.

Bin Packing Given n items whose sizes are positive rational numbers not larger than 1, put

them into the smallest number of bins of size 1. Graph Coloring

11/8/2010 CSE 5311 FALL 2010 KUMAR 25

p g For a given graph, find its chromatic number (the smallest number of colors that

need to be assigned to the graph’s vertices so that no two adjacent vertices are assigned the same color.

Integer Linear Programming Find the maximum (or minimum) value of a linear function of several integer-

valued variables subject to a finite set of constrains in the form of linear equalities and/or inequalities.

Dealing with NP Complete problems

Proving that a given problem is NP-Complete does not make the problem go away!! Udi Manber

An NP-Complete problem cannot be solved precisely in polynomial timeW k i i t f ti lit b t ffi i l t We make compromises in terms of optimality, robustness, efficiency, or completeness of the solution.

Approximation algorithms do not lead to optimal solutions Probabilistic algorithms

Branch and bound

Backtracking

11/8/2010 CSE 5311 FALL 2010 KUMAR 26

Page 14: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

14

Backtracking

The Hamiltonian Circuit Problem

Th S b t bl The Subset problem

11/8/2010 CSE 5311 FALL 2010 KUMAR 27

Branch and Bound

Job Assignment

K k Knapsack

11/8/2010 CSE 5311 FALL 2010 KUMAR 28

Page 15: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

15

Hamiltonian Circuit

The vertex cover is polynomially transformable to the Hamiltonian Circuit problem for directed graphs.

G = (V E) is a given undirected graph and k is an integerG = (V,E) is a given undirected graph and k is an integer

We construct new graph G’ = (V’, E’) such that G’ has a Hamiltonian Circuit iff a set of k vertices of V covers the edges of G.

V = {v1, v2, …, vn}

Each edge (vi,vj) is denoted by eij.

a1, a2, … ak are new symbols ( vertex cover of size k)

The vertices of G’ will consist of one vertex corresponding to each ai PLUS

Four vertices for each edge of G.

Vd = {a a2 An} {[v e b] | v V e E b {0 1} and e is incident upon v }

11/8/2010 CSE 5311 FALL 2010 KUMAR 29

Vd = {a, a2, . . . An} {[v, e, b] | v V, e E, b {0,1}, and e is incident upon v }.

Edge (vi, vj)

From previous edge adjacent to vi

From previous edge adjacent to vj

[vi,eij,0] [vj,eij,0]

[ j ij 1]

A B

D

to vi

11/8/2010 CSE 5311 FALL 2010 KUMAR 30

[vi,eij,1] [vj,eij,1]CD

To next edge adjacent to vjTo next edge

adjacent to vi

Page 16: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

16

Additional Edges

Each aj has an edge to the vertices (vi,eil, 0) such that eil is the first edge on the list for vi.

There is an edge from [vi,eil,1] to each aj if eil is the last edge on the list for vi.

There is an edge from [vi,eil,1] to [vi,eim,0] if edge eim immediately follows eil on the list for vi.

11/8/2010 CSE 5311 FALL 2010 KUMAR 31

v3v2

v1

e23

e13e12

[v1,e12,0] [v2,e12,0]

a1 a2

[v1,ei2,1] [v2,e12,1]

[v1,e13,0] [v3,e13,0]

[v1,e13,1] [v3,e13,1]

11/8/2010 CSE 5311 FALL 2010 KUMAR 32

[v2,e23,0] [v3,e23,0]

[v2,e23,1] [v3,e23,1]

Page 17: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

17

Set Cover

Given a set U of n elements, a collection S1, S2, … Sm of subsets of U, and a number k, does there exist a collection of at most k of these sets whose union is equal to all of Uequal to all of U

Please see pages 456-457 of Kleinberg’s book

11/8/2010 CSE 5311 FALL 2010 KUMAR 33

P NP and NP CompleteP, NP and NP-Complete

Page 18: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

18

P, NP and NP-Complete

P : Problems that can be solved in Polynomial time

NP: Problems that have no known polynomial time solutions; these problems are said to have nondeterministic polynomial time algorithms.

NP- Complete – a class of problems within NP An instance of a known NP-Complete problem can

be reduced to an in instance of the problem under consideration.consideration.

The reduction can be completed in polynomial time

It is said that P and NP-C are contained in NP

NP

We do not know of any polynomial time algorithms for these problemsalgorithms for these problems

We cannot prove that no polynomial time algorithm exists for these problems

Page 19: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

19

NP-Complete

A class of problems within NP

These problems are said to be equivalent These problems are said to be equivalent An instance of one problem to can be reduced to

an instance of the other

A polynomial time algorithm for one of them would imply polynomial algorithm for all problems in NPC

There are large number of NP-Complete problems Classical (e.g., SAT, Clique, Hamiltonian Circuit,

Graph Coloring etc.)

Optimization problems in different areas

Polynomial type reductions

Arbitrary instances of one problem (say X) can be reduced to an instance of another problembe reduced to an instance of another problem (say Y), in polynomial time.

If X can be solved in polynomial time, then Y can be solved in polynomial time, and vice versa

We assume ‘SAT’ problem to the NP-Complete

Reduce an instance of the SAT problem to anReduce an instance of the SAT problem to an instance of the problem under consideration in polynomial time.

Page 20: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

20

More on NP-Complete problems

Whether P = NP is a fundamental problem in CS.

Given a problem X here is the strategy to prove that Given a problem X, here is the strategy to prove that it is NP-Complete Prove that X NP

Choose a problem Y that is known to be NP-Complete

Consider an arbitrary instance SY of problem Y and construct in polynomial time, an instance of problem X that satisfies

If SYis a ‘yes’ instance of Y then SX is a ‘yes SY s a yes sta ce o t e SX s a yesinstance of X

If SX is a ‘yes’ instance of X then SY is a ‘yes instance of Y

Problem in NP

A problem is said to be in NP by a certification Best understood with examplesp Hamiltonian Cycle

G (V,E) is the given graph, a certificate is an ordered list of vertices forming the Hamiltonian cycle.

In polynomial time, we can check that this list contains each vertex exactly once and there is an edge between ordered pairs of vertices.

Vertex Cover problemG (V E) i th i h tifi t i b t f G (V,E) is the given graph, a certificate is a subset of vertices that cover all the edges in the graph.

In polynomial time, check that the above subset of vertices indeed cover all the edges.

Page 21: NP-Complete Problemscrystal.uta.edu/~kumar/CSE5311_10FLDAA/CSE5311M9New.pdfNP-Complete Problems P and NP Polynomial time reductions 11/8/2010 CSE 5311 FALL 2010 KUMAR 1 Satisfiability

11/8/2010

21

Garey, M.R.; Johnson, D.S. (1979). Computers and Intractability: A Guide to theComputers and Intractability: A Guide to the Theory of NP-Completeness. New York: W.H. Freeman. ISBN 0-7167-1045-5.

Cook, S.A. (1971). "The complexity of theorem proving procedures". Proceedings, Third Annual ACM Symposium on the TheoryThird Annual ACM Symposium on the Theory of Computing, ACM, New York. pp. 151–158.