more np complete problems
play

More NP-Complete Problems 19-0 SAT is NP-Complete We - PDF document

Griffith University 3130CIT Theory of Computation (Based on slides by Harald Sndergaard of The University of Melbourne) More NP-Complete Problems 19-0 SAT is NP-Complete We established that every A NP can be


  1. ✬ ✩ Griffith University 3130CIT Theory of Computation (Based on slides by Harald Søndergaard of The University of Melbourne) More NP-Complete Problems ✫ ✪ 19-0

  2. ✬ ✩ SAT is NP-Complete We established that every A ∈ NP can be reduced to SAT in polynomial time. Actually the construction we used reduced every NP problem to SAT CNF , the satisfiability problem for formulas in Conjunctive Normal Form. ✫ ✪ 19-1

  3. � ✬ ✩ SAT is NP-Complete (cont.) But then SAT (for arbitrary propositional formulas) is also NP-complete: 1. It is in NP (as for the CNF case), and 2. There is a trivial poly-time reduction of SAT CNF to SAT . � SAT SAT CNF The reduction from right to left is covered by the general reduction we did in the last lecture. (A direct reduction is not trivial, by the way: We know how to turn an arbitrary formula into CNF, but that technique can cause an exponential blow-up! However, in the translation we don’t have to preserve equivalence, only satisfiability!) ✫ ✪ 19-2

  4. ✬ ✩ 3-SAT A propositional formula is in 3-CNF if it is in CNF and every clause has exactly three literals, as in ( x 1 ∨ ¬ x 2 ∨ ¬ x 3 ) ∧ ( x 1 ∨ x 2 ∨ ¬ x 4 ) 3-SAT is the problem whether a 3-CNF formula is satisfiable. Let us show that the problem is NP-complete. First, 3-SAT is in NP , as the machine which solves SAT in polynomial time also works for 3-SAT . So it suffices to show SAT CNF ≤ P 3-SAT . ✫ ✪ 19-3

  5. ✬ ✩ 3-SAT (cont.) The reduction is as follows. Given an instance of SAT CNF : C 1 ∧ C 2 ∧ . . . C k we turn every clause C into a bunch of 3-literal clauses as follows: If C is a single literal ℓ , produce ( ℓ ∨ ℓ ∨ ℓ ). If C is ( ℓ 1 ∨ ℓ 2 ), produce ( ℓ 1 ∨ ℓ 2 ∨ ℓ 2 ). If C has three literals, leave it as it is. Clearly satisfiability is preserved for these clauses. ✫ ✪ 19-4

  6. ✬ ✩ 3-SAT (cont.) If C has n > 3 literals: ( ℓ 1 ∨ ℓ 2 ∨ ℓ 3 ∨ · · · ∨ ℓ n ) produce n − 2 clauses using n − 3 fresh variables x 3 . . . x n − 1 : ( ℓ 1 ∨ ℓ 2 ∨ x 3 ) ∧ ( ¬ x 3 ∨ ℓ 3 ∨ x 4 ) . . . ∧ ( ¬ x n − 2 ∨ ℓ n − 2 ∨ x n − 1 ) ∧ ( ¬ x n − 1 ∨ ℓ n − 1 ∨ ℓ n ) Why does this preserve satisfiability? ✫ ✪ 19-5

  7. ✬ ✩ 3-SAT (cont.) ⇒ Let t be a truth assignment that satisfies ( ℓ 1 ∨ ℓ 2 ∨ ℓ 3 ∨ · · · ∨ ℓ n ) and let ℓ j be the first literal that comes out true. We satisfy ( ℓ 1 ∨ ℓ 2 ∨ x 3 ) ∧ ( ¬ x 3 ∨ ℓ 3 ∨ x 4 ) . . . ∧ ( ¬ x n − 2 ∨ ℓ n − 2 ∨ x n − 1 ) ∧ ( ¬ x n − 1 ∨ ℓ n − 1 ∨ ℓ n ) by extending t so that x 3 . . . x j are made true, and the remaining x s are false. ✫ ✪ 19-6

  8. ✬ ✩ 3-SAT (cont.) ⇐ Let t be a truth assignment that satisfies ( ℓ 1 ∨ ℓ 2 ∨ x 3 ) ∧ ( ¬ x 3 ∨ ℓ 3 ∨ x 4 ) . . . ∧ ( ¬ x n − 2 ∨ ℓ n − 2 ∨ x n − 1 ) ∧ ( ¬ x n − 1 ∨ ℓ n − 1 ∨ ℓ n ) Then t also satisfies C = ( ℓ 1 ∨ ℓ 2 ∨ ℓ 3 ∨ · · · ∨ ℓ n ) . Namely, assume that it doesn’t. Then every ℓ j is false. So x 3 is true, hence x 4 is, and so on, up to x n − 1 . But then ( ¬ x n − 1 ∨ ℓ n − 1 ∨ ℓ n ) is false. We have a contradiction, so C is satisfiable. ✫ ✪ 19-7

  9. ✬ ✩ NP-complete Graph Problems Clique Given graph G and integer k , does G have a complete subgraph of size k ? Vertex Cover Given graph G and integer k , is there a set C of k nodes such that every edge has (at least) one end in C ? Edge Cover Given graph G and integer k , is there a set C of k edges such that every node is the end of (at least) one edge in C ? Dominating Set Given graph G and integer k , is there a set C of k nodes such that every node is either in C or adjacent to a node in C ? Independent Set Given graph G and integer k , is there a set C of k nodes such that no two nodes in C are adjacent? Subgraph Isomorphism Given graphs G and H , is G isomorphic to some subgraph of H ? ✫ ✪ 19-8

  10. ✬ ✩ NP-complete Graph Problems (cont.) Colouring Given graph G and integer k , can we colour the nodes of G with k colours so that no adjacent nodes have the same colour? Hamiltonian Path Given graph G and nodes s and t , is there a Hamiltonian path in G from s to t ? (A Hamiltonian path is a path that visits every node exactly once.) Hamiltonian Cycle Given graph G , is there a Hamiltonian cycle in G ? Travelling Salesman Problem Given a weighted graph G and integer C , is there a Hamiltonian cycle whose cost (sum of edge weights) is less than C ? ✫ ✪ 19-9

  11. ✬ ✩ The Clique Problem Clique Given graph G and integer k , does G have a complete subgraph of size k ? First, Clique is in NP, because given a set of k nodes of G , we can check whether each pair of nodes in C are adjacent in G in polynomial time. Second, we show Clique is NP-hard by proving that 3SAT ≤ P Clique. Let E = C 1 ∧ · · · ∧ C n be a boolean expression in 3CNF. Let each literal occurrence in C be a node of G . The edges of G connect all pairs of nodes from different clauses except if the two nodes are complementary literals. Let k be n . Clearly ( G, k ) can be constructed in time polynomial in | E | . It is straightforward to see that E is sastisfiable if and only if G has a clique of size k . ✫ ✪ 19-10

  12. ✬ ✩ The Vertex Cover Problem Let G = ( N, E ) be an undirected graph. V ⊆ N is a vertex cover of G iff n 1 ∈ V or n 2 ∈ V for all edges ( n 1 , n 2 ) ∈ E . We show that VERTEX-COVER =  �  G is a graph which has �   �  � G, k � � a vertex cover of size k �  � is NP-complete. The problem is in NP because a nondeterministic TM can guess a set of k nodes and check in polynomial time whether they cover G . All it needs is a linear scan through all of G ’s edges, and for each edge, a linear scan of the guess. ✫ ✪ 19-11

  13. ✬ ✩ Reducing 3-SAT to Vertex Cover For a given 3-CNF formula φ we construct � G, k � such that G has a vertex cover of size k iff φ is satisfiable. Let φ = ( ℓ 11 ∨ ℓ 12 ∨ ℓ 13 ) ∧ · · · ∧ ( ℓ m 1 ∨ ℓ m 2 ∨ ℓ m 3 ) have n variables x 1 . . . x n . We produce 3 m + 2 n nodes, one per literal, and two per variable: { ℓ kj | 1 ≤ k ≤ m, 1 ≤ j ≤ 3 } { x i , ¬ x i | 1 ≤ i ≤ n } and 6 m + n edges: = { x i , ¬ x i } T C k = { ( ℓ k 1 , ℓ k 2 ) , ( ℓ k 2 , ℓ k 3 ) , ( ℓ k 3 , ℓ k 1 ) } L k = { ( ℓ k 1 , v k 1 ) , ( ℓ k 2 , v k 2 ) , ( ℓ k 3 , v k 3 ) } where v kj is x i or ¬ x i depending on which ℓ kj is. ✫ ✪ 19-12

  14. ✬ ✩ 3-SAT to Vertex Cover (cont.) The generated instance is � G, 2 m + n � . For example, ( x 1 ∨ x 2 ∨ ¬ x 3 ) ∧ ( ¬ x 1 ∨ x 2 ∨ x 3 ) is translated to the problem of whether this graph has a cover of size 2 · 2 + 3 = 7: x 1 ¬ x 1 x 2 ¬ x 2 x 3 ¬ x 3 � � � �������������������������� � � ������������� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � ℓ 12 ℓ 22 � � � � � � � � � ������� ������� � � � � � � � � � � � � � � � � � � ℓ 11 ℓ 13 ℓ 21 ℓ 23 By this construction, a vertex cover must contain ✫ ✪ at least 2 m + n nodes. 19-13

  15. ✬ ✩ 3-SAT to Vertex Cover (cont.) Clearly the graph is constructed in polynomial time. We still need to show that G has a vertex cover of size 2 m + n iff φ is satisfiable. ⇒ The cover defines a truth assignment t , as it includes exactly one of x i and ¬ x i . This t makes each clause true: The ℓ kj that is not covered is true. ⇐ Let t satisfy φ . That gives us n nodes ( x i or ¬ x i ) of the cover. For each clause C k , if ℓ kj is satisfied, add the two nodes corresponding to the other two literals in C k . ✫ ✪ 19-14

  16. ✬ ✩ Map and Graph Colouring Four colours suffice in the plane! Tractability of n -colouring: • 1-colouring is trivial. • 2-colouring is easy. • 3-colouring is NP-complete. • 4-colouring is trivial. ✫ ✪ 19-15

  17. ✬ ✩ NP and co-NP With deterministic machines, reversing the yes/no outcome gives an equivalent problem. Using a non-deterministic machine to guess-and-check, it is not clear that this property should hold! For example, how does one guess-and-check that a propositional formula is unsatisfiable? It is not known whether NP is closed under complement. (Of course, if P = NP then it is.) The set of languages that are complements of the NP languages is called co-NP . ✫ ✪ 19-16

  18. ✬ ✩ NP and co-NP (cont.) SAT NP P co-NP The dual of SAT , that is, the validity problem for propositional formulas in CNF, is in co-NP . ✫ ✪ 19-17

Recommend


More recommend