420 likes | 434 Views
Space Complexity. Def: Let M be a deterministic Turing Machine that halts on all inputs. Space Complexity of M is the function f:N N, where f(n) is the maximum number of tape cells that M scans on any input of length n. Def: Let f :N N be a function.
E N D
Def: Let M be a deterministic Turing Machine that halts on all inputs. Space Complexity of M is the function f:NN, where f(n) is the maximum number of tape cells that M scans on any input of length n. Def: Let f :NN be a function. SPACE(f(n))={L | L is a language decided by an O(f(n)) space DTM} NSPACE(f(n))={L | L is a language decided by an O(f(n)) space NTM}
0 0 0 … 0 • Eg. SAT is NP-complete. SAT can be solved in linear(O(m)) space. M1=“On input <>, where is a Boolean formula: • For each truth assignment to the variables x1,…xm of . • Evaluate on that truth assignment. • If ever evaluate to 1, ACCEPT; if not, REJECT.” x1 x2 x3… xn
Let ALLNFA={<A> | A is a NFA and L(A)=*} Eg. ALLNFA can be decided in nondeterministic linear space, but not known to be in NP or co-NP. N=“On input <M> where M is an NFA: • Place a marker on the start state of the NFA. • Repeat 2q times, where q is the number of states of M. • Non-deterministically select an input symbol and change the positions of the markers on M’s states to simulate reading that symbol. • Accept if Stages 2 and 3 reveal some string that M rejects, that is, if at some point none of the markers lie on accept states of M. Otherwise, reject.“ Why 2q ?
Savitch’s Theorem(1970): For any function f:NN, where f(n)n, NSPACE(f(n))SPACE(f2(n)). pf: N: an non-deterministic TM deciding a language A in space f(n). Goal: Construct a det TM M deciding A in space f2(n). Let be an input string to N. t: integer; c1,c2: configurations of N on .
CANYIELD(c1,c2,t) accept if starting from c1 N has a branch entering configuration c2 in t steps; o/wrejects. CANYIELD=“On input c1,c2 and t: • If t=1, test whether c1=c2 or c1├ c2, then accept; else reject. • If t>1, then for each configuration cm of N on using space f(n). • Run CANYIELD(c1,cm, ) • Run CANYIELD(cm,c2, ) • If 3 & 4 both accept, then accept; else reject.”
caccept: accept configuration. cstart: start configuration of N on . Select a constant d so that N has no more than 2df(n) configurations using f(n) tape space, n=| |. M=“On input output the result of CANYIELD(cstart, caccept, 2df(n)).” CANYIELD is a recursive procedure: • Recursive depth:log22df(n)=O(f(n)) • Each recursive call of CANYIELD use O(f(n)) space. • Thus, it uses O(f2(n)) space.
PSPACE is the class of languages (or problems) that are decidable in polynomial space on a det. TM. PSPACE= SPACE(nk). Thm: PNP PSPACE=NPSPACE EXPTIME= TIME( ) Def: (PSPACE completeness) A language (or problem) B is PSPACE-complete if it satisfies 2 conditions: • B is in PSPACE, and • Every A in PSPACE is poly-time reducible to B.
universal quantifier, existential quantifier, = ~quantified Boolean formula ~fully quantified Boolean formula
TQBF: given a fully quantified Boolean formula, is it true? Thm: TQBF is PSPACE-complete. pf: • TQBF is in PSPACE: T=“On input : a fully quantified Boolean formula: 1) If has no quantifier, then it is an expression with only constants, so evaluate and accept if it is true; otherwise reject.
If =x, recursively call T on , first with x=0, and then x=1. If either result is accept, then accept; o/w reject. • If =x, recursively call T on with x=0, and x=1. If both results are accept, then accept; o/w reject.” • TQBF is PSPACE-hard: Let A be a language decided by a TM M in space nk for some constant k. Show ApTQBF.
f • M accepts iff is true. • c1,c2: configurations, t: integer; • Construct a formula c1,c2,t • = Cstart,Caccept,h, h=2df(n). • c1,c2,t=m1,(c3,c4){(c1,m1),(m1,c2)} [c3,c4, ] Configuration size: O(f(n)) Recursion depth: lg2df(n)=O(f(n)) Formula size: O(f2(n)) c1,c2,t=m, [c1,m, m,c2, ] What is the formula size? • x {y, z}[...] • x[(x=y)(x=z)...]
Winning Strategies for games: • =x1x2x3…Qxk[] Q represents either a or an quantifier. Two players: player A; player E. Take turns selecting the values of x1,…, xk. • Player A selects values for the variables that are bound to . • Player E selects values for the variables that are bound to . • Player E wins, if is TRUE. • Player A wins, if is FALSE.
Eg. • Let 1 =x1x2x3[(x1 x2) (x2 x3) (x2 x3)] Player E has a winning strategy. • Let 2 =x1x2x3[(x1 x2) (x2 x3) (x2 x3)] Player A has a winning strategy.
FORMULA-GAME={<> | player E has a winning strategy in the formula game associated with }. • Thm: FORMULA-GAME is PSPACE-complete. pf: TQBF exactly when FORMULA-GAME.
Generalized geography:(GG) Eg. • Player 1: moves first. • Player 2: moves second. Player 1 has a winning strategy: Starts at node 1, Player 1 choose 3 Player 2 choose 5 Player 1 choose 6 Player 2 cannot move anywhere Thus, player 1 wins.
GG={<G,b> | player 1 has a winning strategy for the generalized geography game played on graph G starting at node b.} • Thm: GG is PSPACE-complete. Pf: M=“On input <G,b>, G: directed graph; b: a node of G. 0. REJECT if b has no outgoing edge. 1. Remove node b and all arrows touching it to get a new graph G1. 2. For each of the nodes b1,b2,…,bk that b originally pointed at, recursively call M on <G,bi>. 3. If all of these accept, player 2 has a winning strategy in the original game, so REJECT. O/w player 2 doesn’t have a winning strategy, so player 1 has, thus ACCEPT. “
The only space required is for storing the recursion stack. • The level of recursion can be at most m, which is the number of node in G. Each level uses poly. Space, thus in total M uses poly. space.
Next need to show GG is PSPACE-hard: FORMULA-GAMEpGG. • =x1x2x3…Qxk p <G,b> • Player 1 in GG ~ player E in formula game. • Player 2 in GG ~ player A in formula game. In conjunctive normal form.
=x1x2…Qxk[(x1 x2 x3) (x2 x3… ) … (…)] For simplicity, let Q=
1) • If is FALSE, player 2 may win by selecting the unsatisfied clause. • Then any literal that player 1 may pick is FALSE and is connected to the side the diamond that hasn’t been played. • Thus player 2 may choose the node in the diamond, then player 1 cannot move and lose.
2) • If is TRUE, any clause that player 2 picks contains a TRUE literal. • Player 1 choose that TRUE literal. ∵it is true, ∴ it is connected to the side of the diamond that has been chosen. So, player 2 cannot move and lose.
The class of L and NL L=SPACE(log n) NL=NSPACE(log n) Eg. PATH={<G,s,t> | G is a directed graph that has a directed path from s to t}. PATH: Given a directed graph G and two vertices s and t, is there a directed path from s to t?
M • Def: If M is a TM: read only input tape working tape A configuration of M on is a setting of the state, work tape, and the position of the tape heads.
If M runs in f(n) space on , ||=n, then the number of configurations of M on is: gf(n)•f(n) •c •n 2O(f(n)) c: state number. g: number of tape symbol Possible work tape. Head position of input head. State position. Possible state. ••• f(n)
Savitch’s theorem is true for f(n)lgn; note that the definition of configurations is different for small space case. But the proof is the same.
NL-completeness: NL=?L • Def: (log space reducibility) • A log space transducer is a TM with (1)a read–only input tape(2)a write-onlyoutput tape(3)a read/write work tape. • A log space transducer M computes a function f:**, where f(n) is the string remaining on the output tape after M haltswhen it starts with on input tape.f is called log space computable function. • ALB, if A is mapping reducible to B by using a log space computable function. May contain O(logn) symbols.
Def: A language B is NL-complete if • BNL and • Every A in NL is log space reducible to B. Thm: If A LB and B L then AL. Cor: If any NL-complete language is in L then L=NL.
Thm: PATH is NL-complete. • Pf: It has been shown in class that PATHNL. Need to show that for any ANL, ALPATH. Let M be a NTM that decides A in O(log n) space. Given an input , construct a graph G and 2 vertices s and t in log space, where G has a directed path from s to t iff M accepts . V(G): configurations of M on . (c1,c2)E(G) if c1├ c2. s: start configuration, t: accept configuration.
Need to show that reduction operates in logspace. I.e. need to describe G’s vertices and edges in log space. • Each configuration needs c logn space, for some constant c. • Try all c logn bit string and test with M on to see if it is a legal configuration,if yes, put it into vertex set. For any c1, c2, test if c1├ c2 with M on . Takes O(log n) space.
Cor: NL P. PATH P NLP (?) • co-NL = {B : B is in NL} B = {x : x B } • Thm: NL = co-NL.
Thm: NL = co-NL. • Robert Szelepcs’enyi, “The method of forcingfor nondeterminitic automata,” Bull of the EATCS, 33, p.96-100, 1987. • N. Immerman, “Nondeterministic space isclosed under complementation,“ SIAM J. on computing 17, p.935-938, 1988 . Gödel award.
Thm: NL = co-NL. pf: PATH is NL-complete PATH co-NL. If <G,s,t> PATH, then there is no directed path in G from s to t. • Every A co-NL has ALPATH. The rest shows PATH NL.
M=“On input G, s, t: • c0=1 /* counter */ • For i=0 to m-1 /* m=#of vertex */ • ci+1=0 • d=0 • For each node v in G • ••For each node u in G • Non-det. Either skip or perform the following steps: • • Non-det. Follow a path of length i from s, and if non of the nodes met are u, reject. • • Increase d. • • If (u,v) E(G), then increase ci+1 and goto 6 with next v. 11. ••If dci, then reject.
12. For each node u in G 13.Non-det., either skip or perform these steps: 14.•nondeterminitically follow a path of length i from s and if none of the nodes met are u, reject. 15. •If u=t, then reject. 16. •Increase d. 17.If dcm, then reject, otherwise accept.” • The algorithm needs to store ci, d, i, j and a pointer to the head of a path . Thus, it runs in log space. Ai={u : u is reachable from s within i steps.} Ci=|Ai|, s• AiAi+1.
Nondeterminitic Space is Closed under Complement • NSPACE = co-NSPACE. • LNSPACE Lco-NSPACE. • Robert Szelepcse’nyi: “The method of forcing for nondeterministic automaya,” Bull of the EATCS, 33, p. 96-100, 1987. • N. Immerman: “Nondeterministic space in closed under complementation,” SIAM J. on computing, 17, p. 935-938, 1988.
M: a nondeterminitic S(n)-bounded-space TM. • Each configuration of M can be described in O(S(n)). • c0: Initial configuration of M. • RchM,x(t): The number of configurations reachable by computation on input x in at most t steps starting at c0.
M0: Input: x, n, t, u; accept if u is reachable in t=1 steps. • m:=0 • for each configuration v of M do • non-det simulate M on x during at most t steps, checking if v is reached. • if so, then m:=m+1 if M on input x goes from v to u then accept. • if m=n then reject else abort by halting in a nonfinal state.
M1: Input: x; n:=1; t:=0; for t from 1 to t(|x|) do m:=0; for each configuration u do if u is reachable from c0 in t+1 steps then m:=m+1 n:=m Call M0(x,n,t,u)
n is RchM,x(t) for each t. Thm: If S(n)log n and S is space constructible then NSPACE(S) is closed under complementation. pf: Call M1 on x to compute RchM,X(t|x|). For each configuration u call M0 on <x,n,t(|x|),u>. If No accepting configuration accessible, then accept.
Input: M, s, x. Compute initial conf. C0. • NTM accept L(M). I1:=0; for each conf. C do if C0├1C then I1:=I1+1; D:=I1; K:=1; While K<2S(n) {I2:=0 ; for each conf. C2 do { I1:=0; for each conf. C1 do { guess path C0├K C1; if a correct path, I1++; if C1├1 C2 then { if C2 is accept conf., STOP & REJECT; else{I2++; exit inner loop;} } } if I1D, then STOP; } if (D=I2) then ACCEPT; else K++; D:=I2; } I1: Rch(k-1) I2: Rch(k)