Space Complexity Space Is a Computation Resource
Total Page:16
File Type:pdf, Size:1020Kb
Space Complexity Space is a computation resource. Unlike time it can be reused. Computational Complexity, by Fu Yuxi Space Complexity 1 / 43 Synopsis 1. Space Bounded Computation 2. Logspace Reduction 3. PSPACE Completeness 4. Savitch Theorem 5. NL Completeness 6. Immerman-Szelepcs´enyiTheorem Computational Complexity, by Fu Yuxi Space Complexity 2 / 43 Space Bounded Computation Computational Complexity, by Fu Yuxi Space Complexity 3 / 43 Space Bounded Computation Let S : N ! N and L ⊆ f0; 1g∗. We say that L 2 SPACE(S(n)) if there is some c and some TM deciding L that never uses more than cS(n) nonblank worktape locations on inputs of length n. Computational Complexity, by Fu Yuxi Space Complexity 4 / 43 Space Constructible Function Suppose S : N ! N and S(n) ≥ log(n). 1. S is space constructible if there is a Turing Machine that computes the function n 1 7! xS(n)y in O(S(n)) space. 2. S is space constructible if there is a Turing Machine that upon receiving 1n uses exactly S(n)-space. The second definition is slightly less general than the first. Computational Complexity, by Fu Yuxi Space Complexity 5 / 43 Space Bounded Computation, the Nondeterministic Case L 2 NSPACE(S(n)) if there is some c and some NDTM deciding L that never uses more than cS(n) nonblank worktape locations on inputs of length n, regardless of its nondeterministic choices. For space constructible function S(n) we could allow a machine in NSPACE(S(n)) to diverge and to use more than cS(n) space in unsuccessful computation paths. Computational Complexity, by Fu Yuxi Space Complexity 6 / 43 Configuration A configuration of a running TM M with input x consists of the following: I the state; I the content of the work tape; [In the study of space complexity one may always assume that there is one work tape.] I the head positions. We write Cstart for the unique initial configuration. We assume that there is a single accepting configuration Caccept. Computational Complexity, by Fu Yuxi Space Complexity 7 / 43 Configuration Graph A configuration graph GM;x of M with input x is a directed graph: I the nodes are configurations; I the arrows are one-step computations. \M accepts x" iff \there is a path in GM;x from Cstart to Caccept". Computational Complexity, by Fu Yuxi Space Complexity 8 / 43 Reachability Predicate for Configuration Graph Suppose M is an S(n)-space TM. I A vertex of GM;x is described using O(S(jxj)) bits. O(S(jxj)) I Therefore GM;x has at most 2 nodes. 0 There is an O(S(n))-size CNF 'M;x such that for every two configurations C and C , 0 0 'M;x (C; C ) = 1 iff C ! C is an edge in GM;x . 0 0 I 'M;x (C; C ) can be checked by essentially comparing C and C bit by bit. It can be accomplished in both I O(S(n)) time, and I O(log S(n)) space. Computational Complexity, by Fu Yuxi Space Complexity 9 / 43 Space vs. Time Theorem. Suppose S(n): N ! N is space constructible. Then TIME(S(n)) ⊆ SPACE(S(n)) ⊆ NSPACE(S(n)) ⊆ TIME(2O(S(n))): An algorithm proving that NSPACE(S(n)) ⊆ TIME(2O(S(n))) starts by constructing O(S(n)) GM;x in 2 time, and then applies the breadth first search algorithm to GM;x . Computational Complexity, by Fu Yuxi Space Complexity 10 / 43 Space vs. Time Theorem. For all space constructible S(n), TIME(S(n)) ⊆ SPACE(S(n)= log S(n)). 1. Hopcroft, Paul and Valiant. On Time versus Space and Related Problems. FOCS, 1975. Computational Complexity, by Fu Yuxi Space Complexity 11 / 43 Space Complexity Class def [ PSPACE = SPACE(nc ); c>0 def [ NPSPACE = NSPACE(nc ); c>0 L def= SPACE(log(n)); NL def= NSPACE(log(n)): Computational Complexity, by Fu Yuxi Space Complexity 12 / 43 Games are Harder than Puzzles NP ⊆ PSPACE: Computational Complexity, by Fu Yuxi Space Complexity 13 / 43 Example The following problems are in L: def EVEN = fx j x has an even number of 10sg; def PLUS = f(xmy; xny; xm + ny) j m; n 2 Ng; def MULP = f(xmy; xny; xm × ny) j m; n 2 Ng: Computational Complexity, by Fu Yuxi Space Complexity 14 / 43 PATH is in NL PATH = fhG; s; ti j there is a path from s to t in the digraph Gg. Theorem. PATH 2 NL. Proof. Both a node and a counter can be stored in logspace. Computational Complexity, by Fu Yuxi Space Complexity 15 / 43 Universal Turing Machine without Space Overhead Theorem. There is a universal TM that operates without space overhead for input TM's with space complexity ≥ log(n). A universal TM can simulate Mα by recording all the non-blank tape content of Mα in its single work tape. A counter is used to store the location of the reader at x. Some additional space, whose size depends only on Mα, is needed for bookkeeping. Computational Complexity, by Fu Yuxi Space Complexity 16 / 43 Space Hierarchy Theorem Theorem. If f ; g are space constructible such that f (n) = o(g(n)), then SPACE(f (n)) ( SPACE(g(n)): We design V by modifying the universal machine so that I V(x) simulates Mx (x), and I it stops when it is required to use more than g(n) space, and I it negates the result after it completes simulation. If V was executed in f (n) space, then V = Mα for some large enough α so that V can complete the simulation of Mα on α. But then Mα(α) = V(α) = Mα(α). 1. J. Hartmanis and R. Stearns. On the Computational Complexity of Algorithms. Transactions of AMS, 117:285-306, 1965. Computational Complexity, by Fu Yuxi Space Complexity 17 / 43 Logspace Reduction Computational Complexity, by Fu Yuxi Space Complexity 18 / 43 Logspace Reduction A function f : f0; 1g∗ ! f0; 1g∗ is implicitly logspace computable if the following hold: 1. 9c:8x:jf (x)j ≤ cjxjc , 2. fhx; ii j i ≤ jf (x)jg 2 L and 3. fhx; ii j f (x)i = 1g 2 L. Problem B is logspace reducible to problem C, written B ≤L C, if there is an implicitly logspace computable f such that x 2 B iff f (x) 2 C. I Logspace reductions are Karp reductions. [The converse implication is unknown.] I All known NP-completeness results can be established using logspace reduction. Computational Complexity, by Fu Yuxi Space Complexity 19 / 43 Transitivity of Logspace Reduction Lemma. If B ≤L C and C ≤L D then B ≤L D. Let Mf ; Mg be logspace machines that compute x; i 7! f (x)i respectively y; j 7! g(y)j . We construct a machine that, given input x; j with j ≤ jg(f (x))j, outputs g(f (x))j . I The machine operates as if f (x) were stored on a virtual tape. I It stores the address i of the current cell of the virtual tape. I It uses O(log jf (x)j) = O(log jxj) space to calculate g(f (x))j . Computational Complexity, by Fu Yuxi Space Complexity 20 / 43 Logspace Computability A function f : f0; 1g∗ ! f0; 1g∗ is logspace computable if it can be computed by a TM that has a write-once output tape using O(log n) work tape space. Lemma. Implicitly logspace computability = logspace computability. Computational Complexity, by Fu Yuxi Space Complexity 21 / 43 PSPACE Completeness Computational Complexity, by Fu Yuxi Space Complexity 22 / 43 Space Completeness 0 0 A language L is PSPACE-hard if L ≤L L for every L 2 PSPACE. If in addition L0 2 PSPACE then L0 is PSPACE-complete. Computational Complexity, by Fu Yuxi Space Complexity 23 / 43 Quantified Boolean Formula A quantified Boolean formula (QBF) is a formula of the form Q1x1Q2x2 ::: Qnxx :'(x1;:::; xn) where each Qi is one of the two quantifiers 8; 9, x1;:::; xn range over f0; 1g, and ' is a quantifier free Boolean formula containing no free variables other than x1;:::; xn. Let TQBF be the set of true QBFs. Computational Complexity, by Fu Yuxi Space Complexity 24 / 43 Quantified Boolean Formula Suppose ' is a CNF. I ' 2 SAT if and only if 9ex:' 2 TQBF. I ' 2 TAUTOLOGY if and only if 8ex:' 2 TQBF. Computational Complexity, by Fu Yuxi Space Complexity 25 / 43 Stockmeyer-Meyer Theorem. TQBF is PSPACE-complete. 1. Larry Stockmeyer, Albert Meyer. Word Problems Requiring Exponential Time. STOC, 1973. Computational Complexity, by Fu Yuxi Space Complexity 26 / 43 Proof of Stockmeyer-Meyer Theorem TQBF 2 PSPACE. Suppose = Q1x1Q2x2 ::: Qnxx :'(x1;:::; xn). I A counter of length n can be identified to an assignment. I Apply the depth first tree traversal. We actually have a linear space algorithm. Computational Complexity, by Fu Yuxi Space Complexity 27 / 43 Proof of Stockmeyer-Meyer Theorem Let M be a TM that decides L in polynomial space, say S(n) space. ∗ 2 We reduce x 2 f0; 1g to a QBF 'x of size O(S(jxj) ) in logspace such that M(x) = 1 iff 'x is true. 0 0 1. Construct in logspace 0 such that 0(C; C ) is true if and only if C ! C . 0 i 0 2. Let i (C; C ) be true if and only if there exists a path of length ≤ 2 from C to C . It can be defined by the following formula, which is computable in logspace. 00 1 2 1 2 00 1 00 2 0 1 2 9C 8D 8D :((D =C ^ D =C ) _ (D =C ^ D =C )) ) i−1(D ; D ): 2 3.