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

Similar documents
Lecture 16: Time Complexity and P vs NP

Finish K-Complexity, Start Time Complexity

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

Time Complexity. CS60001: Foundations of Computing Science

Theory of Computation Time Complexity

Theory of Computation

Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary

CS151 Complexity Theory. Lecture 1 April 3, 2017

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

Computational Complexity

CS154, Lecture 13: P vs NP

CSCE 551 Final Exam, Spring 2004 Answer Key

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

Complexity Theory Part I

CS154, Lecture 13: P vs NP

7.1 The Origin of Computer Science

Computational complexity

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CSCI 2200 Foundations of Computer Science Spring 2018 Quiz 3 (May 2, 2018) SOLUTIONS

Chapter 2: The Basics. slides 2017, David Doty ECS 220: Theory of Computation based on The Nature of Computation by Moore and Mertens

Chapter 7: Time Complexity

CSE 105 THEORY OF COMPUTATION

Harvard CS 121 and CSCI E-121 Lecture 14: Turing Machines and the Church Turing Thesis

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

CSE 105 THEORY OF COMPUTATION

CSCI3390-Lecture 14: The class NP

Analysis of Algorithms

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

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

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

ECS 120 Lesson 23 The Class P

Computability and Complexity

Asymptotic notation : big-o and small-o

1 Showing Recognizability

Computability Theory

Advanced topic: Space complexity

Theory of Computation (IX) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION

INTRODUCTION TO THE THEORY OF NP-COMPLETENESS

Theory of Computation

TURING MAHINES

CISC 4090 Theory of Computation

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

Intro to Theory of Computation

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

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

Great Theoretical Ideas in Computer Science. Lecture 7: Introduction to Computational Complexity

Great Theoretical Ideas in Computer Science. Lecture 9: Introduction to Computational Complexity

Computational Models Lecture 11, Spring 2009

Algorithms and Theory of Computation. Lecture 2: Big-O Notation Graph Algorithms

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

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

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

Complexity (Pre Lecture)

CSCE 551: Chin-Tser Huang. University of South Carolina

Theory of Computation

Computability Theory. CS215, Lecture 6,

6.045 Final Exam Solutions

1 Computational Problems

ECE 695 Numerical Simulations Lecture 2: Computability and NPhardness. Prof. Peter Bermel January 11, 2017

Turing Machine Recap

Turing Machines Part III

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

Notes for Lecture Notes 2

What languages are Turing-decidable? What languages are not Turing-decidable? Is there a language that isn t even Turingrecognizable?

Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College

Time-Space Tradeoffs for SAT

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

Could we potentially place A in a smaller complexity class if we consider other computational models?

Theory of Computation

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2016, face-to-face day section Prof. Marvin K. Nakayama

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

1. Provide two valid strings in the languages described by each of the following regular expressions, with alphabet Σ = {0,1,2}.

Complexity: moving from qualitative to quantitative considerations

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

Intro to Theory of Computation

About the relationship between formal logic and complexity classes

Intro to Theory of Computation

CP405 Theory of Computation

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

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

Introduction to Cryptography

CSE 105 THEORY OF COMPUTATION

Complexity Theory 112. Space Complexity

Complexity Theory Part I

CSE 105 THEORY OF COMPUTATION

Section 14.1 Computability then else

Please give details of your answer. A direct answer without explanation is not counted.

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) Spring l. Blum TIME COMPLEXITY AND POLYNOMIAL TIME;

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Complexity: Some examples

CMPT 710/407 - Complexity Theory Lecture 4: Complexity Classes, Completeness, Linear Speedup, and Hierarchy Theorems

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

Chapter 3: The Church-Turing Thesis

ACS2: Decidability Decidability

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

Turing Machines. The Language Hierarchy. Context-Free Languages. Regular Languages. Courtesy Costas Busch - RPI 1

Transcription:

Harvard CS 121 and CSCI E-121 Lecture 20: Polynomial Time Harry Lewis November 12, 20123

Review of Asymptotic Notation For f, g : N R + f = O(g): c > 0 s.t. f(n) c g(n) for all sufficiently large n. f = Ω(g): g = O(f) f = Θ(g): f = O(g) and g = O(f) f = o(g): c > 0 we have f(n) c g(n) for all sufficiently large n. Equivalently, lim n f(n)/g(n) = 0. f = ω(g): g = o(f). Equivalently, lim n f(n)/g(n) =. Which of the following implies the other? lim n f(n)/g(n) = t for some 0 < t <. f = Θ(g). 1

