CSCI3390-Lecture 14: The class NP

Similar documents
Computational complexity

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

CSCI3390-Lecture 16: NP-completeness

BBM402-Lecture 11: The Class NP

Advanced topic: Space complexity

Notes for Lecture Notes 2

1 Computational Problems

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

NP-Completeness. Until now we have been designing algorithms for specific problems

SOLUTION: SOLUTION: SOLUTION:

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

CS151 Complexity Theory. Lecture 1 April 3, 2017

Data Structures in Java

Week 2: Defining Computation

Complexity Theory Part II

CMSC 441: Algorithms. NP Completeness

Decidability and Undecidability

CSCE 551 Final Exam, Spring 2004 Answer Key

CSCI3390-Second Test with Solutions

Umans Complexity Theory Lectures

Lecture 20: conp and Friends, Oracles in Complexity Theory

CSCI3390-Lecture 18: Why is the P =?NP Problem Such a Big Deal?

Intro to Theory of Computation

The purpose here is to classify computational problems according to their complexity. For that purpose we need first to agree on a computational

Computer Sciences Department

CSC 5170: Theory of Computational Complexity Lecture 9 The Chinese University of Hong Kong 15 March 2010

Computational Complexity

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

CSE200: Computability and complexity Space Complexity

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

Lecture 18: P & NP. Revised, May 1, CLRS, pp

Boolean circuits. Lecture Definitions

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

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

Lecture 24: Randomized Complexity, Course Summary

Lecture 8: Complete Problems for Other Complexity Classes

6.045 Final Exam Solutions

Lecture 3: Nondeterminism, NP, and NP-completeness

UNIT-VIII COMPUTABILITY THEORY

About the relationship between formal logic and complexity classes

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

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

Lecture 4 : Quest for Structure in Counting Problems

CS154, Lecture 10: Rice s Theorem, Oracle Machines

1 Computational problems

Limitations of Algorithm Power

Space Complexity. The space complexity of a program is how much memory it uses.

Comparison of several polynomial and exponential time complexity functions. Size n

Design and Analysis of Algorithms

Time-bounded computations

Theory of Computation

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

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

P and NP. Or, how to make $1,000,000.

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

} } } Lecture 23: Computational Complexity. Lecture Overview. Definitions: EXP R. uncomputable/ undecidable P C EXP C R = = Examples

Computability and Complexity CISC462, Fall 2018, Space complexity 1

Introduction to Languages and Computation

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

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

Introduction to Complexity Theory

Lecture Notes: The Halting Problem; Reductions

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

Asymptotic notation : big-o and small-o

V Honors Theory of Computation

Lecture 22: Counting

Lecture 25: Cook s Theorem (1997) Steven Skiena. skiena

CS5371 Theory of Computation. Lecture 18: Complexity III (Two Classes: P and NP)

A An Overview of Complexity Theory for the Algorithm Designer

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

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Complexity (Pre Lecture)

Computational Models Lecture 11, Spring 2009

Complexity Theory. Knowledge Representation and Reasoning. November 2, 2005

Announcements. Problem Set 6 due next Monday, February 25, at 12:50PM. Midterm graded, will be returned at end of lecture.

CS154, Lecture 13: P vs NP

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Computability Theory

Turing Machines and Time Complexity

Lecture 14 - P v.s. NP 1

Turing Machines Part III

6-1 Computational Complexity

Lecture 22: Quantum computational complexity

Theory of Computation

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

On the Computational Hardness of Graph Coloring

Computational Models Lecture 8 1

CSC 5170: Theory of Computational Complexity Lecture 4 The Chinese University of Hong Kong 1 February 2010

Turing Machines Part II

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

1 Non-deterministic Turing Machine

NP-Completeness. Sections 28.5, 28.6

Lecture Notes 4. Issued 8 March 2018

Computational Complexity

Computational Models Lecture 8 1

CpSc 421 Homework 9 Solution

Transcription:

CSCI3390-Lecture 14: The class NP 1 Problems and Witnesses All of the decision problems described below have the form: Is there a solution to X? where X is the given problem instance. If the instance is a Yes instance of the problem, then a solution is called a witness to this fact. 1.1 Example: Sudoku The pair of grids in the figure below (which you have seen before) is an instance of the following decision problem: The grid on the left is an instance of this problem: Input: A partially filled-in Sudoku grid. Output: Yes if a solution exists, no otherwise. It happens that the grid on the left is a Yes instance of this problem, and the grid on the right is a witness to this fact. 1.2 Hamiltonian circuit This problem is Input: A graph. Output: Yes if a there is a path, starting and ending at the same vertex, that passes through every vertex of the graph exactly once. No otherwise. An instance of this problem is shown in Figure 2. This is a Yes instance, and a witness to this is the sequence of vertices 1, 2, 5, 6, 4, 3, 1. Observe that there are several different witnesses possible. For this graph, there is, in a sense, only one Hamiltonian circuit, but we can choose any vertex for the start and end point, and make the tour in either of two directions. 1

