Week 2: Defining Computation

Similar documents
Week 3: Reductions and Completeness

CSCI3390-Lecture 14: The class NP

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

CSCI3390-Lecture 16: NP-completeness

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

Languages, regular languages, finite automata

Turing Machines and Time Complexity

Computational Complexity

Complexity (Pre Lecture)

Boolean circuits. Lecture Definitions

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

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Lecture 20: conp and Friends, Oracles in Complexity Theory

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

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

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

Computability Theory

Turing Machine Recap

CSCI3390-Assignment 2 Solutions

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

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

NP Complete Problems. COMP 215 Lecture 20

Please bring the task to your first physics lesson and hand it to the teacher.

Computational complexity

MTAT Complexity Theory October 13th-14th, Lecture 6

Essential facts about NP-completeness:

1 Computational problems

Nondeterministic finite automata

CS4026 Formal Models of Computation

CS 6505, Complexity and Algorithms Week 7: NP Completeness

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

Time-bounded computations

Lecture 22: PSPACE

LTCC Course: Graph Theory 2017/18 3: Complexity and Algorithms

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

Lecture 3: Reductions and Completeness

Complexity Theory Part I

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

SOLUTION: SOLUTION: SOLUTION:

A non-turing-recognizable language

CSCI3390-Second Test with Solutions

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

Lecture Notes Each circuit agrees with M on inputs of length equal to its index, i.e. n, x {0, 1} n, C n (x) = M(x).

Time to learn about NP-completeness!

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

Turing Machines, diagonalization, the halting problem, reducibility

Part I: Definitions and Properties

More Turing Machines. CS154 Chris Pollett Mar 15, 2006.

Chapter 7 Turing Machines

Turing Machines Part III

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

1 Deterministic Turing Machines

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

Section 4.6 Negative Exponents

6-1 Computational Complexity

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

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

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

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

Theory of Computation Time Complexity

Introduction to Turing Machines. Reading: Chapters 8 & 9

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits

Definition: Alternating time and space Game Semantics: State of machine determines who

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Lecture 22: Quantum computational complexity

CSE 135: Introduction to Theory of Computation NP-completeness

Most General computer?

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

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

CS151 Complexity Theory. Lecture 1 April 3, 2017

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

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

Complexity and NP-completeness

The Turing machine model of computation

(a) Definition of TMs. First Problem of URMs

Theory Bridge Exam Example Questions

More About Turing Machines. Programming Tricks Restrictions Extensions Closure Properties

Space Complexity. Huan Long. Shanghai Jiao Tong University

$1,000,000. P vs. NP. the prize for solving any of the Millennium Prize Problems. Millennium Prize Problems. Millennium Prize Problems

Math Fundamentals for Statistics I (Math 52) Unit 7: Connections (Graphs, Equations and Inequalities)

Further discussion of Turing machines

Turing machines and linear bounded automata

Principles of Knowledge Representation and Reasoning

Lecture 11: Proofs, Games, and Alternation

Design and Analysis of Algorithms

Pr[X = s Y = t] = Pr[X = s] Pr[Y = t]

Definition: Alternating time and space Game Semantics: State of machine determines who

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

UNIT-VIII COMPUTABILITY THEORY

Final Exam Comments. UVa - cs302: Theory of Computation Spring < Total

Lecture 4: Constructing the Integers, Rationals and Reals

Final Exam (Version B) December 16, 2014 Name: NetID: Section: 1 2 3

where Q is a finite set of states

Lecture 24: Randomized Complexity, Course Summary

DRAFT. Algebraic computation models. Chapter 14

Final Exam Version A December 16, 2014 Name: NetID: Section: # Total Score

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

Turing Machines Part Three

Turing machine recap. Universal Turing Machines and Undecidability. Alphabet size doesn t matter. Robustness of TM

Transcription:

Computational Complexity Theory Summer HSSP 2018 Week 2: Defining Computation Dylan Hendrickson MIT Educational Studies Program 2.1 Turing Machines Turing machines provide a simple, clearly defined way of describing algorithms. They turn out to be as powerful as any programming language, but easier to reason about due to their simplicity. A Turing machine has access to an infinite sequence of cells, called a tape. Each cell has one of a predefined list of symbols; we ll say cells can be blank or contain 0 or 1, though the number of symbols doesn t really matter. The Turing machine also has some number of internal states, including one labelled accept and one labelled reject. At any time, it is in one of its internal states and looking at one cell of the tape. To run the Turing machine for one step, check the state it s in and the symbol in the cell it s looking at. Based on the state and symbol, it can write a new symbol in the cell, move one cell left or right, and switch to a different state. Exactly what it does for each state and symbol is part of the specification of the Turing machine. To run a Turing machine on some input, we start with the input written on the tape and the Turing machine looking at the first cell of the input, in a specific start state. We then repeatedly run it for one step until it enters either the accept or reject state, at which point we say it has accepted or rejected. Notice that we must represent the input as a string of valid symbols; if the input is a number, we can just write it in binary, but if it s something more complicated, we ll have to find a way to convert it to a string. (If you don t know binary, it s just a way of writing numbers using only 0 and 1, instead of base ten which uses the ten digits 0 through 9. If a problem in this class involves numbers written in binary, you can usually use numbers in base ten instead if you prefer, by allowing the Turing machine to use all ten digits.) This will make more sense with an example. We often draw Turing machines, using circles for states and arrows for transitions between states. start indicates that q 0 is the starting state. Arrows between states are transitions, annotated with what they do. If there is an arrow labelled x y,d from state q 1 to q 2, it means that when the Turing machine is in state q 1 and reads x on the tape, it replaces x with y, move in the direction D (either L or R ), and switches to state q 2. For example, the arrow labelled 0,R indicates that when the Turing machine is in state q 0 and reads a 0, it erases the 0 (the blank symbol is represented by ), moves one cell right, and stays in state q 0. The accepting and rejecting states are q acc and q rej ; the double circles indicate that the Turing machine halts when it reaches one of those states. 0,R start q 0 1,R,R q acc q rej Exercise 1. What decision problem does the above Turing machine answer? Assume that the input is a 2-1

Week 2: Defining Computation 2-2 string of 0s and 1s, with no blanks (there are still infinitely many blanks past the end of the input). Find a property of the input that determines whether this machine accepts. To describe a Turing machine, you have to specify the following: Input/tape alphabet. This is the set of valid symbols, typically 0, 1, and blank. (Sometimes the input alphabet and tape alphabet are different, meaning you can write symbols to the tape which can t be part of the input.) States, including the start state, accept state, and reject states. Transitions. For each state (other than accept and reject) and symbol, specify a new symbol, direction to move, and new state. All this can be representing graphically as in the above image. Exercise 2. Find a Turing machine that, given an input containing only 0s and 1s, says whether it s a palindrome (i.e. is the same written forwards and backwards). Such a machine should accept inputs such as 0110 and 11111, but reject inputs such as 0100 and 0101101. Exercise 3. Find a Turing machine that checks whether its input is even. Assume the input is a number in binary (or base 10 if you prefer). Exercise 4. Find a Turing machine that checks whether two strings of 0s and 1s separated by a blank are identical. Sometimes we want Turing machines that do more than just accept or reject. For example, we might want to be able to add two numbers. In this case, we give the Turing machine a single halt state instead of accept and reject states, and take the output as whatever is written on the tape when it halts. Here s an example: 0 1,R start q 0 1 0,R,R q halt Exercise 5. What function does the above Turing machine compute? That is, what is its output in relation to its input? Exercise 6. Find a Turing machine that reverses a string of 0s and 1s. Exercise 7. Find a Turing machine that adds 1 to its input. Exercise 8. Find a Turing machine that multiplies its input by 2. Hopefully you ve gotten a sense that Turing machines can be pretty powerful, even if it takes them a while to move back and forth across the tape. For any program you write in your favorite programming language, it s possible to find a Turing machine that does the same thing.

