2005 SDU Lecture15 P,NP,NP-complete
2005 SDU 2 The PATH problem PATH = { | G is a directed graph that has a directed path from s to t} s t
2005 SDU 3 An NP algorithm for the PATH problem N= “On input where G is a directed graph and s,t are nodes of G: 1. c:=s; V:={} 2. Repeat while c V and there is an outgoing edge from c: 3. Guess a node b such that G has the edge (c,b); 4. V:=V {c}; c:=b; 5. If t V, accept. Otherwise reject. s t
2005 SDU 4 A P algorithm for the PATH problem N= “On input where G is a directed graph and s,t are nodes of G: 1. Mark s. 2. Repeat until no additional nodes are marked: 3. Scan all the edges of G. If an edge (a,b) is found going from a marked node a to an unmarked node b, mark node b. 4. If t is marked, accept. Otherwise reject. s t
2005 SDU 5 The Hamiltonian path problem HAMPATH = { | G is a directed graph that has a directed path from s to t that goes through every node exactly once} s t
2005 SDU 6 Polynomial time reduction Definition. A function f is polynomial time computable if there exists a polynomial time TM that halts on each input x with only f(x) on the tape. Definition. A language A is polynomial time (mapping) reducible to a language B (write A p B) if A is mapping reducible to B via a polynomial time computable function.
2005 SDU 7 NP-completeness Definition. A language A is NP-complete if A is in NP and every language in NP is polynomial time reducible to A. Theorem. A language A is NP-complete and A P, then P = NP. We may use the following to prove something is NP- complete. Theorem. A language A is NP-complete, B NP, and A p B, then B is NP-complete.
2005 SDU 8 SAT is NP-complete 3SAT is NP-complete. HPATH is NP-complete. CLIQUE is NP-complete. … SAT is NP-complete. Given a Boolean formula = (x 1 x 3 x 7 ) (x 3 x 2 ) ( x 1 x 8 ), dose there exist a truth assignment T to variables x 1, …,x n (assignment of 0s and 1s to the variables), such that (T) = 1( is satisfiable)? x 1 variable ; x 1, x 3 literal
2004 SDU 9 3SAT vs. CLIQUE A clause is the disjunction of some literals, e.g., x 1 x 3 x 7 A Boolean formula is in conjunctive normal form (CNF in short) if it is in the conjunction ( ) of some clauses. A 3CNF formula is a formula in CNF in which each clause consists of three literals. (x 1 x 3 x 7 ) (x 3 x 2 x 7 ) ( x 1 x 2 x 8 ) 3SAT: Given a 3CNF formula, is it satisfiable? CLIQUE: Given a graph (V, E), and a number k, does G contain a complete sub-graph with at least k vertices? Theorem. 3SAT is polynomial time reducible to CLIQUE.
2004 SDU 10 Proof of theorem Given a formula of k three-literal clauses, construct a graph G = (V, E), where V = {(i, j)| 1 i k, 1 j 3} and E = {((i, j) (i’, j’))| (i i’ and the jth literal in the ith clause and the j’th literal in the i’th clause do not interfere with each other.)} = (x 2 x 1 x 3 ) ( x 1 x 2 x 4 ) (x 2 x 4 x 3 ) x2x2 x1x1 x3 x3 x 1 x 2 x 4 x2x4x3x2x4x3
2004 SDU 11 Proof of theorem(cont’d) Claim. is satisfiable if and only if G has a k-clique. <=Let S be a k-clique of G. Then S has a node from each triple so that the selected nodes do not interfere with each other as assignments. => Let A be a satisfying assignment. Select from each triple a literal that is satisfied by A to construct a set S. |S| = k and it is a clique. The mapping is polynomial time computable.