Computability and Complexity

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

CSE 105 Theory of Computation

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

Chapter 7: Time Complexity

CSE 105 THEORY OF COMPUTATION

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

Theory of Computation Time Complexity

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Computability Theory

CS154, Lecture 13: P vs NP

CS154, Lecture 13: P vs NP

CISC 4090 Theory of Computation

CP405 Theory of Computation

Computational Models Lecture 11, Spring 2009

Time Complexity. CS60001: Foundations of Computing Science

Computability and Complexity

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

Lecture 16: Time Complexity and P vs NP

Chapter 2 : Time complexity

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Computability Theory

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Intractable Problems [HMU06,Chp.10a]

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

BBM402-Lecture 11: The Class NP

Final exam study sheet for CS3719 Turing machines and decidability.

CSE 105 THEORY OF COMPUTATION

1 Computational Problems

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

MA/CSSE 474 Theory of Computation

Notes for Lecture Notes 2

CSE 105 THEORY OF COMPUTATION

Applied Computer Science II Chapter 7: Time Complexity. Prof. Dr. Luc De Raedt. Institut für Informatik Albert-Ludwigs Universität Freiburg Germany

Lecture 19: Finish NP-Completeness, conp and Friends

Complexity (Pre Lecture)

Functions on languages:

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

CS5371 Theory of Computation. Lecture 19: Complexity IV (More on NP, NP-Complete)

CS 455/555: Finite automata

Exam Computability and Complexity

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

Computational complexity

Finish K-Complexity, Start Time Complexity

Context-Free and Noncontext-Free Languages

CSE 135: Introduction to Theory of Computation NP-completeness

V Honors Theory of Computation

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

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

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

1 Non-deterministic Turing Machine

Polynomial Time Computation. Topics in Logic and Complexity Handout 2. Nondeterministic Polynomial Time. Succinct Certificates.

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

CS481F01 Solutions 8

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Intractable Problems. Time-Bounded Turing Machines Classes P and NP Polynomial-Time Reductions

Time and space classes

Lecture 3: Nondeterminism, NP, and NP-completeness

Complexity Theory Part II

Chapter 1 - Time and Space Complexity. deterministic and non-deterministic Turing machine time and space complexity classes P, NP, PSPACE, NPSPACE

Computational Complexity

Time Complexity. Definition. Let t : n n be a function. NTIME(t(n)) = {L L is a language decidable by a O(t(n)) deterministic TM}

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

22c:135 Theory of Computation. Analyzing an Algorithm. Simplifying Conventions. Example computation. How much time does M1 take to decide A?

13.1 Nondeterministic Polynomial Time

Computer Sciences Department

Intro to Theory of Computation

CS Lecture 28 P, NP, and NP-Completeness. Fall 2008

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

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

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

CS20a: summary (Oct 24, 2002)

CPS 220 Theory of Computation

NPDA, CFG equivalence

DM17. Beregnelighed. Jacob Aae Mikkelsen

CSCE 551 Final Exam, Spring 2004 Answer Key

THEORY OF COMPUTATION

Theory of Computation

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

Context Free Languages: Decidability of a CFL

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

CS481F01 Prelim 2 Solutions

Computational Models Lecture 8 1

ACS2: Decidability Decidability

Computational Models Lecture 8 1

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

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

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

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

Homework 8. a b b a b a b. two-way, read/write

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

6.840 Language Membership

P vs. NP Classes. Prof. (Dr.) K.R. Chowdhary.

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Asymptotic notation : big-o and small-o

The Unsolvability of the Halting Problem. Chapter 19

Computational Models Lecture 8 1

Transcription:

Computability and Complexity Lecture 10 More examples of problems in P Closure properties of the class P The class NP given by Jiri Srba Lecture 10 Computability and Complexity 1/12

Example: Relatively Prime Definition Natural numbers x and y are relatively prime iff gcd(x, y) = 1. gcd(x, y)... the greatest common divisor of x and y RELPRIME def = { x, y x and y are relatively prime numbers } Remember our agreement about encoding of numbers: x and y are encoded in binary, so the length of x, y is O(log(x + y)). Brute-Force Algorithm is Exponential Given an input x, y of length n = x, y, going through all numbers between 2 and min{x, y} and checking whether some of them divide both x and y takes time exponential in n. Lecture 10 Computability and Complexity 2/12

Solving RELPRIME in P Euclidean algorithm for finding gcd(x, y): function gcd( x, y ) def = if (y == 0) return x else return gcd( y, x mod y ) Theorem The Euclidean algorithm called on input x, y runs in time O(log(x + y)). Hence its running time is O(n) (its input is encoded in binary). Conclusion RELPRIME P Lecture 10 Computability and Complexity 3/12