Week 2: Defining Computation 2-3 2.2 Complexity Classes We want to look at Turing machines that run quickly in order to define easy problems. We can t simply put a constant bound on the number of steps the Turing machine takes before halting, since we expect it to take a long time on a very large input. Instead, we ll let the running time grow as a function of the length of the input. Maybe we ll give it 25 steps for inputs of length 5, and 10000 steps for inputs of length 100. We mostly care about the behavior of the running time for very large inputs. Since there are a finite (but huge) number of inputs of length 100, you could write a Turing machine with the answers to each of those inputs hard-coded; the Turing machine reads across the input and ends up in a different state depending on which length-100 string it is. Such a machine would need about 2 100 states, but would take only about 100 steps to process inputs of length at most 100. This sort of construction isn t terribly interesting, and doesn t depend on the structure of the problem the Turing machine is solving, so we ignore it by focusing on the asymptotic growth of the running time. The growth rates we generally think of as small are polynomials: functions like n 2 or n 3, if the input length is n. We say that a Turing machine runs in polynomial time if there are constants a and b such that for every input of length n, the Turing machine halts within an b steps. In other words, there should be a polynomial in the input length that is an upper bound for the running time. There are standard notations for comparing growth rates in general (most commonly O(), but also e.g. o(), Θ(), and Ω()), but we won t need them in this class. It ll usually be enough to say whether a function grows polynomially or faster than polynomially. Why do we use polynomial growth instead something more limited, such as linear (an) or quadratic (an 2 ) growth? Consider the decision problem of determining whether a string is a palindrome. A Turing machine takes quadratic time to solve this problem; it has to check each matching pair of bits of the input (of which there are n, and checking each pair requires crossing between them (they re n apart on average). What if we instead defined Turing machines differently, so that they had an extra tape to work with (the extra tape starts blank, the Turing machine has a position on each tape, and the new symbol and movement direction for each tape and new internal state depend on the readings from both tapes)? Then we could make a Turing machine that decides whether a string is a palindrome in only linear time: first, copy the input onto the second tape. Then read one copy of the input forwards and the other copy backwards, comparing them as you go. So a two-tape Turing machine is faster than an ordinary Turing machine. Similarly, real-life computers work in a way that lets them do a lot of things faster than Turing machines. Even though these different models vary in speed, they re within a polynomial of each other. Being able to do something in linear time on a multi-tape Turing machine doesn t mean you can do it in linear time on a single-tape Turing machine, but if you can do something in polynomial time on a multi-tape Turing machine, then a single-tape Turing machine can also do it in polynomial time. To see this, you can design a single-tape Turing machine that simulates a two-tape Turing machine by marking off two sections of its tape to serve as two separate tapes. It then takes some time to go back and forth between the two sections, but the overhead is only polynomial, so if the two-tape machine runs in polynomial time, so does the single-tape machine simulating it. Polynomial time is resilient to changes in the model of computation, which makes it a natural class to consider. Definition 2.1. P is the class of decision problems L such that there is a polynomial-time Turing machine that decides L. NP is the class of decision problems that can be verified in polynomial time. That is, a decision problem L is in NP iff there is a polynomial-time Turing machine M such that for each x L, there is a certificate c for x where M(x, c) accepts, and whenever M(x, c) accepts, x is in L. conp is NP, the class of decision problems that can be verified false in polynomial time.

Week 2: Defining Computation 2-4 The definition of NP may be confusing; some examples of NP problems and certificates will help. It s very similar to the alternate definition of RE we saw last week. You can also think of NP as being the class of decision problems that can be solved by a polynomial-time Turing machine which is allowed to make lucky guesses; you guess the value of a certificate and then see if it worked. Such a machine is called a nondeterministic Turing machine, which is where the N comes from. It should be clear that P NP and P conp; if you can solve something in polynomial time, then you can verify it just as quickly. Can you prove or disprove that P = P? Here are some decision problems in P: Given a completed Sudoku grid, is it solved correctly? Given a number, is it prime? (this is hard to show) Given some numbers and the location of mines in Minesweeper, is the arrangement of mines valid? Given a (directed) graph and two vertices s and t, is there a path from s to t? Given a boolean formula and assignments to variables, is the formula true? Here are some decision problems in NP but not known to be in P: Given a Sudoku puzzle, does it have a solution? Given numbers n, a, and b, does n have a factor between a and b? Given some numbers in Minesweeper, is there an arrangement of mines satisfying them? Given a graph, does it have a Hamiltonian path? Given a boolean formula, does it have a satisfying assignment? For each of these NP problems, the complement problem is in conp. The factoring problem is also in conp; the prime factorization of n serves as a certificate to prove it doesn t have a factor between a and b. So this problem is in NP conp; the other problems are not known to be in conp. Sometimes we don t care how long a program takes to run, and instead care about how much memory it uses. A Turing machine runs in polynomial space if there are constants a and b such that for every input of length n, the Turing machine visits at most an b cells of the tape. Definition 2.2. PSPACE is the class of decision problems L such that there is a polynomial-space Turing machine that decides L. What about verifying in polynomial space? We could define NPSPACE similarly, but it turns (not obviously) out that PSPACE = NPSACE; if you can verify something in polynomial space, you can solve it in polynomial space too. A Turing machine uses only one cell per step, so a polynomial-time machine runs in polynomial space. Thus P PSPACE. Suppose you have an NP problem. The certificates must be polynomially long, since otherwise the polynomial-time verifier wouldn t be able to read the whole certificate. We can make a polynomial-space Turing machine that writes each possible certificate to its tape and runs the verifier on it, then increments the certificate. This machine solves the NP problem, so NP PSPACE; similarly conp PSPACE. Here are some decision problems in PSPACE that aren t known to be in NP or conp:

Week 2: Defining Computation 2-5 Given a Rush Hour puzzle, is it solveable? Given a quantified boolean formula, is it true? Given a level in Super Mario Bros., is it solveable? Given a position in Othello/Reversi, can white force a win? If the tape has k cells, there are roughly 2 k configurations of the tape, so a polynomial-space Turing machine can take an exponential amount of time. Nobody knows for sure whether P = PSPACE, but it seems extremely likely that there are problems in PSPACE but not in P; you can do strictly more with polynomial space than you can with polynomial time. 2.3 Challenge Problems Here are some harder problems in case you want more practice designing Turing machines. I also highly recommend playing Manufactoria (http://pleasingfungus.com/manufactoria/), a Flash game about building devices a lot like Turing machines. Exercise 9. Find a Turing machine that checks whether the first of two numbers is greater than the second. Assume the numbers are written in binary (or base 10) and separated by a blank. Exercise 10. Find a Turing machine that checks whether a number (in binary/base 10) is a multiple of 3. Exercise 11. Find a Turing machine that adds two numbers separated by a blank. Exercise 12. Find a Turing machine that checks whether a string contains the same number of 0s and 1s. Exercise 13. Find a Turing machine that checks whether its input is of the form 0 n 1 n, i.e. some number of 0s followed by the same number of 1s. Exercise 14. Find a Turing machine that multiplies its input by 3. Exercise 15. Find a Turing machine that multiplies two numbers separated by a blank. Exercise 16. Find a Turing machine that checks whether a number is prime. Does it run in polynomial time? Exercise 17. Find a Turing machine that checkes whether a string of open and close paretheses is valid (e.g. ()() and (()(())) are valid but ( and ())(() aren t). You can either let the Turing machine use ( and ) as symbols, or interpret 0 as ( and 1 as ).