Computational Complexity

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

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

CSE 105 THEORY OF COMPUTATION

Time Complexity. CS60001: Foundations of Computing Science

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

CS5371 Theory of Computation. Lecture 23: Complexity VIII (Space Complexity)

Chapter 7: Time Complexity

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

CSE 105 THEORY OF COMPUTATION

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

Computability and Complexity CISC462, Fall 2018, Space complexity 1

CS154, Lecture 13: P vs NP

CISC 4090 Theory of Computation

Theory of Computation Time Complexity

Computability Theory

Lecture 16: Time Complexity and P vs NP

Computational Models Lecture 11, Spring 2009

CS154, Lecture 13: P vs NP

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

CSE 135: Introduction to Theory of Computation NP-completeness

BBM402-Lecture 11: The Class NP

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

The space complexity of a standard Turing machine. The space complexity of a nondeterministic Turing machine

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

Theory of Computation

Computational complexity

1 Computational Problems

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

CS5371 Theory of Computation. Lecture 23: Complexity VIII (Space Complexity)

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

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

Complexity (Pre Lecture)

Notes for Lecture Notes 2

Finish K-Complexity, Start Time Complexity

CS311 Computational Structures. NP-completeness. Lecture 18. Andrew P. Black Andrew Tolmach. Thursday, 2 December 2010

COMPLEXITY THEORY. PSPACE = SPACE(n k ) k N. NPSPACE = NSPACE(n k ) 10/30/2012. Space Complexity: Savitch's Theorem and PSPACE- Completeness

Space Complexity. Huan Long. Shanghai Jiao Tong University

CSE 105 Theory of Computation

Computability and Complexity

ECS 120 Lesson 23 The Class P

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

CSE 105 THEORY OF COMPUTATION

Complexity Theory 112. Space Complexity

Turing Machine Variants

CS151 Complexity Theory. Lecture 1 April 3, 2017

Intractable Problems [HMU06,Chp.10a]

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

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

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

Computer Sciences Department

1 Non-deterministic Turing Machine

conp, Oracles, Space Complexity

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

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

Definition: conp = { L L NP } What does a conp computation look like?

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan August 30, Notes for Lecture 1

CSCI3390-Lecture 14: The class NP

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

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

Complexity: moving from qualitative to quantitative considerations

INTRODUCTION TO THE THEORY OF NP-COMPLETENESS

Lecture 20: PSPACE. November 15, 2016 CS 1010 Theory of Computation

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

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

Artificial Intelligence. 3 Problem Complexity. Prof. Dr. Jana Koehler Fall 2016 HSLU - JK

Lecture 19: Finish NP-Completeness, conp and Friends

Complexity Theory Part II

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

De Morgan s a Laws. De Morgan s laws say that. (φ 1 φ 2 ) = φ 1 φ 2, (φ 1 φ 2 ) = φ 1 φ 2.

Hierarchy theorems. Evgenij Thorstensen V18. Evgenij Thorstensen Hierarchy theorems V18 1 / 18

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

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

Theory of Computation. Ch.8 Space Complexity. wherein all branches of its computation halt on all

Lecture 24: Randomized Complexity, Course Summary

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

Lecture 22: PSPACE

Limits of Feasibility. Example. Complexity Relationships among Models. 1. Complexity Relationships among Models

Review of unsolvability

CS 241 Analysis of Algorithms

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

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

CSCI 1590 Intro to Computational Complexity

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?

1 Computational problems

Intro to Theory of Computation

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

Lecture 3: Reductions and Completeness

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

Time and space classes

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}

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

The P versus NP Problem. Dean Casalena University of Cape Town CSLDEA001

CSE200: Computability and complexity Space Complexity

Outline. Complexity Theory. Example. Sketch of a log-space TM for palindromes. Log-space computations. Example VU , SS 2018

Notes on Complexity Theory Last updated: December, Lecture 2

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

Chapter 2 : Time complexity

The Polynomial Hierarchy

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

Transcription:

CS311 Computational Structures Computational Complexity Lecture 16 Andrew P. Black Andrew Tolmach 1

So, itʼs computable! But at what cost? Some things that are computable in principle are in practice intractable because of the high cost Cost can measured in time, or in space, or in other resources Simple time measure of decision algorithm is number of steps taken by a (one-tape, deterministic) Turing Machine 2

