CS Master Introduction to the Theory of Computation

  • Slides: 16
Download presentation
CS Master – Introduction to the Theory of Computation Lecture 10 -11 NP-Completeness Jan

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

CS Master – Introduction to the Theory of Computation Outline Lecture 9 -10 :

CS Master – Introduction to the Theory of Computation 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 Jan Maluszynski - HT 2007 2

CS Master – Introduction to the Theory of Computation The class NP NTIME(t(n)) =

CS Master – Introduction to the Theory of Computation 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 <w, c> 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. Jan Maluszynski - HT 2007 3

CS Master – Introduction to the Theory of Computation Example of an NP problem.

CS Master – Introduction to the Theory of Computation 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, s, t> | 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 <G, s, t, c> 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! Jan Maluszynski - HT 2007 4

CS Master – Introduction to the Theory of Computation HAMPATH verifier is polynomial Input:

CS Master – Introduction to the Theory of Computation 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: <c> list of nodes in c on tape 1; <n> list of nodes in G on tape 2 • For each element x of <c> find x in <n>: reject if x not in <n> or if marked ; otherwise mark x in <n>, O(|n|2) • Check if all nodes in <n> are marked O(|n|) runs in O(|n|2) on two-tape TM Jan Maluszynski - HT 2007 5

CS Master – Introduction to the Theory of Computation More examples of NP problems

CS Master – Introduction to the Theory of Computation 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, k>|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} Jan Maluszynski - HT 2007 6

CS Master – Introduction to the Theory of Computation P vs. NP It is

CS Master – Introduction to the Theory of Computation 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. Jan Maluszynski - HT 2007 7

CS Master – Introduction to the Theory of Computation Polynomial time reducibility Intuition: composition

CS Master – Introduction to the Theory of Computation 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 Jan Maluszynski - HT 2007 8

CS Master – Introduction to the Theory of Computation Polynomial time reducibility A function

CS Master – Introduction to the Theory of Computation 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 PB 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. Jan Maluszynski - HT 2007 9

CS Master – Introduction to the Theory of Computation Polynomial-time reduction: example 3 -cnf

CS Master – Introduction to the Theory of Computation 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 3 SAT problem: satisfiability of 3 -cnf formulae. Theorem: 3 SAT is polynomial-time reducible to CLIQUE Proof: construction of a graph with nodes corresponding to the literals of a 3 -cnf formula Jan Maluszynski - HT 2007 10

CS Master – Introduction to the Theory of Computation Definition of NP-completeness A language

CS Master – Introduction to the Theory of Computation 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 Jan Maluszynski - HT 2007 11

CS Master – Introduction to the Theory of Computation Proving a language to be

CS Master – Introduction to the Theory of Computation 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!!! Jan Maluszynski - HT 2007 12

CS Master – Introduction to the Theory of Computation Cook-Levin Theorem: SAT is NP-complete.

CS Master – Introduction to the Theory of Computation 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 3 cnf-formula). Corollary: 3 SAT is NP-complete Jan Maluszynski - HT 2007 13

CS Master – Introduction to the Theory of Computation More examples of NP-complete problems

CS Master – Introduction to the Theory of Computation More examples of NP-complete problems • 3 SAT proved directly • CLIQUE: existence of a clique of size k in a given graph, proved by reduction from 3 SAT • 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 3 SAT • HAMPATH existence of a Hamiltonian path in a directed graph, proved by reduction from 3 SAT • 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 Jan Maluszynski - HT 2007 14

CS Master – Introduction to the Theory of Computation Importance of time-complexity analysis •

CS Master – Introduction to the Theory of Computation 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. Jan Maluszynski - HT 2007 15

CS Master – Introduction to the Theory of Computation Importance of time-complexity analysis •

CS Master – Introduction to the Theory of Computation 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. Jan Maluszynski - HT 2007 16