Announcements. Problem Set 7 graded; will be returned at end of lecture. Unclaimed problem sets and midterms moved!

Similar documents
Complexity Theory Part II

Friday Four Square! Today at 4:15PM, Outside Gates

Recap from Last Time

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

Lecture 16: Time Complexity and P vs NP

Turing Machines Part III

NP, polynomial-time mapping reductions, and NP-completeness

Complexity Theory Part I

Finish K-Complexity, Start Time Complexity

Decidability and Undecidability

CS154, Lecture 13: P vs NP

Lecture 3: Nondeterminism, NP, and NP-completeness

Computational complexity

CS154, Lecture 13: P vs NP

CSE 105 THEORY OF COMPUTATION

1 Computational Problems

Turing Machines Part II

Notes for Lecture Notes 2

Complexity. Complexity Theory Lecture 3. Decidability and Complexity. Complexity Classes

CSE 105 THEORY OF COMPUTATION

Computability and Complexity CISC462, Fall 2018, Space complexity 1

CSCE 551 Final Exam, Spring 2004 Answer Key

Complexity Theory Part I

Intro to Theory of Computation

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

BBM402-Lecture 11: The Class NP

CP405 Theory of Computation

CISC 4090 Theory of Computation

ECS 120 Lesson 24 The Class N P, N P-complete Problems

CSCI3390-Lecture 14: The class NP

1 Non-deterministic Turing Machine

Computational Models Lecture 11, Spring 2009

Chapter 7: Time Complexity

Advanced Topics in Theoretical Computer Science

Chap. 4,5 Review. Algorithms created in proofs from prior chapters

CSE 105 THEORY OF COMPUTATION

Recap from Last Time

Harvard CS 121 and CSCI E-121 Lecture 20: Polynomial Time

Computational Models Lecture 8 1

Theory of Computation

Computability and Complexity

COP 4531 Complexity & Analysis of Data Structures & Algorithms

6.045: Automata, Computability, and Complexity (GITCS) Class 15 Nancy Lynch

Intractable Problems [HMU06,Chp.10a]

Class Note #20. In today s class, the following four concepts were introduced: decision

Computational Complexity

Turing Machines Part II

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

P = k T IME(n k ) Now, do all decidable languages belong to P? Let s consider a couple of languages:

Complexity Theory Part Two

CSE 105 Theory of Computation

Mapping Reducibility. Human-aware Robotics. 2017/11/16 Chapter 5.3 in Sipser Ø Announcement:

Complexity Theory Part One

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Computational Models Lecture 8 1

NP-Completeness Part I

ACS2: Decidability Decidability

CSE 105 THEORY OF COMPUTATION

CSCI3390-Lecture 16: NP-completeness

CSE 135: Introduction to Theory of Computation NP-completeness

Time Complexity (1) CSCI Spring Original Slides were written by Dr. Frederick W Maier. CSCI 2670 Time Complexity (1)

UNIT-VIII COMPUTABILITY THEORY

Computational Models Lecture 8 1

Lecture 17: Cook-Levin Theorem, NP-Complete Problems

Algorithms and Theory of Computation. Lecture 19: Class P and NP, Reduction

CSE 105 THEORY OF COMPUTATION

Lecture 2 (Notes) 1. The book Computational Complexity: A Modern Approach by Sanjeev Arora and Boaz Barak;

An example of a decidable language that is not a CFL Implementation-level description of a TM State diagram of TM

CS151 Complexity Theory. Lecture 1 April 3, 2017

Intro to Theory of Computation

15-251: Great Theoretical Ideas in Computer Science Lecture 7. Turing s Legacy Continues

Problems, and How Computer Scientists Solve Them Manas Thakur

CPSC 421: Tutorial #1

Computability and Complexity

1 Computational problems

Decidability. Human-aware Robotics. 2017/10/31 Chapter 4.1 in Sipser Ø Announcement:

CS5371 Theory of Computation. Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)

TIME COMPLEXITY AND POLYNOMIAL TIME; NON DETERMINISTIC TURING MACHINES AND NP. THURSDAY Mar 20

The Class NP. NP is the problems that can be solved in polynomial time by a nondeterministic machine.

Exam Computability and Complexity

Essential facts about NP-completeness:

Notes on Complexity Theory Last updated: December, Lecture 2

Complexity Theory 112. Space Complexity

COSE215: Theory of Computation. Lecture 20 P, NP, and NP-Complete Problems

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Lecture 21: Space Complexity (The Final Exam Frontier?)

CS21 Decidability and Tractability

Theory of Computation Time Complexity

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

satisfiability (sat) Satisfiability unsatisfiability (unsat or sat complement) and validity Any Expression φ Can Be Converted into CNFs and DNFs

Time Complexity. CS60001: Foundations of Computing Science

CS154, Lecture 17: conp, Oracles again, Space Complexity