Example: Context-Free Languages Theorem Every context-free language is in P. Proof: Let L be a CFL. Then there is CFG G in Chomsky normal form s.t. L(G) = L. For any given string w = w 1 w 2... w n we want to decide in polynomial time whether w L(G) or not. Problem of the naive approach: Brute-force algorithm (i.e. enumerating all derivations of the length 2n 1) takes exponential time! Solution: We use dynamic programming instead. Lecture 10 Computability and Complexity 4/12

Checking whether w L(G) using Dynamic Programming Idea (for a given grammar G in Chomsky normal form): On input w = w 1 w 2... w n create temporary sets of nonterminals called table(i, j) for 1 i j n such that A table(i, j) if and only if A w i w i+1... w j. On input w = w 1 w 2... w n : 1. If w = ɛ then accept if S ɛ is a rule in G, else reject. 2. For i:=1 to n do: if A w i is a rule in G, add A to table(i, i). 3. For l:=2 to n do: for all i, k such that 1 i k < i + l 1 } {{ } j n do: for all rules A BC in G do: if B table(i, k) and C table(k + 1, j) then add A to table(i, j). 4. If S table(1, n) then accept, else reject. The algorithm runs in O(n 3 ). Lecture 10 Computability and Complexity 5/12

Closure Properties of the Class P Theorem (Closure Properties of the Class P) The class P is closed under intersection, union, complement, concatentation and Kleene star. In other words: If L 1 and L 2 are decidable in deterministic polynomial time, then L 1 L 2, L 1 L 2, L 1, L 1.L 2, and L 1 are decidable in deterministic polynomial time too. Lecture 10 Computability and Complexity 6/12

Proof: Closure of Decidable Languages under Union Let L 1, L 2 P. We want to show that L 1 L 2 P. Because L 1, L 2 P then there is a decider M 1 for L 1 running in time O(n k ) for some k, and a decider M 2 for L 2 running in time O(n l ) for some l. The following 2-tape TM M is a decider for L 1 L 2 : M= On input x: 1. copy x on the second tape 2. on the first tape run M 1 on x 3. if M 1 accepted then accept else goto step 4 4. on the second tape run M 2 on x 5. if M 2 accepted then accept else reject. M runs in time O(n k ) + O(n l ) = O(n c ) where c = max{k, l}. M can be simulated by a single-tape TM running in time O((n c ) 2 ) = O(n 2c ), hence L(M) P because 2c is a constant. Lecture 10 Computability and Complexity 7/12

Running Time of a Nondeterministic TM Definition (Running Time of a Nondeterministic TM) Let M be a nondeterministic decider. The running time or (worst-case) time complexity of M is a function f : N N where f (n) is the maximum number of steps that M uses on any branch of its computation tree for any input of length n. Theorem Let t(n) be a function s.t. t(n) n. Every nondeterministic TM running in time t(n) has an equivalent deterministic TM running in time 2 O(t(n)). Proof: Simulate a nondeterministic TM M by a deterministic TM M (from Lecture 2) and analyze the running time of M. Lecture 10 Computability and Complexity 8/12

The Complexity Class NTIME(t(n)) Definition (Time Complexity Class NTIME(t(n))) Let t : N R >0 be a function. NTIME(t(n)) def = {L(M) M is a nondeterministic decider running in time O(t(n))} In other words: NTIME(t(n)) is the class (collection) of languages that are decidable by nondeterministic TMs in time O(t(n)). Example: HAMPATH def = { G, s, t G is a directed graph with a Hamiltonian path from s to t } HAMPATH NTIME(n 2 ) Lecture 10 Computability and Complexity 9/12

HAMPATH NTIME(n 2 ) Consider the following nondeterministic decider for HAMPATH: On input G, s, t : 1. Nondeterministically select a sequence of nodes v 1, v 2,..., v m where m is the number of nodes in G. 2. Verify that every node appears in the sequence exactly once. If not then reject. 3. Verify that v 1 = s and v m = t. If not then reject. 4. For each i:= 1 to m 1 verify if there is an edge from v i to v i+1. If not then reject. 5. All test passed so accept. The nondeterministic decider runs in time O(n 2 ). Lecture 10 Computability and Complexity 10/12

The Class NP Definition The class NP is the class of languages decidable in polynomial time on nondeterministic single-tape Turing machine, i.e., NP def = k 0 NTIME(n k ). Example: HAMPATH NP Discussion: The class NP is robust (the class remains the same even if we choose some other nondeterministic model of computation). Every problem from NP can be solved in exponential time on a deterministic TM. P NP (every determin. TM is a nondetermin. TM too) The question whether P=NP is open. Lecture 10 Computability and Complexity 11/12

Exam Questions RELPRIME and any context-free language are in P. Closure properties of the class P. Nondeterministic time complexity, the classes NTIME(t(n)) and NP. Simulation of nondeterministic TM by a deterministic one with exponential increase in a running time. Lecture 10 Computability and Complexity 12/12