Figure 1: The pair of grids is an instance of the polynomial-time verifier problem for Sudoku Figure 2: Does this graph have a Hamiltonian circuit? 2

1.3 Graph k-coloring Each value of k gives a different problem: Input: A graph. Output: Yes if a there a way to assign a color to each of the vertices of the graph, so that k or fewer colors are used, and so that adjacent vertices are not assigned the same color. No otherwise. Consider again the graph in Figure 1. If k = 2 this is a No instance, but if k = 3, the assignment: 1 : green, 2 : blue, 3 : blue, 4 : green, 5 : red, 6 : blue is a witness, representing a legal coloring. Observe there are many different ways to legally color this graph with three colors. 1.4 Compositeness Input: An integer n given in binary. Output: Yes if there is an integer m < n such that m n. No otherwise. A witness is a pair of integers m, k such that n = mk and m < n. 1.5 Rush Hour A problem we ve seen before: Input: A setup of cars on an N N Rush Hour grid. Output: Yes if there is a sequence of moves that gets the red car out of the grid. No otherwise. Figures 3 and 4 below show a particularly difficult Yes instance and its solution on a 6 6 board. 1.6 Theoremhood We ve seen this before. Input: A sentence φ of arithmetic. Output: Yes if φ is a theorem. No otherwise. A witness to a Yes instance, of course, is a proof of φ. 3

Figure 3: Can this Rush Hour puzzle be solved? Figure 4: An optimal 50-move solution to the puzzle in the preceding figure. The symbols R,L,U,D mean right, left up and down, and each instruction includes the number of cells to slide the image. 4

2 NP Problems All six problems described above share a common feature concerning the ease of verifying a witness, and the first four share another feature concerning the size of witnesses. The two features together define the class of decision problems called NP. 2.1 Easy verification... As we saw in the last lecture, if I give you the original Sudoku puzzle and the proposed solution, then the algorithm for verifying that it is indeed a solution runs in time polynomial in the size of the problem. This reflects the observed fact that you can verify at a glance that a Sudoku grid has been filled in correctly. Much the same observation holds for the Hamiltonian circuit problem. If I give you a specification of the graph and a list of vertices, you can verify it as follows: create a checklist of all the vertices in the graph check off the first vertex s in the list for each subsequent vertex v in the list: if v is not connected by an edge to the preceding vertex, reject else: check v off if v is already checked off: if v==s and all vertices have been checked off: accept else: reject reject The number of passes through the loop is no more than the length of the list, which in turn must be equal to the number n of vertices in the graph. Each pass requires checking the graph representation to see if a pair of vertices is an edge, and locating a vertex in the check list. The exact step count depends on how we represent the graph, but in any case there will require O(n) steps. This more detailed analysis again reflects a simple observation: If I give you the list of vertices and the graph, it is an easy matter to scan through the list and verify that it is a Hamiltonian circuit. 5

An identical observation holds for the k-coloring problem. For a relatively small graph, you can spot adjacent vertices with the same color at a glance. A careful algorithm takes time O(n 2 ) on a graph with n vertices. For compositeness, we only need to multiply together the two numbers m, k in the witness. Observe that the size of the witness is the number of bits in the representation of the two numbers (and not the values m and k themselves). Multiplication, done the usual way, takes time proportional to the square of the number of bits. For Rush Hour, once again we have a straightforward algorithm for verifying the solution we can just take that card with the solutions moves written on it, grab our Rush Hour game, and move the cars around, following the script, and checking that the red car does indeed exit the grid. A computer implementation requires time linear in the length of the script, although this again might depend on implementation details (but see below!). To verify a proof, we need to check that each line is either an axiom, or follows from a previous line or lines by a rule of inference. The exact details depend on the axiomatic system, but typically this will be O(n 2 ) where n is the length of the proof, reflecting the intuition that proofs ought to be easy to verify. 2.2 Short witnesses... While all six problems discussed above share the easy to verify property, there is a stark difference between the first four examples and the last two: In the first four cases, the size of the witness was itself comparable to the size of the input. On the other hand, in sliding-block puzzles like Rush Hour, it is possible that the length of a solution is exponential in the size of the board. For theoremhood, we can t even guarantee that the length of a proof of φ is bounded by an exponential function, or any computable function, in the length of the sentence: if this were the case, we could in principle survey all possible proofs up to this bound, and decide whether a sentence is a theorem. But we have already seen that this is an undecidable problem. So we are interested in decision problems that can be settled by verifying a witness, subject to these constraints. The size of the witness is polynomial in the size of the problem instance. That is, there is a positive integer k such that every guess has length O(n k ) for inputs of length n. 6