Algorithms Design & Analysis. Approximation Algorithm

NP and NP Completeness

A An Overview of Complexity Theory for the Algorithm Designer

Space Complexity. then the space required by M on input x is. w i u i. F ) on. September 27, i=1

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

Transcription:

N P NP

Announcements Problem Set 7 graded; will be returned at end of lecture. Unclaimed problem sets and midterms moved! Now in cabinets in the Gates open area near the drop-off box.

The Complexity Class P The complexity class P (polynomial time) contains all problems that can be solved in polynomial time. Formally: P = TIME(n k ) k = 0 The Cobham-Edmonds Thesis: A decision problem can be solved efficiently iff it is in P.

Examples of Problems in P All regular languages are in P. Belong to TIME(n). All DCFLs are in P. Belong to TIME(n2 ). All CFLs are in P. Belong to TIME(n 18 ). Many other problems are in P: POWER2 SEARCH

Regular Languages DCFLs CFLs P R Undecidable Languages

Proving Languages are in P Directly prove the language is in P. Build a decider for the language L. Prove that the decider runs in time O(nk ). Use closure properties. Prove that the language can be formed by appropriate transformations of languages in P. Reduce the language to a language in P. Show how a polynomial-time decider for some language L' can be used to decide L.

Polynomial-Time Reductions Let A Σ 1 * and B Σ 2 * be languages. A polynomial-time reduction is a function f : Σ 1 * Σ 2 * with the following properties: f(w) can be computed in polynomial time. w A iff f(w) B. Notation: A P B. Informally: A way of turning inputs to A into inputs to B that can be computed in polynomial time that preserves the correct answer.

Polynomial-Time Reductions Suppose that we know that B P. Suppose that A P B. Then A P as well. Input size: n Time required: O(n k ) Input size: O(n k ) A Solvable in O(n kr ) A reduces to B B decides A Time required: O(n kr ) B Solvable in O(n r )

Theorem: If B P and A P B, then A P. Proof: Let H be a polynomial-time decider for B. Consider the following TM: M = On input w: Compute f(w). Run H on f(w). If H accepts, accept; if H rejects, reject. We claim that M is a polynomial-time decider for A. To see this, we prove that M is a polynomial-time decider, then that L(M) = A. To see that M is a polynomial-time decider, note that because f is a polynomial-time reduction, computing f(w) takes time O(n k ) for some k. Moreover, because computing f(w) takes time O(n k ), we know that f(w) = O(n k ). M then runs H on f(w). Since H is a polynomial-time decider, H halts in O(m r ) on an input of size m for some r. Since f(w) = O(n k ), H halts after O( f(w) r ) = O(n kr ) steps. Thus M halts after O(n k + n kr ) steps, so M is a polynomial-time decider. To see that L( M) = A, note that M accepts w iff H accepts f(w) iff f(w) A. Since f is a polynomial-time reduction, f(w) B iff w A. Thus M accepts w iff w A, so L( M) = A.

A Sample Reduction

Maximum Matching Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint. A maximum matching is a matching with the largest number of edges.

Maximum Matching Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint. A maximum matching is a matching with the largest number of edges. A maximum maximum matching. matching.

Maximum Matching Jack Edmonds' paper Paths, Trees, and Flowers that describes a polynomialtime algorithm for finding maximum matchings. (This is the same Edmonds as in Cobham- Edmonds Thesis.) Using this fact, what other problems can we solve?

Domino Tiling

A Domino Tiling Reduction Let MATCHING be the language defined as follows: MATCHING = { G, k G is an undirected graph with a matching of size at least k } Theorem (Edmonds): MATCHING P. Let DOMINO be this language: DOMINO = { D, k D is a grid and k nonoverlapping dominoes can be placed on D. } We'll prove DOMINO P MATCHING to show that DOMINO P.

Solving Domino Tiling

Solving Domino Tiling

Solving Domino Tiling

Solving Domino Tiling

Solving Domino Tiling

Solving Domino Tiling

Solving Domino Tiling

Solving Domino Tiling

Our Reduction Given as input D, k, construct the graph G as follows: For each empty cell x i, construct a node v i. For each pair of adjacent empty cells x i and x j, construct an edge (v i, v j ) Let f( D, k ) = G, k.

A Polynomial-Time Reduction To prove that f is a polynomial-time reduction, we will show that the size of f(w) is a polynomial in the size of w. Technically, this is not sufficient to prove that f runs in polynomial time. However, most reductions that construct a polynomially-large object take polynomial time. We will gloss over the fact that the polynomialsize object can be constructed in polynomial time; barring very unusual reductions, this is almost always true.

A Polynomial-Time Reduction Given a grid D and a number k, how large is the constructed graph G? One node per empty cell in D. One edge per pair of adjacent empty cells in D. There are O( D ) empty cells in D. Each empty cell may have up to four neighbors. So there are at most O( D ) constructed edges. Each node and edge can be built in polynomial time, so the overall reduction takes polynomial time.

