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

Similar documents
Advanced topic: Space complexity

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

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

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

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

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

Computability and Complexity CISC462, Fall 2018, Space complexity 1

CSE 555 HW 5 SAMPLE SOLUTION. Question 1.

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

Lecture 22: PSPACE

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

CSE200: Computability and complexity Space Complexity

conp, Oracles, Space Complexity

SOLUTION: SOLUTION: SOLUTION:

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

CSCI 1590 Intro to Computational Complexity

Logarithmic space. Evgenij Thorstensen V18. Evgenij Thorstensen Logarithmic space V18 1 / 18

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

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan 9/6/2004. Notes for Lecture 3

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

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

Lecture 8: Complete Problems for Other Complexity Classes

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

Notes on Space-Bounded Complexity

V Honors Theory of Computation

Polynomial Space. The classes PS and NPS Relationship to Other Classes Equivalence PS = NPS A PS-Complete Problem

Introduction to Computational Complexity

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

Notes on Space-Bounded Complexity

Space Complexity. Huan Long. Shanghai Jiao Tong University

Complexity Theory 112. Space Complexity

Lecture 5: The Landscape of Complexity Classes

Lecture 20: conp and Friends, Oracles in Complexity Theory

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

Lecture 24: Randomized Complexity, Course Summary

Theory of Computation Space Complexity. (NTU EE) Space Complexity Fall / 1

CS151 Complexity Theory. Lecture 4 April 12, 2017

15.1 Proof of the Cook-Levin Theorem: SAT is NP-complete

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).

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

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

Space and Nondeterminism

Lecture 3: Reductions and Completeness

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

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

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

Lecture 3. 1 Terminology. 2 Non-Deterministic Space Complexity. Notes on Complexity Theory: Fall 2005 Last updated: September, 2005.

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

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}

1 Computational problems

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

Part I: Definitions and Properties

CS256 Applied Theory of Computation

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

Complexity (Pre Lecture)

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

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

CP405 Theory of Computation

Lecture 6: Oracle TMs, Diagonalization Limits, Space Complexity

Turing Machines and Time Complexity

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

Theory of Computation

198:538 Complexity of Computation Lecture 16 Rutgers University, Spring March 2007

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

Computability Theory. CS215, Lecture 6,

PSPACE, NPSPACE, L, NL, Savitch's Theorem. More new problems that are representa=ve of space bounded complexity classes

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

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

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Lecture 8. MINDNF = {(φ, k) φ is a CNF expression and DNF expression ψ s.t. ψ k and ψ is equivalent to φ}

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

9 Nondeterministic Turing Machines

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

Time and space classes

1 PSPACE-Completeness

CSCI 1590 Intro to Computational Complexity

Principles of Knowledge Representation and Reasoning

COL 352 Introduction to Automata and Theory of Computation Major Exam, Sem II , Max 80, Time 2 hr. Name Entry No. Group

Exam Computability and Complexity

Ma/CS 117c Handout # 5 P vs. NP

Computability Theory

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

Languages, regular languages, finite automata

Computability and Complexity

6.045 Final Exam Solutions

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

CSE 135: Introduction to Theory of Computation NP-completeness

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

1 Deterministic Turing Machines

CS278: Computational Complexity Spring Luca Trevisan

Deterministic Time and Space Complexity Measures

Notes for Lecture Notes 2

CISC 4090 Theory of Computation

1 Deterministic Turing Machines

Undirected ST-Connectivity in Log-Space. Omer Reingold. Presented by: Thang N. Dinh CISE, University of Florida, Fall, 2010

Computational Complexity CSCI-GA Subhash Khot Transcribed by Patrick Lin

CSCI 1590 Intro to Computational Complexity

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

Computer Sciences Department

Transcription:

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

Measuring Space When we compute the space used by a TM, we do not count the input (think of input as readonly). We say that TM M runs in space S(n) if for all inputs of length n, M uses at most S(n) cells in total on its work-tapes. Goddard 18: 2

Example: SAT The problem SAT can be decided in linear space. The natural algorithm is to try all assignments. The storage required is to keep track of the assignment, and to do the verification. Both take at most linear space. Goddard 18: 3

Time versus Space Since it takes one time-step to access one memory cell, the number of memory cells a TM accesses cannot exceed the number of steps it runs for: If TM runs in time T (n), then it runs in space T (n). Goddard 18: 4

Infinite Loops We repeat an observation we used before: Fact. Suppose a deterministic TM runs in S(n) space with g tape symbols and q states. If TM runs for longer than qng S(n) steps on input of length n, then it is stuck in an infinite loop. Goddard 18: 5