The verification algorithm runs in time polynomial in the length of the witness. The two properties together imply that the verification algorithm also runs in time polynomial in the length of the input. This class of decision problems is called NP. 2.3 Formal definition of NP What follows is a more formal definition. It takes a bit of gymnastics to write it down completely correctly. To properly understand the concept you should think about the examples above A language L Σ is in NP if there exist a positive integer k, and a language L Σ, such that L P w L if and only if there exists v Σ with v w k, and w#v L. In this definition v is the witness, and L is the problem of determining whether v is a solution to w. Let s observe a few things about this definition. First of all P NP, because if L P, we can just take L = L and v to be the empty string, so L satisfies the definition of languages in NP. Second, every language in NP is decidable by the brute-force algorithm: Given an input w of length n, generate every string v of length no more than n k, and test if w#v L. This requires Σ nk calls to the polynomial-time verifier algorithm. 3 What does the N stand for? NP stands for nondeterministic polynomial time. This refers to another, equivalent way of defining this complexity class. 3.1 Nondeterministic computation Imagine a conventional procedural programming language, supplemented with a kind of fantasy control structure: an either...or statement: 7

either: <sequence S of statments> or: <sequence T of statements> Conventional programs compute deterministically: Run the same program twice on the same inputs, and it will do exactly the same thing. The either...or statement causes the program to compute nondeterministically. The same program run twice on the same inputs will in general give different results, depending on which branch of code it decides to execute. Here is an example of a function written in this fantasy language that determines whether a graph G is 3-colorable. The function calls the easy verification algorithm described earlier as a subroutine: def three_colorable(g): for each vertex v in G: either: color v red or: color v green or: color v blue #verify the coloring: if the coloring is legal: return True else: return False Each run of the function requires time polynomial in the size of the graph we have already observed that this is true for the verification algorithm called at the end, and the guessing phase at the beginning takes time proportional to the number of vertices in the graph. What is different is the way in which this peculiar program solves the problem of determining 3-colorability: If there is some sequence of choices that leads to the function returning True, then the graph is 3-colorable. To turn this into a normal deterministic computation, we would have to try out all 3 n possible choices, where n is the number of vertices. So here is an alternative, equivalent, definition of NP: It consists of those decision problems solved by a boolean-valued either-or function that runs in polynomial time on every input. 8

3.2 A Turing machine version... In order to prove things about NP problems, we will require a more concrete model. Once again, we turn to Turing machines: Suppose you took a list of quintuples (q, σ, q, γ, D) that we ordinarily associate with the transitions of a Turing machine. Does every such list actually define a TM? The answer is no, because it might contain two different quintuples with the same first two components (q, σ), and thus the action of the machine when the current state is q and the currently scanned tape symbol is σ would not be determined. In a nondeterministic Turing machine (NDTM), such duplication is allowed. Formally, the transition function is δ : (Q {accept, reject) Γ P(Q Γ {L, R}). If the machine is in a particular configuration, there may be several configurations that can follow it. Thus the computation of the machine from a given starting position is not a sequence of configurations, but a tree of configurations. It is exactly ike the programming language with an either-or statement: each time this is encountered, the program can decide which branch to follow. We say that the NDTM accepts its input, if there is some path from the root of the tree that is, some sequence of guesses that leads to the accept state. A polynomial-time NDTM has the additional property that for some integer k > 0, every path from the root leads to either acceptance or rejection in O(n k ) steps, where n is the length of the original input. 3.3...and another. Here is another, equivalent, model of a polynomial-time NDTM: At the start of the computation, on input w, the machine goes through a guessing phase, during which it writes w k additional symbols on the tape, changing the tape contents to w#v. After that, the machine computes deterministically in polynomial time, like an ordinary polynomial-time Turing machine. The machine accepts w if there is some word v that leads to acceptance in the deterministic mode. This is just our guess-and-verify process that we described originally. It s not too hard to show that this is equivalent to the model we described above what we are doing is 9

Figure 5: Is this the right picture of the language classes we ve studied? pre-loading all of our guesses at the outset, instead of making them whenever a decision is required. In either version of the NDTM, another equivalent definition of NP is: L NP if and only if there is a polynomial-time NDTM that accepts exactly the strings in L. 4 A picture of the world of computational problems We have classified decision problems (=languages) according to their computational difficulty. We know that every problem in P is in NP, that every problem in NP is decidable and that every decidable problem is Turing-recognizable. So our picture looks like Figure 2. But are these inclusions strict? That is, are any of the colored regions actually empty? We know that the Turing-recognizable languages do not constitute all languages. (Because, for instance, the language {< M, w >: Mdoes not accept w} is not Turing-recognizable.) And the language {< M, w >: Maccepts w} 10

Figure 6:..or is this? is a Turing-recognizable language that is not decidable. It is a little harder to separate NP from the decidable languages, but it is known that this inclusion is also strict. What about the inclusion P NP? The question of whether this inclusion is strict or not is still open. For all we know, the world might look like Figure 3. This is the P? = NP problem. The common belief is that the inclusion is strict. If P = NP, many strange things would follow (including the collapse of cryptographic systems), but the question remains one of the great unsolved problems of mathematics. 11