Lemma: f is computable in polynomial time. Proof: We show that f( D, k ) = G, k has size that is a polynomial in the size of D, k. For each empty cell x i in D, we construct a single node v i in G. Since there are O( D ) cells, there are O( D ) nodes in the graph. For each pair of adjacent, empty cells x i and x j in D, we add the edge (x i, x j ). Since each cell in D has four neighbors, the maximum number of edges we could add this way is O( D ) as well. Thus the total size of the graph G is O( D ). Consequently, the total size of G, k is O( D + k ), which is a polynomial in the size of the input. Since each part of the graph could be constructed in polynomial time, the overall graph can be constructed in polynomial time.

Summary of P P is the complexity class of yes/no questions that can be solved in polynomial time. P is closed under polynomial-time reductions.

What can't you do in polynomial time?

start end How How many many simple paths paths are are there there from from the the start start node node to to the the end end node?

1, 2, 3, 4, 5, 6, 7, 8 How How many many subsets of of this this set set are are there?

1 2 3 4 5 6 7 8 How How many many binary search trees trees can can you you form form from from these these numbers?

An Interesting Observation There are (at least) exponentially many objects of each of the preceding types. However, each of those objects is not very large. Each simple path has length no longer than the number of nodes in the graph. Each subset of a set has no more elements than the original set. Each binary search tree made from some elements has exactly one node per element. This brings us to our next topic...

N P NP

NTMs A nondeterministic Turing machine (NTM) is a generalization of the Turing machine. An NTM may have multiple transitions defined for a given state/symbol combination. The NTM accepts if any choice of transitions enters an accepting state. The NTM rejects if all choices of transitions enter a rejecting state. Otherwise, the NTM loops.

Nondeterminism Revisited If we add nondeterminism to the DFA, we get the NFA. NFAs are no more powerful than DFAs. If we add nondeterminism to the DPDA, we get the PDA. PDAs are more powerful than DPDAs. Adding nondeterminism to a TM produces the equivalently powerful NTM. NTMs are no more powerful than TMs.

Nondeterminism Revisited Converting an NFA to a DFA might introduce exponentially more space. It is sometimes impossible to convert an NPDA to a DPDA. Converting an NTM to a TM might dramatically slow down the TM.

Designing NTMs Nondeterminism is a very powerful tool for solving problems. Many problems can be solved simply with nondeterminism using the following template: Nondeterministically guess some important piece of information. Deterministically check that the guess was correct.

Nondeterministic Algorithms Recall: a number n > 1 is composite if it is not prime. Let Σ = { 1 } and consider the language COMPOSITE = { 1 n n is composite } We can build a multitape, nondeterministic TM for COMPOSITE as follows: M = On input 1 n : Nondeterministically write out q 1s on a second tape (2 q < n) Nondeterministically write out r 1s on a third tape (2 r < n) Deterministically check if qr = n. If so, accept. Otherwise, reject

Analyzing NTMs When discussing deterministic TMs, the notion of time complexity is (reasonably) straightforward. Recall: One way of thinking about nondeterminism is as a tree. In a deterministic computation, the tree is a straight line. The time complexity is the height of that straight line.

Analyzing NTMs When discussing deterministic TMs, the notion of time complexity is (reasonably) straightforward. Recall: One way of thinking about nondeterminism is as a tree. The time complexity is the height of the tree (the length of the longest possible choice we could make).

Analyzing NTMs M = On input 1n : Nondeterministically write out q 1s on a second tape (2 q < n) Nondeterministically write out r 1s on a third tape (2 r < n) Deterministically check if qr = n. If so, accept. Otherwise, reject + O(n) steps O(n) steps O(n 2 ) steps O(1) steps O(n 2 ) steps

Analyzing NTMs Our multitape NTM can decide COMPOSITE in time O(n 2 ). Using a similar construction to the deterministic case, a single-tape NTM can decide COMPOSITE in O(n 4 ). The best known deterministic algorithm for deciding COMPOSITE runs much more slowly. Runs in time around O(n8 ). Just how much more powerful are NTMs?

From NTMs to TMs NTMs are at least as powerful as TMs. Just don't use any nondeterminism! TMs are at least as powerful as NTMs. Idea: Simulate the NTM with a multitape TM. Run a breadth-first search on possible options. 0 q 0 1 1 0 Work Tape q 0 0 1 0 # 1 1 q 2 0 0 # q 4 0 1 Configuration Tape

From NTMs to TMs

From NTMs to TMs Theorem: For any NTM with time complexity f(n), there is a TM with time complexity 2 O(f(n)). It is unknown whether it is possible to do any better than this in the general case. NTMs are capable of exploring multiple options in parallel; this seems inherently faster than deterministic computation.

