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

Similar documents
CSCI 1590 Intro to Computational Complexity

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

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

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

Advanced topic: Space complexity

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

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

CSE200: Computability and complexity Space Complexity

SOLUTION: SOLUTION: SOLUTION:

CS151 Complexity Theory. Lecture 4 April 12, 2017

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

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

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

Database Theory VU , SS Complexity of Query Evaluation. Reinhard Pichler

Space is a computation resource. Unlike time it can be reused. Computational Complexity, by Fu Yuxi Space Complexity 1 / 44

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

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

Introduction to Complexity Classes. Marcin Sydow

6.045 Final Exam Solutions

Complexity Theory 112. Space Complexity

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

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

Universal Algebra and Computational Complexity Lecture 1

6.841/18.405J: Advanced Complexity Wednesday, February 12, Lecture Lecture 3

Intelligent Agents. Formal Characteristics of Planning. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University

Notes on Space-Bounded Complexity

Notes on Space-Bounded Complexity

Universality for Nondeterministic Logspace

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

Computability and Complexity CISC462, Fall 2018, Space complexity 1

Lecture 8: Complete Problems for Other Complexity Classes

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

Space and Nondeterminism

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 PSPACE-Completeness

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

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

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

Introduction to Computational Complexity

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

COMPLEXITY THEORY. Lecture 17: The Polynomial Hierarchy. TU Dresden, 19th Dec Markus Krötzsch Knowledge-Based Systems

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

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

Computational Complexity for Algebraists

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

Foundations of Query Languages

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

CSCE 551 Final Exam, Spring 2004 Answer Key

Review of Basic Computational Complexity

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

Computability and Complexity Theory: An Introduction

6.840 Language Membership

CSCI 1590 Intro to Computational Complexity

CSE 555 HW 5 SAMPLE SOLUTION. Question 1.

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

1 Deterministic Turing Machines

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

Lecture 7: The Polynomial-Time Hierarchy. 1 Nondeterministic Space is Closed under Complement

Part I: Definitions and Properties

Space Complexity. Huan Long. Shanghai Jiao Tong University

BBM402-Lecture 11: The Class NP

Introduction to Computational Complexity

Chapter 7: Time Complexity

Complexity (Pre Lecture)

Theory of Computation

Computability Theory. CS215, Lecture 6,

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

Theory of Computation

Lecture 3: Reductions and Completeness

CS154, Lecture 13: P vs NP

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

Lecture 6: Oracle TMs, Diagonalization Limits, Space Complexity

Lecture 22: PSPACE

CS256 Applied Theory of Computation

Apropos of an errata in ÜB 10 exercise 3

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

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

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

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

CS154, Lecture 13: P vs NP

Lecture 5: The Landscape of Complexity Classes

Theory of Computation Lecture Notes. Problems and Algorithms. Class Information

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

Turing Machines and Time Complexity

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

CPSC 421: Tutorial #1

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

1 Computational Problems

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

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

Principles of Knowledge Representation and Reasoning

Notes for Lecture Notes 2

Exam Computability and Complexity

9 Nondeterministic Turing Machines

MACHINE COMPUTING. the limitations

Intractable Problems [HMU06,Chp.10a]

conp, Oracles, Space Complexity

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

CSCI3390-Lecture 14: The class NP

Transcription:

Complexity Theory Complexity Theory Outline Complexity Theory VU 181.142, SS 2018 3. Logarithmic Space Reinhard Pichler Institute of Logic and Computation DBAI Group TU Wien 3. Logarithmic Space 3.1 Computational Power of Log-space 3.2 Log-Space Reductions 3.3 Nondeterministic Log-Space 3.4 Nondeterministic Space vs. Deterministic Time 3.5 Savitch s 3.6 Basic Complexity Classes Revisited 3.7 Immerman-Szelepscényi 13 March, 2018 Reinhard Pichler 13 March, 2018 Page 1 Reinhard Pichler 13 March, 2018 Page 2 Complexity Theory 3. Logarithmic Space 3.1. Computational Power of Log-space Example Log-space computations If a Turing machine with input and output is supposed to operate within space bound O(log(n)), then it may never copy a substantial portion of the input onto its worktapes. Access to the input and control of the machine is based on the following log-space functionalities: maintaining (a constant number of) counters maintaining (a constant number of) pointers to the input storing a constant-size fragment of the input in the state Example The language of palindromes (over an arbitrary alphabet Σ) can be recognized by a 3-string Turing machine M with input within space bound O(log(n)). (There is no output tape needed.) Complexity Theory 3. Logarithmic Space 3.1. Computational Power of Log-space Sketch of a log-space TM for palindromes The 3-string Turing machine M with input implements a loop from 1 to n with n = x. For every i, it checks if x[i] = x[n + 1 i] holds: 1 Tape 2 contains the loop counter i. It is initialized to 1 (in binary) and will be subsequently incremented. 2 Tape 3 contains another counter j which, for every i, controls the cursor movements required for comparing x[i] and x[n + 1 i]: (a) Initialize j to 1. (b) Move the cursor from the front end of x to x[i]. The integer j counts the cursor movements (i.e.: increment j as long as j < i). (c) Store the symbol x[i] in an appropriate state. (d) Reinitialize j to 1. (e) Move the cursor from the rear end of x to x[n + 1 i]. (f) Compare x[n + 1 i] with x[i] (via the state). If x[n + 1 i] = x[i] then increment i and repeat Step 2. Otherwise halt with no. Reinhard Pichler 13 March, 2018 Page 3 Reinhard Pichler 13 March, 2018 Page 4

Complexity Theory 3. Logarithmic Space 3.2. Log-Space Reductions Log-Space Reductions Complexity Theory 3. Logarithmic Space 3.2. Log-Space Reductions Composing Reductions Reductions in the Formale Methoden lecture 2 kinds of reductions: Turing reductions vs. many-one reductions Limit on the resources needed by a reduction: polynomial time vs. logarithmic space reductions. Default for problem reductions in Formale Methoden (e.g., in NP-completeness proofs) : polynomial time, many-one reductions. In this course: We also want to prove completeness results for classes below NP (in particular, completeness in P or NL). = We need reductions in a complexity class below P. From now on: log-space, many-one reductions, denoted as L Remark. All polynomial-time reductions encountered so far (in the Formale Methoden lecture) also work in log-space! In the Formale Methoden lecture, we have established the following chain of reductions: 3-SAT L INDEPENDENT SET L VERTEX COVER. But do reductions compose, i.e., is L transitive? For instance, does 3-SAT L VERTEX COVER hold? If R is a reduction from language L 1 to L 2 and R is a reduction from L 2 to L 3, then the composition R R is a reduction from L 1 to L 3. As R, R are reductions, x L 1 iff R(x) L 2 iff R (R(x)) L 3. It remains to show that R (R(x)) can be computed in O(log n) space where n = x. Reinhard Pichler 13 March, 2018 Page 5 Reinhard Pichler 13 March, 2018 Page 6 Complexity Theory 3. Logarithmic Space 3.2. Log-Space Reductions Logarithmic space consumption Complexity Theory 3. Logarithmic Space 3.2. Log-Space Reductions Logarithmic space consumption (continued) To construct a machine M for the composition R R working in space O(log n) requires care as the intermediate result computed by M R cannot be stored (possibly longer than log n). Solution: simulate M R on input R(x) by remembering the cursor position i of the input string of M R which is the output string of M R. Only the index i is stored (in binary) and the symbol currently scanned but not the whole string. x M R R(x) M R R (R(x)) Initially i = 1 and it is easy to simulate the first move of M R (scanning ). If M R moves the cursor on the input tape to the right, then simulate M R to generate the next output symbol and increment i by one. If M R moves the cursor on the input tape to the left, then decrement i by one and run M R on x from the beginning, counting the output symbols and stopping when the i-th symbol is output. The space required for simulating M R on x as well as M R on R(x) is O(log n) where n = x. The space needed for bookkeeping the output of M R on x is O(log n) as R(x) = O(n k ) and we need only indices stored in binary. Reinhard Pichler 13 March, 2018 Page 7 Reinhard Pichler 13 March, 2018 Page 8