TIME and Big-O Recall: Let t : N R +. Then TIME(t) is the class of languages L that can be decided by some multitape TM with running time t(n) for inputs of size n. Table lookup shows that using more states we can get t(n) = n for finitely many n. Linear Speedup Theorem shows that using more states and a larger tape alphabet we can reduce t(n) by a constant factor (as long as t(n) is not too small). So TIME(O(t(n))) = TIME(t(n)) for t(n) not too small (e.g. t(n) 1.1n). What about more tapes? 2

Time-bounded Simulations Q: How quickly can a 1-tape TM M 2 simulate a multitape TM M 1? If M 1 uses f(n) time, then it uses f(n) tape cells M 2 simulates one step of M 1 by a complete sweep of its tape. This takes O(f(n)) steps. M 2 uses f(n) O(f(n)) = O(f 2 (n)) steps in all. So L TIME multitape TM (f) L TIME 1-tape TM (O(f 2 )) Similarly O(f k ) for 2-D Tapes Random Access TMs... 3

Basic thesis of complexity theory Extended Church-Turing Thesis: Every reasonable model of computation can be simulated on a Turing machine with only a polynomial slowdown. Counterexamples? Randomized computation. Parallel computation. Analog computers. DNA computers. Quantum computers. Should qualify thesis with sequential and deterministic. 4

Polynomial Time Def: Let P = TIME(p), where p is a polynomial p = TIME(n k ) k 0 also known as PTIME or P Coarse approximation to efficient : 5

Model Independence of P Although P is defined in terms of TM time, P is a stable class, independent of the computational model. (Provided the model is reasonable.) Justification: If A and B are different models of computation, L TIME A (p 1 (n)), and B can simulate a time t computation of A in time p 2 (t), then L TIME B (p 2 (p 1 (n))). Polynomials are closed under composition, e.g. f(n) = n 2, g(n) = n 3 + 1 f(g(n)) = (n 3 + 1) 2 = n 6 + 2n 3 + 1. 6

How much does representation matter? How big is the representation of an n-node directed graph?... as a list of edges?... as an adjacency matrix? How big is the representation of a natural number n?... in binary?... in decimal?... in unary? 7

Describing & Analyzing Polynomial-Time Algorithms Due to Extended Church-Turing Thesis, we can use high-level descriptions. Freely use algorithms we ve seen as subroutines, if we (or you) have analyzed their running time. Bound the total number of high-level steps (including # of loop iterations), and the running time of each step. Be careful about the size of data. poly(n) executions of poly(n)-time algorithms on poly(n)-sized inputs takes time poly(n) 8

For which of the following do we know polynomial-time algorithms? Given a DFA M and a string w, decide whether M accepts w. What is the size of a DFA? Given an NFA N, construct an equivalent DFA M. This is a function, not a language. 9

More problems about regular languages: are they in P? Given an NFA N and a string w, decide whether N accepts w. Given a regular expression R, construct an equivalent NFA N. 10

Problems about context-free languages: are they in P? Given a string w, decide whether w L(G) for a fixed CFG G? What if G is part of the input? 11

Problems about arithmetic: are they in P? Given two numbers N, M, compute their product. What is the size of the numbers? Given a number N, decide if N is prime. Given a number N, compute N s prime factorization. 12

A bogus polynomial-time algorithm Consider the following algorithm on input an n-bit number z: Repeat n times: let z z z (using grade-school multiplication algorithm) Proof that this algorithm is polynomial time: The loop has n iterations. Each time we multiply, which takes time O(n 2 ). Total time = n O(n 2 ) = O(n 3 ). Where is the error? 13

Another way of looking at P Multiplicative increases in time or computing power yield multiplicative increases in the size of problems that can be solved If L is in P, then there is a constant factor k > 1 such that If you can solve problems of size s within a given amount of time and you are given a computer that runs twice as fast, then you can solve problems of size k s on the new machine in the same amount of time. E.g. if L is decidable in O(n d ) time, then with twice as much time you can solve problems 2 1/d as large 14

Exponential time E = c>0 TIME(c n ) For problems in E, a multiplicative increase in computing power yields only an additive increase in the size of problems that can be solved. If L is in E, then there is a constant k such that If you can solve problems of size s within a given amount of time and you are given a computer that runs twice as fast, then you can solve problems only of size k + s on the new machine using the same amount of time. 15