<<

Computational Complexity Theory, Fall 2010 September 3 Lecture 4: Space and Time

Lecturer: Kristoffer Arnsfelt Hansen Scribe: Camilla Gravgaard

How to halt a space bounded TM Definition 1 (Configuration). A configuration of a consists of • Internal state. • Positions of tape heads. • Content of all writable tapes. Theorem 2. Suppose S(n) ≥ log(n). Let M be an S(n) space-bounded TM. Then there is a O(S(n)) space bounded TM M 0 that always halts with (M) = L(M 0). Proof. First we give an upper bound on the number of possible configurations of a TM M. • Number of configurations of M ≤ |Q| · (n + 2)S(n) · |Γ|S(n) • In general, number of configurations of M with using less than k cells is at most k |Q| · (n + 2) · k · |Γ| ≤ alog2(n)+k+b for some constants a and b. Operation of M 0 : • Keeping a counter in a-ary, we simulate of M, and increase the counter with each step of M. • Whenever M uses a new cell on the work tape for the first time, we reset the counter to 0.

• After each simulated step, we see if the counter uses more than log2(n) + k + b digits, where k is the number of worktape cells currently in use, then halt and reject.

By our calculation, if the counter in fact uses more than log2(n) + k + b digits, then we know that the machine has repeated a configuration, and has thus entered an infinite loop. We can thus safely reject.

Observation 3. The above proof does not work for sublogarithmic space-bounds. The result, how- ever, still remains true, by a result of Sipser (1978). Definition 4 (Space constructability). We say S(n) is space constructable iff there is a O(S(n)) space-bounded Turing machine that on input 1n halts, leaving the string 1S(n) on the work tape. Definition 5 (Complexity classes). For any function S(n) we define the following complexity classes. • DSPACE(S(n)) = class of language accepted by a O(S(n)) space bounded Turing machine. • NSPACE(S(n)) = class of language accepted by a O(S(n)) space bounded nondeternimistic Tuting machine.

1 The

Theorem 6. Let S2(n) ≥ log(n) be space-constructable. If S1(n) = o(S2(n)), then

DSPACE(S1(n)) ( DSPACE(S2(n))

Proof. We construct TM M, such that L(M) ∈ DSPACE(S2(n)) \ DSPACE(S1(n)). On input x, |x| = n, the machine operates as follows.

1. Use space constructibility of S2 to measure out S2(n) cells of worktape. We use this in the following ways:

• enforce that the remaining computation stays within the S2(n) cells. Halt and reject if simulation exceeds the bound • Use it for a binay counter to run the remaining computation for at most 2log2(n)+S2(n) steps. If time runs out halt and accept.

2. Check if x = 0i1w, where w is a encoding of a TM with read-only input and a single worktape. If not, halt and reject.

3. Simulate M 0 on input x. If M 0 accepts, then reject. If M 0 reject, then accept.

Analysis: 0 Clearly M is O(S2(n)) space bounded, by construction. Assume now that M is a O(S1(n)) space bounded TM. Let w be an encoding of M 0 and look at the computation of M with inputs of the form x = 0i1w. 0 Then M will simulate M on input x. Since S1(n)=o(S2(n)) then simulation will not ex- 0 log (n)+O(S (n)) ceed spece bound for all sufficiently large i. M has 2 2 1 configurations. Since S1(n) log (n)+S (n) =o(S2(n)), for sufficiently large i this is less than 2 2 2 . Thus for all sufficiently large i, if the simulation runs for 2log2(n)+S2(n) steps, we know for sure that M 0 has entered an infinite loop. In this case we halt and accept. If M 0 halts, M 0 will give the opposite answer of M. Thus in conlusion, for all sufficiently large i, M and M 0 differ on input 0i1w.

The reachability method Theorem 7. For T (n) ≥ n, S(n) ≥ log(n),

(a) NTIME(T (n)) ⊆ DSPACE(T (n)),

(b) NSPACE(S(n)) ⊆ DTIME(2O(S(n))).

Proof. a) Observe first that DTIME(T (n)) ⊆ DSPACE(T (n)), since the Turing machine cannot use more tape cells than the number of computation steps. Now, assume first T (n) is time constructible, and let M be a T (n) time bounded TM. Then we first measure out T (n) tape cells. Let c be a constant such that M has at most c nondeterministic choices at every step. We then iterate through all strings in {1, . . . , c}T (n) on the work tape, reusing space each time. For each string we simulate M using the string as the nondeterministic choices. If M accepts, then accept. Otherwise continue with the next string. If M did not accept during any of these runs, we reject. The space usage is clearly O(T (n)).

2 To get rid of the time constructibility assumption, we can simply try T = 1,T = 2,T = 3,... , as a substitute for T (n) until all simulations of length T suceeds. Alternative view: We can see the computation of a non-deterministic Turing machine as a tree of depth T (n), and we are basically doing a depth first search in the tree searching for an accepting configuration at a leaf. b) Recall that a configuration of a Turing machine consists of the following information: The internal state, position of all tape heads, and content of all writable tapes. If M is S(n) ≥ log(n) space bounded then there are 2O(S(n)) configurations, and we can encode these by strings of length O(S(n)). We now define the configuration graph of M as the directed graph G = (V,E) where V is all the configurations and there is directed edges E between configurations if the machine can move between them in one step. Now, assume that S(n) is space-constructible, then G can be generated in time 2O(S(n)). We need to check if there is a path from the initial configuration to an accepting configuration doing graph traversing (for ex. using depth first search). This takes polynomial time in the size of G, and therefore the total time usage is 2O(S(n)). To get rid of the space-constructibility assumption, we run the for S = 0, 1, 2,... , restricting to configurations using S cells of work tape, until it works. That is, until for all configurations generated, M does not move to a configuration that uses more than S cells of work tape. The total time for doing this remains 2O(S(n)).

Now we have a hierarchy of classes:

L = DSPACE(log(n)) ⊆ b NL = NSPACE(log(n)) ⊆ PTIME = DTIME(nO(1)) ⊆ a NP = NTIME(nO(1)) ⊆ b PSPACE = DSPACE(nO(1)) ⊆ O(1) EXP = DTIME(2n ) ⊆

O(1) a NEXP = NTIME(2n ) ⊆ O(1) EXPSPACE = DSPACE(2n ).

Savitch’s Theorem Theorem 8. Let S(n) ≥ log(n). Then

NSPACE(S(n)) ⊆ DSPACE(S(n)2).

3 Proof. We want to find a path in the configuration graph of M from the initial configuration s to an accepting configuration t. Now assume that S(n) is space constructible and encode the configurations by strings of length O(S(n)). We define the predicate reach(u, v, i) = Yes iff there is a path from u to v in at most 2i steps. We now want to compute reach(s, t, c · S(n)) for some constant c. Now note that we can write:

reach(u, v, i) = Yes iff ∃w : reach(u, w, i − 1) = Yes ∧ reach(w, v, i − 1) = Yes.

The implementation of reach by a recursive algorithm has the idea of reusing space. To do the recursion, we run over all string w encoding configurations and call recusively twice. Doing this we get O(S(n)) levels of recursion. Doing this, in each level we only need to store 3 configurations u, v and w and the depth i, taking space O(S(n)). The space used is then: S(n) levels of recursion times S(n) space which is a total of O(S(n)2) space usage. Again, we can get rid of the assumption of space-constructibility, by trying all S = 0, 1, ... until the computation is successful.

4