Complexity Theory 3. Logarithmic Space 3.3. Nondeterministic Log-Space Complexity Theory 3. Logarithmic Space 3.3. Nondeterministic Log-Space Nondeterministic Log-Space Motivation The intuition of a complexity class is best understood by looking at natural problems which are complete for this class. The complexity of a problem is only understood if we manage to show its completeness in a natural complexity class. REACHABILITY is NL-complete (w.r.t. log-space reductions), i.e. It can be decided by an NTM in space O(log(n)). Any problem in NL can be reduced to it in log-space. Proof sketch of the NL-membership Let (V, E) be a graph with vertices V = {1,..., n}. Moreover, suppose that we attempt to find a path from vertex 1 to n. We sketch an NTM N with input tape plus 3 worktapes: 1 On tape 2, store the current node i in binary; initially take node 1. 2 On tape 3, guess an integer j n (= next node in the path) and check that (i, j) E. 3 If (i, j) E, then continue at step 2 with j as the new current node. Moreover, if j = n, then halt with yes. If (i, j) E, then halt with no. 4 On tape 4, maintain a counter which checks that we do not construct paths of length n. Reinhard Pichler 13 March, 2018 Page 9 Reinhard Pichler 13 March, 2018 Page 10 Complexity Theory 3. Logarithmic Space 3.3. Nondeterministic Log-Space Complexity Theory 3. Logarithmic Space 3.3. Nondeterministic Log-Space Proof sketch of the NL-hardness Let P be an arbitrary problem in NL, i.e., P is decided by a k-string nondeterministic TM M with input tape within space f (n) = O(log n). Let x be an arbitrary instance of P. From this, we construct the instance R(x) = (G, u, v) of REACHABILITY as follows: The configuration graph G(M, x) of M has as its nodes all possible configurations of M and there is an edge between two nodes (configurations) C 1 and C 2 iff C 1 M C2. Our graph G contains an additional node success and there is an edge from any configuration C with state yes to the success node. Finally, we set u = C 0 = (s,, x,, ɛ,...,, ɛ) (= the initial configuration of M on input x) and v = success. Proof sketch of the NL-hardness (continued) Clearly, this problem reduction is correct, i.e., there exists an accepting computation of M on input x iff there exists a path in graph G from node u = C 0 to node v = success. It remains to show that R(x) can be computed (by a deterministic TM N with input and output) in log-space. Sketch of a log-space TM N. N has 3 worktapes. The first two worktapes are used to store one possible configuration of M at a time. We are assuming that M is a k-string Turing machine with input. Hence, configurations are represented as (q, i, w 2, u 2,..., w k, u k ) where 1 i n + 1 gives the cursor position on the input string. Clearly, position i as well as each string u j, w j fits into log-space. Reinhard Pichler 13 March, 2018 Page 11 Reinhard Pichler 13 March, 2018 Page 12

Complexity Theory 3. Logarithmic Space 3.3. Nondeterministic Log-Space Proof sketch of the NL-hardness (continued) Operating principles of the log-space TM N. In a loop, N generates all possible configurations of M on its first worktape and writes each configuration to the output tape. At the end, also success is output. In a nested loop, N generates all possible configurations of M plus the additional node success on each of its first two worktapes. For every pair of configurations C 1 and C 2, N checks (by using the third worktape) if C 1 M C2 holds. If this is the case, then N writes the pair (= edge) (C 1, C 2 ) to the output. N also outputs all edges (C, success ) if C corresponds to an accepting configuration. Finally, the nodes u = C 0 = (s, 0,, ɛ,...,, ɛ) and v = success are output. Complexity Theory 3. Logarithmic Space 3.4. Nondeterministic Space vs. Deterministic Time Nondeterministic Space vs. Deterministic Time Motivation The NL-hardness proof of REACHABILITY implicitly establishes that NL P holds. This result can be rephrased as follows: a nondeterministic machine M working in space f (n) = log n can be simulated by a deterministic machine N, s.t. the time bound of N is exponential w.r.t. f (n). We want to generalize this relationship between space and time complexity to any reasonable function f (n) log n. The idea of reasonable functions is formalized by the definition of proper complexity functions. Reinhard Pichler 13 March, 2018 Page 13 Reinhard Pichler 13 March, 2018 Page 14 Complexity Theory 3. Logarithmic Space 3.4. Nondeterministic Space vs. Deterministic Time Proper Complexity Functions Definition A function f : N N is a proper complexity function if f is nondecreasing and there is a k-string TM M f with input and output such that on any input x, 1 M f (x) = f ( x ) where is a quasi-blank symbol, 2 M f halts after O( x + f ( x )) steps, and 3 M f uses O(f ( x )) space besides its input. Remark For the definition of complexity classes TIME(f (n)), NTIME(f (n)), SPACE(f (n)), NSPACE(f (n)), we have to avoid the situation that a function f cannot be computed within the time or space it allows. Complexity Theory 3. Logarithmic Space 3.4. Nondeterministic Space vs. Deterministic Time For any proper complexity function f (n) log n, we have Proof sketch NSPACE(f (n)) TIME(c f (n) ) We construct the configuration graph as in the NL-hardness proof of REACHABILITY. We get the following bound on the number of possible configurations represented as (q, i, w 2, u 2,..., w k, u k ) where 1 i n + 1: K (n + 1)( Σ f (n) ) 2(k 1) K 2n( Σ 2(k 1) ) f (n) nc f (n) log n+f (n) 2f (n) 1 c1 c1 c f (n) Hence, deciding if x is a positive instance of problem P reduces to a reachability problem for a graph with at most c f (n) nodes. Reinhard Pichler 13 March, 2018 Page 15 Reinhard Pichler 13 March, 2018 Page 16