We Can Assume Space-Bounded TMs Halt Theorem. If L accepted by TM M in space S(n) (S(n) log n), then L is accepted by TM M that runs in space O(S(n)) but always halts. Proof. Build TM M that is almost M, but also has a binary counter that counts the number of steps that M has been going. When counter exceeds above bound, M stops and rejects. A counter that counts up to T takes O(log T ) space. Thus, space for counter is O(log(qng S(n) )) = O(S(n) + log n). So M still runs in O(S(n)) space. Goddard 18: 6

At Most Exponential Blow-Up Another consequence of above fact is: Theorem. If language L is decided in space S(n) (where S(n) log n), then there is constant C such that L is decided in time O(C S(n) ). Goddard 18: 7

Constant Space It turns out that: Fact. The languages decidable in constant space are precisely the regular languages. Goddard 18: 8

Nondeterministic Space NTM M runs in space S(n) if for any input of length n and for any branch, M uses at most S(n) cells on its work-tape. The above results about time and space still apply. Goddard 18: 9

Polynomial Space PSPACE is the set of languages that can be decided in polynomial space; NPSPACE is the set of languages that can be decided in polynomial space by a nondeterministic machine. It is perhaps surprising that these two classes are known to be the same: Goddard 18: 10

Savitch s Theorem Savitch s Theorem. PSPACE = NPSPACE We show that if there is an NTM for language L that uses S(n) space (where S(n) log n), then there is a DTM for L that uses O((S(n)) 2 ) space. The theorem follows since the square of a polynomial is still a polynomial. Goddard 18: 11

Proof of Savitch s Theorem Let M be NTM that always halts and runs in space S(n). Then M runs in at most T = qng S(n) steps for q states and g tape symbols. Re-program M to erase its work-tape and end in a particular state when it accepts. We use configurations and pad each to have length S(n). So there is unique starting configuration C s for given input and unique accepting configuration C a. The question is: is there a sequence of moves from C s to C a? Goddard 18: 12

A Recursive Function Define boolean function f that takes as arguments two configurations C 1 and C 2 and integer i such that f(c 1, C 2, i) is TRUE if M can get from C 1 to C 2 in at most i steps and FALSE otherwise. This can be computed recursively: Goddard 18: 13

The Function f Calculating f(c 1, C 2, i): if i=1 then return onestep(m, C 1, C 2 ) else { for all strings C 3 of length S(n) { if f(c 1, C 3, i/2) TRUE and f(c 3, C 2, i/2) TRUE then return TRUE } failing which: return FALSE } The boolean function onestep determines whether C 1 follows from C 2 by the rules of M. Goddard 18: 14

Conclusion So we build a deterministic machine and ask it to calculate f(c s, C a, T ). (T was the upper bound on M s running time.) How much storage does this use? The recursive program uses a stack, pushing a snapshot of its variables each time it calls itself. Each configuration and hence each snapshot uses O(S(n)) space. The maximum number of snapshots on stack is log T (the depth of the recursion). Since log T is O(S(n)), it follows that space used is O(n 2k ), as claimed. Goddard 18: 15

Examples in PSPACE Deciding whether an RE generates all strings is in PSPACE (discussed in exercises). It can be shown that any language given by a context-sensitive grammar is in PSPACE. Goddard 18: 16

Practice Show that PSPACE is closed under the star operation. Goddard 18: 17

Solution to Practice Suppose A PSPACE. We build algorithm for A. Assume input is w. Then start by calculating for each substring of w whether in A. Then try all possible ways to split w into substrings and see whether in any case all substrings are in A. Extra storage is polynomial. Goddard 18: 18

Logarithmic Space The class L is the set of problems solvable in O(log n) space. The class NL is the set of problems solvable in O(log n) space by an NTM. Example: { 0 n 1 n : n 0 } is in L. The key is that a binary counter can be maintained in logarithmic space. Here the TM counts the 0 s and 1 s, and compares the counts. Goddard 18: 19

The Complexity Chain From earlier result it follows that NL P. So: L NL P NP PSPACE = NPSPACE The only other thing humanity knows about how these classes compare is: L PSPACE Goddard 18: 20

Summary The space complexity of a TM is the space or memory taken as a function of the input length n in the worst case. The class PSPACE is the set of all languages that are decidable by a TM running in polynomial space. It is known that PSPACE = NPSPACE. Examples of languages in PSPACE include ALL re and any context-sensitive language. It is known that P NP PSPACE and it is believed that there is not equality. Goddard 18: 21