Presentation is loading. Please wait. # CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.1 Lecture 10-11 NP-Completeness Jan Maluszynski, IDA, 2007

## Presentation on theme: "CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.1 Lecture 10-11 NP-Completeness Jan Maluszynski, IDA, 2007"— Presentation transcript:

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.1 Lecture 10-11 NP-Completeness Jan Maluszynski, IDA, 2007 http://www.ida.liu.se/~janma janma @ ida.liu.se

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.2 Outline Lecture 9-10 : NP-completeness (Sipser 7.4 – 7.5) 1.Motivation P vs. NP 2.NP-complete problems definition & intuition 3.3-SAT 4.Polynomial time reducibility 5.Cook-Levin theorem 6.A survey of NP-complete problems

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.3 The class NP NTIME(t(n)) = {L | L is a language decided by a O(t(n)) time nondeterministic Turing Machine} A language is in NP iff it is decided by a nondeterministic polynomial time Turing Machine A verifier for L is an algorithm (deterministic TM) V: where L = {w | V accepts for some string c} Intuitively c (certificate) gives an evidence that w is in L which can be checked by V. A language is in NP iff it has a polynomial time ( wrt to the size of w) verifier.

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.4 Example of an NP problem. A Hamiltonian path in a directed graph G is a path where every node of G appears exactly once. HAMPATH = { | G is a directed graph with a Hamiltonian path connecting s and t } HAMPATH is in NP: a NTM T constructs pathes of G that at s and have no repeated nodes; T accepts if a constructed path is Hamiltonian. HAMPATH Verifier: on input checks if c is a Hamiltonian path from s to t in G. Can be done in polynomial time on the size of G. Explain how to construct polynomial-time verifier!

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.5 HAMPATH verifier is polynomial Input: G, s, t, c 1. Check if c is a path from s to t in G: PATH is in P 2. Check if c is Hamiltonian; use 2-tape TM: list of nodes in c on tape 1; list of nodes in G on tape 2 For each element x of find x in : reject if x not in or if marked ; otherwise mark x in, O(|n| 2 ) Check if all nodes in are marked O(|n|) runs in O(|n| 2 ) on two-tape TM

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.6 More examples of NP problems A clique in an undirected graph is a subgraph where every two nodes are connected by an edge. CLIQUE ={ |G is a graph with a k nodes clique} A Boolean formula is constructed from variables by using operators:    e.g. (x   y)  (  x  z) A formula is satisfiable iff some assignment of 0’s and 1’s to variables makes it evaluate to 1. SAT = { |  is a satisfiable Boolean formula}

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.7 P vs. NP It is not known if P=NP ? Conjecture: it doesn’t. We know NP  EXPTIME Since nondeterministic polynomial time TM decider T can be transformed to a deterministic TM that explores breadth-first all computation branches of T.

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.8 Polynomial time reducibility Intuition: composition of efficient algorithms is efficient! Having: a polynomial time decider for a language B a polynomial time reduction f of A to B We can decide w  A in polynomial time by 1.Transforming w to f(w) (in polynomial time) 2.Deciding f(w)  B (in polynomial time) Th: If A p.t.r to B and B  P then A  P

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.9 Polynomial time reducibility A function f:  *   * is polynomial time computable if some polynomial time TM M on every input w halts with f(w) on its tape Language A is polynomial time mapping reducible to B written A  P B if there is a computable function f s.that for every w w  A  f(w)  B f is called polynomial time reduction of A to B.

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.10 Polynomial-time reduction: example 3-cnf formulae: Literal: x or  x, where x is a variable Clause: disjunction of literals eg. (x  y   z) Cnf- formula: conjunction of clauses eg. (x  y   z)  (z   x) 3-cnf formula: each clause has 3 literals 3SAT problem: satisfiability of 3-cnf formulae. Theorem: 3SAT is polynomial-time reducible to CLIQUE Proof: construction of a graph with nodes corresponding to the literals of a 3-cnf formula

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.11 Definition of NP-completeness A language B is NP-complete iff: B is in NP Every language A in NP is polynomial time reducible to B Intution: most time-consuming problems in NP. If B is NP-complete and B is in P, then P=NP. If B is NP-complete, C is NP, and B is polynomial time reducible to C then C is NP-complete

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.12 Proving a language to be NP-complete How to prove that an NP language B is NP-complete: Directly from definition (difficult: all NP-languages are to be considered) Knowing one NP-complete language A find a polynomial time reduction from A to B. Find one NP-complete problem!!!

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.13 Cook-Levin Theorem Cook-Levin Theorem: SAT is NP-complete. Proof idea (p.281). For any string in NP language there is an accepting polynomial-time computation. Represent it as a tableau. The tableau can be characterized by a satisfiable Boolean formula (also by 3cnf-formula). Corollary: 3SAT is NP-complete

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.14 More examples of NP-complete problems 3SAT proved directly CLIQUE: existence of a clique of size k in a given graph, proved by reduction from 3SAT VERTEX-COVER (p.288): existence of a set C of k nodes in a graph s.that every edge has a node in C, proved by reduction from 3SAT HAMPATH existence of a Hamiltonian path in a directed graph, proved by reduction from 3SAT UHAMPATH existence of a Hamiltonian path in an undirected graph, reduction from HAMPATH SUBSET-SUM given a set of integers is there a subset whose sum equals a given number

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.15 Importance of time-complexity analysis Polynomial-time complexity preserved by realistic models of computations. P is a class of problems that can be realistically solved on a computer. The notion of NP-completeness based on P; relevant for practical computing.

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.16 Importance of time-complexity analysis The notion of NP-completeness identifies computationally expensive problems. Many of them appear in practice e.g. scheduling and resource allocation problems. NP-completeness of a problem shows that no algorithm will behave well in worst case; for some data an algorithm may still be efficient.

Download ppt "CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 200710.1 Lecture 10-11 NP-Completeness Jan Maluszynski, IDA, 2007"

Similar presentations

Ads by Google