Complexity Theory 3. Logarithmic Space 3.5. Savitch s Complexity Theory 3. Logarithmic Space 3.5. Savitch s Savitch s REACHABILITY SPACE(log 2 n). Proof sketch Given a graph G and nodes x, y and i 0, define PATH(x, y, i) as the assertion there is a path from x to y of length at most 2 i. If G has n nodes then any cycle-free path has length n and we can solve reachability in G if we can compute whether PATH(x, y, log n ) holds for any given nodes x, y of G. This can be done using middle-first search. Proof sketch (continued) Idea of the middle-first search. Guess a midpoint of the alleged path and recursively check for the existence of a half-length path from the start to the midpoint and from the midpoint to the finish. Implementation of the middle-first search. function path(x, y, i) /* middle-first search */ if i = 0 then if x = y or there is an edge (x, y) in G then return yes ; else for all nodes z do if path(x, z, i 1) and path(z, y, i 1) then return yes ; return no. Reinhard Pichler 13 March, 2018 Page 17 Reinhard Pichler 13 March, 2018 Page 18 Complexity Theory 3. Logarithmic Space 3.5. Savitch s Complexity Theory 3. Logarithmic Space 3.5. Savitch s Proof sketch (continued) Proof that path(x, y, i) correctly determines PATH(x, y, i) (by induction on i): i = 0. Clearly, path(x, y, 0) correctly determines PATH(x, y, 0). i > 0. path(x, y, i) returns yes iff there is a node z with both path(x, z, i 1) and path(z, y, i 1) holding. By the induction hypothesis, path(x, z, i 1) and path(z, y, i 1) return yes iff there are paths from x to z and from z to y both at most 2 i 1 long. This is the case iff there is a path from x to y at most 2 i long. Proof sketch (continued) The algorithm is started with path(x, y, log n ). The O(log 2 n) space bound is achieved by handling recursion using a stack containing a triple (x, y, i) for each active recursive call. For each node z put (x, z, i 1) onto the stack and call path(x, z, i 1). If this fails, erase (x, z, i 1) and put (x, z, i 1) for the next z. Otherwise erase (x, z, i 1) and continue with (z, y, i 1). As there are at most log n recursive calls active with each taking at most 3 log n space, the O(log 2 n) space bound is achieved. Reinhard Pichler 13 March, 2018 Page 19 Reinhard Pichler 13 March, 2018 Page 20