Counting TM Steps Lax = {w {a,b}* next to last symbol of w is a} L a L b L L a R 0 1 2 3 a R b R b R R 7 Machine always takes exactly n+3 steps on input of length n 311

Time complexity class STEPS(t(n)) is the class of all languages that are decidable by a (one tape deterministic) Turing machine in at most t(n) steps. Given input of size n, machine must halt within t(n) steps with definite answer accept or reject. So Lax STEPS(n+3) 4

A smarter machine for Lax b R a R 2 b R a R L a R b R L 0 1 3 4 a R b R Machine takes at most n+1 steps on input of length n So Lax STEPS(n+1) 5

A machine for {a k b k k 0} 5 a L b L R R 4 b, L a, R b R L 0 1 2 3 a R b R Main loop matches a from start and b from end. e.g. 0aabb 1abb a1bb ab2b abb2 ab3b a4b 4ab 4 ab 0ab 6

Calculating machine time Main loop on a k b k takes 4k+1 steps and reduces k by 1 e.g. for k = 2: 0aabb 1abb a1bb ab2b abb2 ab3b a4b 4ab 4 ab 0ab So overall time for yes decision on a k b k is (4k+1) + (4(k-1)+1) +... + (4+1) + 1 = 4(k+(k-1)+...+1) + k + 1 = 4k(k+1)/2 + k+1 = (2k+1) (k+1) = 2k 2 + 3k + 1 By inspection, reaching no canʼt take longer than yes, so machine decides in at most (1/2)n 2 + (3/2)n + 1 steps 7

Problems vs. Algorithms So {a k b k k 0} STEPS((1/2)n 2 + (3/2)n + 1). Does this mean that deciding {a k b k k 0} always takes this much time? No! There are faster algorithms (machines) for deciding this language. e.g., can be done in time proportional to n log n 8

Letʼs approximate Weʼd like to discuss time for algorithms even if they are only described informally And even when we do have a precise TM, counting steps exactly is tedious! Also, we often care only about the asymptotic ( big O ) behavior of an algorithm or problem. From now on, weʼll be loose about describing and counting steps e.g. {a k b k k 0} TIME(n 2 ) 9

Reviewfrom Hein textbook for CS250 10

In other words... O(g) is the set of functions whose asymptotic behavior is bounded above by that of g Ω(g) is the set of functions whose asymptotic behavior is bounded below by that of g Also, we define ϴ(g) to be the set of functions with the same asymptotic behavior as g i.e., both O(g) and Ω(g) 11

Comparative growth rates of some functions 100 90 f(x) = 2 2x f(x) = x x f(x) = x! 80 atoms in observable universe 70 60 log 10 f(x) 50 40 f(x) = 3 x 30 20 10 f(x) = 2 x seconds since Big Bang f(x) = x 3 0 0 10 20 30 40 50 60 70 80 90 f(x) = x 2 100 x 12

Avoiding Exponential Time Algorithms requiring exponential time are too slow to be practical except for very small input sizes. Indeed, problems requiring more than polynomial time are often called intractable. Note: this is just a convenient term. A tractable problem that requires O(n 100 ) time is likely not practically solvable. 13

Another problem: PATH PATH = { G,s,t G is a directed graph that has a directed path from s to t } We assume G is encoded as an adjacency matrix of size O(n 2 ). (Any other reasonable encoding will also work.) Thereʼs an obvious brute force algorithm to decide this language: try each possible sequence of nodes in G of length up to n, and see if it forms a path in G We consider each possible path only once But there are still n! possible paths, so time of this algorithm is Ω(2 n ). 14

A faster PATH finder PATH = { G,s,t G is a directed graph that has a directed path from s to t } A faster algorithm operates like this: 1. Place a mark on node s 2. Repeat until no additional nodes are marked 2.1. Scan all edges of G. If an edge (a,b) is found from a marked node a to an unmarked node b, mark b. 3. If t is marked accept; otherwise reject. Time: step 2 repeats O(n) times; each step takes O(n 2 ) time, so overall time is O(n 3 ). PATH is tractable after all. 15

Finding a Hamiltonian path HAMPATH = { G,s,t G is a directed graph with a path from s to t passing through each node exactly once} The brute force algorithm for PATH works here too, so HAMPATH is in TIME(n!) (where n is number of nodes in graph). Nobody knows for sure whether there is a polynomial-time algorithm for HAMPATH. 16