TIME and NTIME Recall: TIME(f(n)) is the class of languages that can be decided in O(f(n)) time by a single-tape TM. NTIME(f(n)) is the class of languages that can be decided in O(f(n)) time by a singletape NTM. All possible options terminate in O(f(n)) steps. For any f(n), TIME(f(n)) NTIME(f(n)). Can always convert a TM to an NTM.

The Complexity Class NP The complexity class NP (nondeterministic polynomial time) contains all problems that can be solved in polynomial time by a single-tape NTM. Formally: NP = NTIME(n k ) k = 0 What types of problems are in NP?

A Problem in NP Does a Sudoku grid have a solution? M = On input S, an encoding of a Sudoku puzzle: Nondeterministically guess how to fill in all the squares. Deterministically check whether the guess is correct. If so, accept; if not, reject. 2 4 3 6 7 8 1 5 9 5 9 8 4 1 3 6 7 2 7 1 6 5 9 2 3 8 4 9 8 1 7 5 6 2 4 3 6 7 2 3 4 1 5 9 8 4 3 5 2 8 9 7 6 1 1 6 9 8 3 5 4 2 7 8 5 4 1 2 7 9 3 6 3 2 7 9 6 4 8 1 5 If we allow for a generalized Sudoku board of arbitrary size: There are polynomially many grid cells to fill in. Checking the grid takes polynomial time. Overall algorithm takes polynomial time.

A Problem in NP A graph coloring is a way of assigning colors to nodes in an undirected graph such that no two nodes joined by an edge have the same color. Applications in compilers, cell phone towers, etc. Question: Can graph G be colored with at most k colors? M = On input G, k : Nondeterministically guess a k-coloring of the nodes of G. Deterministically check whether it is legal. If so, accept; if not, reject.

A Problem in NP Suppose you want to start a delivery service. You want to place depots such that each customer is within some distance of the depot. Given a set of candidate locations for depots, can you place k depots and guarantee that each customer is covered? M = On input D, C, δ, k (depot locations, customer locations, minimum distance required, and number of depots desired): Nondeterministically guess k depots from D. Deterministically verify each c C is within δ distance of some depot. If so, accept; otherwise reject.

A General Pattern The NTMs we have seen so far always follow this pattern: M = On input w: Nondeterministically guess some string x. Deterministically check whether x solves w. If so, accept; otherwise, reject. Is there a different way of characterizing NP?

Polynomial-Time Verifiers A polynomial-time verifier is a deterministic TM of the form M = On input w, x : Deterministically check whether x solves w. If so, accept; otherwise, reject. such that M runs in time polynomial in the length of w (not the length of x). The string x is called a certificate or a witness for w.

An Efficiently Verifiable Puzzle Question: Can this lock be opened?

Verifiers, Formally Formally, a verifier is a TM V such that w L iff x Σ*. V accepts w, x In other words L = { w Σ* x Σ*. V accepts w, x } If w L, the verifier can check this easily if we know the proper x. If w L, the verifier does not help much. Just because V rejects w, x does not mean that w L. Note that L(V) L.

Verification is Powerful Many undecidable languages can still be verified. Here is a verifier for HALT: V = On input M, w, n, where M is a TM, w is a string, and n is a natural number: Run M on w for n steps. If M halts w within that time, accept; otherwise reject. V always halts on all inputs (even if M loops on w). If M halts on w, there is some choice of n for which V accepts (namely, the number of steps M takes before it halts on w). Thus HALT can be verified but not decided.

A Problem in NP Does a Sudoku grid have a solution? M = On input S, A, an encoding of a Sudoku puzzle and an alleged solution to it: Deterministically check whether A is a solution to S. If so, accept; if not, reject. 3 6 8 1 5 1 7 7 5 2 3 4 1 2 4 6 3 1 8 3 5 7 1 9 8 5 7 5 2 2 7 9 4 8

A Problem in NP A graph coloring is a way of assigning colors to nodes in an undirected graph such that no two nodes joined by an edge have the same color. Applications in compilers, cell phone towers, etc. Question: Can graph G be colored with at most k colors? M = On input G, k, C, where C is an alleged coloring: Deterministically check whether C is a legal k-coloring of G. If so, accept; if not, reject.

Two Equivalent Formulations of NP Theorem: A language L has a polynomial-time verifier iff L NP. Proof sketch: Any polynomial-time verifier can be turned into a polynomial-time NTM by having the NTM nondeterministically guess the certificate for w, then check it (deterministically) by running the verifier. If an NTM can decide L in polynomial time, a verifier could work by having a certificate saying which nondeterministic choices the original NTM made, then simulating those choices of the NTM to check it.

Next Time NP-Completeness What are the hardest problems in NP? How do you prove a problem is NPcomplete?