Complexity Theory 3. Logarithmic Space 3.5. Savitch s Nondeterministic Space vs. Deterministic Space Corollary For any proper complexity function f (n) log n, we have Proof sketch NSPACE(f (n)) SPACE((f (n)) 2 ) To simulate an f (n)-space bounded NTM M on input x, run the previous algorithm on the configuration graph G(M, x). The edges of the graph G(M, x) are determined on the fly by examining the input x. The configuration graph has at most c f (n) nodes. By Savitch s, the algorithm needs at most (log c f (n) ) 2 = f (n) 2 log 2 c = O(f (n) 2 ) space. Complexity Theory 3. Logarithmic Space 3.6. Basic Complexity Classes Revisited Basic Complexity Classes Revisited L NL P NP PSPACE EXPTIME NEXPTIME EXPSPACE Proof In the Formale Methoden lecture, we showed all inclusions except for NL P and PSPACE EXPTIME. These inclusions follow from the more general relationship Remark NSPACE(f (n)) TIME(c f (n) ) It is now clear, why we have not mentioned NPSPACE and NEXPSPACE. Indeed, PSPACE = NPSPACE and EXPSPACE = NEXPSPACE hold. Reinhard Pichler 13 March, 2018 Page 21 Reinhard Pichler 13 March, 2018 Page 22 Complexity Theory 3. Logarithmic Space 3.7. Immerman-Szelepscényi Immerman-Szelepscényi Given a graph G and a node u, the number of nodes reachable from u in G can be computed by an NTM within logarithmic space. More formally, given a graph G, a node u, and an integer m, deciding if the number of nodes reachable from u is m can be done in NL. REACHABILITY is in co-nl. Hence, NL = co-nl. If f (n) log n is a proper complexity function, then NSPACE(f (n)) = co-nspace(f (n)). Complexity Theory 3. Logarithmic Space 3.7. Immerman-Szelepscényi Witnesses for NL-Problems Characterization of positive instances Let P denote a problem in NL. Every positive instance x of P can be characterized by a witness y, s.t. the witness y may be polynomially big, but we can check if y is a witness by a sequence of local consistency checks each requiring only logarithmic space. REACHABILITY (G, u, v) is a positive instance of REACHABILITY if there exists a path π from u to v s.t. the path π = (z 0, z 1,..., z k 1, z k ) with u = z 0, v = z k, and k n with n = V may be polynomially big, but it suffices to check for every pair of neighbouring nodes z i, z i+1 that an arc (z i, z i+1 ) indeed exists in E. Reinhard Pichler 13 March, 2018 Page 23 Reinhard Pichler 13 March, 2018 Page 24

Complexity Theory 3. Logarithmic Space 3.7. Immerman-Szelepscényi co-nl-membership of REACHABILITY Proof Idea What shall a witness look like that there is no path from u to v? Idea. Let S(k) denote the set of nodes reachable from u in k steps (with 0 k n 1) and suppose that we know m = S(n 1). Then a witness y for not-reachability consists of m paths from u to (pairwise distinct) vertices v 1,..., v m V, s.t. v i v for all i. Logspace verification of such witnesses for j := 1, 2,..., n do { guess flag; /* meaning: flag = true if v j S(n 1) */ if flag then { decrement m; guess a path π from u to v j of length n 1; check that v v j ; } } check that m = 0; Complexity Theory 3. Logarithmic Space 3.7. Immerman-Szelepscényi Counting the Number of Reachable Nodes in NL Idea of the Algorithm The strategy is to compute values S(1), S(2),..., S(n 1) iteratively and recursively, i.e. S(i) is computed from S(i 1). S(0) := 1; for k := 1, 2,..., n 1 do { l := 0; for j := 1, 2,..., n do guess flag; /* meaning: flag = true if v j S(k) */ if flag then { check that v j S(k); increment l; } else check that v j S(k); } S(k) := l; } Reinhard Pichler 13 March, 2018 Page 25 Reinhard Pichler 13 March, 2018 Page 26 Complexity Theory 3. Logarithmic Space 3.7. Immerman-Szelepscényi Idea of the Algorithm (continued) Clearly, we can check v j S(k) in NL. It remains to show that we can also check v j S(k) in NL in the inner loop of our algorithm. When checking v j S(k), we already know m = S(k 1). A witness y for v j S(k) consists of m paths from u to vertices v 1,..., v m V, s.t. v i v j and (v i, v j ) E. Below we give a verification of witness y that requires only logspace. for v := 1, 2,..., n do { guess flag; /* meaning: flag = true if v S(k 1) */ if flag then { decrement m; guess a path π from u to v of length k 1; check that v v j and (v, v j ) E; } } check that m = 0; Complexity Theory 3. Logarithmic Space 3.7. Immerman-Szelepscényi Learning Objectives Computational power of log-space Reductions in this lecture: log-space, many-one Composability of reductions NL-completeness of REACHABILITY (configuration graph) Savitch s (middle-first search) Basic relationships (inclusions) between complexity classes Immerman-Szelepscényi Reinhard Pichler 13 March, 2018 Page 27 Reinhard Pichler 13 March, 2018 Page 28