What if we vary the model? When weʼre talking about timing, our precise choice of TM model matters. Unlike for decidability results. Example: Given a two-tape TM, we can recognize {a n b n n 0} in O(n) time. How? Example: On a nondeterministic TM, the brute force algorithm for PATH runs in polynomial time. Why? 17

Time cost of simulation We can relate execution times on fancy TMʼs to those on the standard TM. For every multitape TM that runs in time t(n), there is an equivalent single tape TM that runs in time O(t 2 (n)). IALC Thm. 8.10 For every ND TM that decides in time t(n), there is an equivalent single tape TM that decides in time 2 O(t(n)). Straightforward from simulation method 18

Summary Sometimes thereʼs an algorithm that is asymptotically faster than the obvious one. Sometimes there isnʼt (and we may not know). The distinction between polynomial and exponential time algorithms matters The underlying computation model matters 19

The class P: Tractable Problems P is the class of languages that are decidable in polynomial time on a deterministic singletape Turing machine. In other words, P = TIME(n k ) k where the time complexity class TIME(t(n)) is the collection of languages that are decidable by a deterministic single-tape TM in O(t(n)) steps 20

Tractable Problems Most of the computer programs in common use a solve problem in P. If it werenʼt, the program would probably run too slowly to be useful! Exception: some problems can be solved for interesting special cases even if they arenʼt tractable in general But sometimes finding a polynomial time algorithm is challenging And for a large class of problems, we donʼt know for sure whether such a algorithm exists. 21

Verifying vs. Solving Often, it seems easier to verify an alleged solution to a problem than it is to determine from scratch whether there is a solution. Example: Consider the Hamiltonian Path problem; no polynomial time algorithm for this is known. But if we have a proposed solution (i.e., a path that visits each node once), it is simple to verify whether the path is correct in polynomial time. (How?) The proposed solution is described by a certificate e.g., for Hamiltonian Path, the proposed path A verifier is a TM that takes a problem and a certificate and answers OK or fake 22

The Class NP The class NP contains all the decision problems that can be verified in Polynomial time. Equivalently The class NP contains all the decision problems that can be solved in Polynomial time by a nondeterministic algorithm It may make arbitrary (nondeterministic) choices The number of steps must be bounded by some polynomial in n, where n is the length of the input NTIME(t (n)) = languages decidable in O(t (n)) time by a NDTM NP = k NTIME(n k ) 23

Equivalence of Two Definitions of NP Suppose that we have a deterministic verifier then we build a non-deterministic solver that: non-deterministically generates all putative certificates (effectively in parallel) runs the deterministic verifier to check them (each in polynomial time) if there is a solution, weʼll find and approve its certificate 24

Conversely: Suppose we have a non-deterministic solver, e.g., a non-deterministic TM M At each of its polynomially-many steps, it may branch at most a constant number of ways. We can use the path of choices made as the certificate; valid certificates lead to accept states. So: we can build a deterministic verifier that, given the certificate, simulates M on that path, and checks that it is an accept path. This takes polynomially-many steps 25

Relationship NP Problems P Problems Anything in P is also in NP because any deterministic algorithm is also a nondeterministic algorithm Does P = NP? currently not known, but widely suspected P NP 26

Beyond NP Many interesting and natural problems are in NP Typically show membership in NP by exhibiting a polynomial-time verifier. But some (natural) problems are not... n EXPTIME = k TIME(2 k ) is believed to be larger than NP (and known to be larger than P) 2-EXPTIME = Uk TIME(2 2 ) is larger than NP n k 27

What about Space? We can measure the space use of a TM as the maximum number of tape cells it scans on an input of length n. Define SPACE(f(n)) as the class of languages decided by a (deterministic) TM using O(f(n)) space. Define NSPACE similarly for non-deterministic TM. 28

NP PSPACE By analogy with time classes, we define PSPACE = k SPACE(n k ) and NPSPACE = k NSPACE(n k ) Then NP PSPACE. Clearly NP NPSPACE, because a machine that takes t steps can access at most t tape squares. It turns out that NPSPACE = PSPACE Consequence of Savitchʼs theorem (IALC 11.5) It also turns out that NPSPACE EXPTIME But it is unknown whether NP PSPACE or NSPACE EXPTIME 29