1 Slides: Asaf Shapira & Oded Schwartz; Sonny Ben-Shimon & Yaniv Nahum. Sonny Ben-Shimon & Yaniv...
-
date post
21-Dec-2015 -
Category
Documents
-
view
235 -
download
3
Transcript of 1 Slides: Asaf Shapira & Oded Schwartz; Sonny Ben-Shimon & Yaniv Nahum. Sonny Ben-Shimon & Yaniv...
11
Slides: Asaf Shapira & Oded Schwartz;Slides: Asaf Shapira & Oded Schwartz;
Sonny Ben-Shimon & Yaniv Nahum.Sonny Ben-Shimon & Yaniv Nahum.
Notes: Leia Passoni, Reuben Sumner, Yoad Notes: Leia Passoni, Reuben Sumner, Yoad Lustig & Tal Hassner.Lustig & Tal Hassner.
(from Oded Goldreich’s course lecture notes) (from Oded Goldreich’s course lecture notes)
22
IntroductionIntroduction
This lecture covers:This lecture covers: Space ComplexitySpace Complexity
Non-Deterministic spaceNon-Deterministic space
33
Complexity FunctionsComplexity FunctionsDef:Def: A function A function ff is called is called constructibleconstructible if it if it
satisfies the following conditions:satisfies the following conditions:
PositivePositive: : f: Nf: N+ + N N++
MonotoneMonotone: : f(n+1) f(n+1) f(n) f(n) for all for all nn
ConstructiveConstructive: : a Turing Machine a Turing Machine MMff that, on input that, on input xx, outputs a string of , outputs a string of size size f(|x|)f(|x|), in time , in time O(|x|+f(|x|)),O(|x|+f(|x|)), and in and in space space O(f(|x|))O(f(|x|))
4.1
44
Constructible functionsConstructible functions
Many “popular” complexity functions, e.g. Many “popular” complexity functions, e.g. nn,, log(n) log(n), , nn22, , n!n! satisfy the above criteria satisfy the above criteria
Odd things may occur, in regard to Odd things may occur, in regard to relations between complexity classes, if relations between complexity classes, if we don't choose these functions properlywe don't choose these functions properly
NoteNote:: We therefore use time constructible We therefore use time constructible functions for time bound and space functions for time bound and space constructible functions for space boundconstructible functions for space bound
4.2
55
Space Complexity - The Space Complexity - The model: model:
3-tape Turing machine3-tape Turing machine::
1.1. Input Tape – Read OnlyInput Tape – Read Only
2.2. Output tape – Write only Output tape – Write only [Omitted for decision problems][Omitted for decision problems][Usually unidirectional][Usually unidirectional]
3.3. Work tape – Read & WriteWork tape – Read & Write
4.3
Enables sub linear space
Length of which corresponds to space usage
66
What kind of What kind of TMTM should we should we use?use?
Any multi-tape Any multi-tape TMTM can be simulated can be simulated by an ordinary by an ordinary TMTM with a polynomial with a polynomial loss of efficiencyloss of efficiency
Hence, from here on, a Hence, from here on, a TMTM will refer will refer to the to the 33 tape tape TMTM described above described above
77
DSPACEDSPACE - Definition - DefinitionFor every TM, For every TM, MM, and input , and input xx::
WWMM(x) = (x) = The index of the rightmost cell on the The index of the rightmost cell on the work-tape scanned by work-tape scanned by MM on on xx
SSMM(n) = max(n) = max|x|=n|x|=n W WMM(x) (x)
LL(x) = 1 if x(x) = 1 if xL, 0 otherwiseL, 0 otherwise
DSPACE(S(n)) =DSPACE(S(n)) =
{L|{L| DTM M, DTM M, x M(x)= x M(x)= LL(x) and (x) and n Sn SMM(n) (n) S(n) } S(n) }
Maximal amount of space used by
M for input of length n
88
Sub-Logarithmic SpaceSub-Logarithmic Space
DSPACE(O(1))DSPACE(O(1)) is equivalent to the set of is equivalent to the set of regular languages.regular languages.
Do we gain any strength by having sub-Do we gain any strength by having sub-logarithmic sapce?? Or formally…logarithmic sapce?? Or formally…
DSAPCE(o(log(n))) DSAPCE(o(log(n))) DSPACE(O(1)) ? DSPACE(O(1)) ? or is itor is it DSPACE(o(log(n))) = DSPACE(O(1)) ?DSPACE(o(log(n))) = DSPACE(O(1)) ?
4.4
99
Thm:Thm: DSPACE(o(log(n)))DSPACE(o(log(n))) is a proper superset is a proper superset of of DSPACE(O(1))DSPACE(O(1))
Proof:Proof: We will construct a language We will construct a language LL
s.t. s.t. LLDSPACE(loglog(n))DSPACE(loglog(n)), however,, however,
LLDSPACE(O(1))DSPACE(O(1)), which will prove the , which will prove the theorem (theorem (log(log(n)) = o(log(n))log(log(n)) = o(log(n))) .) .
DSPACE(o(log(n))) DSPACE(o(log(n))) DSPACE(O(1))DSPACE(O(1))
1010
Proof (contd.) - Definition of Proof (contd.) - Definition of LL
L = {xL = {xkk|k|kN,xN,xkk=B=Bkk’’00$B$Bkk
’’11$B$Bkk
’’22$…$B$…$Bkk
’’ (2 (2
kk-1)-1)$}$}
where: where:
BBkk’’ii == Binary representation of Binary representation of ii of length of length kk..
For example:For example:
xx22 = 00$01$10$11$ = 00$01$10$11$
1111
Claim 1Claim 1:: LLDSPACE(O(1))DSPACE(O(1)) (Regular-(Regular-Languages)Languages)
ProofProof:: By using the “Pumping Lemma” By using the “Pumping Lemma”
Claim 2Claim 2:: LLDSPACE(loglog(n))DSPACE(loglog(n))
ProofProof:: We will show an algorithm for We will show an algorithm for deciding deciding L L that uses that uses loglog(n)loglog(n) space. space.
Proof (contd.)Proof (contd.)
1212
1) Check that the first block is all 1) Check that the first block is all 00’s ’s and that the last is all and that the last is all 11’s.’s.
2) For any two consecutive blocks, 2) For any two consecutive blocks, check that the second is the binary check that the second is the binary increment of the first.increment of the first.
Clearly (1) can be done in constant space, and (2) in log(k) space which is loglog(n) space, as n=|xk|=(k+1)2k
The The wrongwrong way of proving way of proving Claim 2Claim 2
works if works if xxLL
this might use this might use moremore then loglog(n) if x then loglog(n) if xkk L (e.g. 0 L (e.g. 0mm$1$1mm$) $) m=n/2 - 1m=n/2 - 1
1313
The The correctcorrect solution solutionm = 1m = 1whilewhile ( (truetrue) {) {
check that the last check that the last mm bits of the first block are bits of the first block are all all 0’s0’s
check that the last check that the last mm bits of the bits of the BBkk’’i i blocks form blocks form
an increasing sequence mod an increasing sequence mod 22mm, and that each , and that each block has block has mm bits. bits.
check that the last check that the last mm bits of the last block are all bits of the last block are all 1’s1’s
if you found an error, return if you found an error, return falsefalse if if mm is the exact size of is the exact size of BBkk
’’i i return return truetrue..
m = m +1m = m +1}}
1414
The The correctcorrect solution – An solution – An ExampleExample
m=2m=2, 2 left bits increasing mod , 2 left bits increasing mod 2222=4=4
000$001$010$011$100$101$110$111$
000$001$010$011$100$101$110$111$
000$001$010$011$100$101$110$111$
m=1, 1 left bits increasing mod 21=2
The entire series is increasing return true
m=3, 3 left bits increasing mod 23=8
input: 000$001$010$011$100$101$110$111$
1515
Sub-LogarithmSub-Logarithm
Conclusion:Conclusion:
L L Space(O(loglog(n)))\Space(O(1)) Space(O(loglog(n)))\Space(O(1)) DSPACE(o(log(n))) DSPACE(o(log(n))) DSPACE(O(1)) DSPACE(O(1))
In fact, the above claim doesIn fact, the above claim does
not work for not work for o(loglog(n))o(loglog(n)), that is:, that is:
DSPACE(o(loglog(n))=DSPACE(O(1))DSPACE(o(loglog(n))=DSPACE(O(1))
1616
Configuration - DefinitionConfiguration - Definition DefDef: A : A configurationconfiguration of a of a TMTM MM, is a , is a
complete description of its state at complete description of its state at a computation stage, comprising: a computation stage, comprising:
1.1. the state of the state of MM ( (range range |Q|QMM||))2.2. contents of the worktape (contents of the worktape (rangerange
22s(n)s(n)))3.3. the head position on the input tape the head position on the input tape
((rangerange nn))4.4. the head position on the worktape the head position on the worktape
((rangerange s(n)s(n)).).
1717
#Configuration – An upper #Configuration – An upper boundbound
Let Let CC be the number of possible be the number of possible configuarations of a TM configuarations of a TM MM..
C |QM|* 2s(n) * n * s(n)
number of number of statesstates
contents contents of the of the
worktapeworktapehead head
position on position on input tapeinput tape
head head position on position on worktapeworktape
1818
Relation between time and Relation between time and space space
Thm:Thm: s(n) ≥ log(n)s(n) ≥ log(n)
DSPACE(s(n)) DSPACE(s(n)) Dtime(2 Dtime(2O(s(n))O(s(n))))
Proof:Proof:
For every For every L L DSPACE(s(n)) DSPACE(s(n)),There is a TM,There is a TM MM that that uses no more thanuses no more than O(s(n))O(s(n)) space on input space on input xx. .
the number of configurations of the number of configurations of M M 22O(s(n))O(s(n)) . .
if if MM does not stop after does not stop after 22O(s(n))O(s(n)) steps, it must steps, it must pass through the same configuration twice, pass through the same configuration twice, which implies an infinite loop. which implies an infinite loop.
4.5
1919
How to Make TMs halt?How to Make TMs halt?Thm:Thm: For For s(n)s(n) ≤ log(n)≤ log(n), for any , for any TMTM, , MMDSPACE(s(n))DSPACE(s(n)), ,
there is a there is a TMTM,, M’M’DSPACE(O(s(n)) DSPACE(O(s(n)) s.t.s.t. L(M’)=L(M)L(M’)=L(M),, and and M’M’ always halts. always halts.
ProofProof:: By simulation. Given By simulation. Given xx,, M’M’ computes the computes the maximal number of configurations maximal number of configurations CC -- that -- that takes takes s(|x|)s(|x|) space. space.
Now Now M’M’ simulates simulates MM. If it arrives at an answer . If it arrives at an answer in less than in less than CC steps, it returns it. steps, it returns it.
Otherwise (Otherwise (MM is in an infinite loop) is in an infinite loop) M’M’ returns returns ‘no’‘no’..
This stage also takes This stage also takes s(|x|)s(|x|), so the total is, so the total is O(s|O(s|x|)x|)..
4.6
2020
Space Hierarchy Space Hierarchy Thm:Thm: for any for any ss11(n), s(n), s22(n)(n), if, if s s11(n) (n) log(n) log(n),, s s22(n) (n)
is space-constructible andis space-constructible and s s11(n)=o(s(n)=o(s22(n)) (n)) thenthen
DSPACE(sDSPACE(s11(n)) (n)) ≠≠ DSPACE(s DSPACE(s22(n))(n))
Proof:Proof: By diagonalization. We construct a By diagonalization. We construct a language language LL, such that , such that L L DSPACE(s DSPACE(s22(n))(n)), but , but LL can’t be recognized by any can’t be recognized by any TMTM using using ss11(n)(n) space:space:
Let Let cc00 be a constant, be a constant, 00 c c00 11. .
L =L = { { x | x = <M> 01*x | x = <M> 01*, , |<M>| |<M>| c c00ss22(|x|)(|x|),, M M
rejects rejects x x using using ≤≤ cc00ss22(|x|)(|x|) space space }}
4.7
2121
Space Hierarchy Space Hierarchy Claim:Claim: L L DSPACE(s DSPACE(s22(n))(n))
Proof:Proof: By a straightforward algorithm. By a straightforward algorithm.
1.1. check if check if xx is of the right form. ( is of the right form. (O(1)O(1) space) space)
2.2. compute compute S:= cS:= c00ss22(|x|)(|x|).. ((ss22(|x|)(|x|) space) space)
3.3. check that check that |<M>| |<M>| c c00ss22(|x|)(|x|). (. (log(S)log(S) space) space)
4.4. simulate simulate MM..if the bound if the bound SS has been exceeded – reject. has been exceeded – reject.if if MM rejects rejects xx – accept, else reject. – accept, else reject.
Altogether Altogether O(sO(s22(|x|)) (|x|)) space as claimed.space as claimed.
2222
Space Hierarchy Space Hierarchy
Claim:Claim: L L DSPACE(s DSPACE(s11(n))(n))
Proof:Proof: We show that for every We show that for every TMTM M M of space of space complexitycomplexity s s11(n)(n),, L(M) L(M) L L..
ss11(n)=o(s(n)=o(s22(n))(n)) nn00. s. s11(n(n00) ) c c00**ss22(n(n00)). .
Assume, by way of contradiction, a Assume, by way of contradiction, a TMTM MM00 of space complexityof space complexity s s11(n)(n), s.t. , s.t. |<M|<M00>| >| cc00**ss22(n(n00)), accepting, accepting L L..
Observe Observe MM00 result on the inputresult on the input stringstring0 0 1
0 01 n MM
2323
L L DSPACE(s DSPACE(s11(n)) – Proof (n)) – Proof contd.contd.
1.1. if if MM00 accepts accepts xx, then by definition , then by definition x x LL..
2.2. if if MM00 rejects rejects xx, then since , then since |<M|<M00>| >| cc00ss22(n(n00)), and , and MM0 0 onon xx uses at most uses at most ss11(n(n00)) c c00**ss22(n(n00)) space, it must be that space, it must be that x x L L..
In any case this is a contradiction to In any case this is a contradiction to the fact thatthe fact that M M0 0 acceptsaccepts L L..
2424
Non Deterministic Space Non Deterministic Space
DefDef:: AA non-deterministic Turing non-deterministic Turing machine - NDTMmachine - NDTM is ais a TMTM with a non with a non--ddeterministic transition function, eterministic transition function, having a work tape, a read-only input having a work tape, a read-only input tape, and a unidirectional write-only tape, and a unidirectional write-only output tape.output tape.
The machine is said to The machine is said to acceptaccept input input xx if there exists a computation ending if there exists a computation ending in an accepting state.in an accepting state.
5.1
2525
DefDef: On-line / Off-line TM: On-line / Off-line TM
An An offlineoffline ((onlineonline) non-deterministic ) non-deterministic TM has a work tape, a read-only TM has a work tape, a read-only input tape, a unidirectional write-input tape, a unidirectional write-only output tape, and a only output tape, and a two-waytwo-way ((one-wayone-way) read-only ) read-only guess tapeguess tape..
The machine is said to The machine is said to acceptaccept input input xx if there exists a content if there exists a content yy to the to the guess tape that causes the guess tape that causes the machine’s computation to end in machine’s computation to end in an accepting state.an accepting state.
2626
NspaceNspaceonon, , NspaceNspaceoffoff
Def:Def: NspaceNspaceonon(S) =(S) = {{ L |L | there exist an there exist an online-NDTM online-NDTM MMLL, which uses , which uses ≤ S(|x|)≤ S(|x|)
space, that accepts space, that accepts xx iff iff xxL L }}
Def:Def: NspaceNspaceoffoff(S) = (S) = {{ L | L | there exist an there exist an offline-NDTMoffline-NDTM MMLL, which, which uses uses ≤≤ S(|x|)S(|x|)
space, that accepts space, that accepts x x iff iff xxLL }}
2727
NDTM = Online-NDTMNDTM = Online-NDTMClaim:Claim: the NDTM model is equivalent to the the NDTM model is equivalent to the
online-NDTM modelonline-NDTM modelProof:Proof: We show that a language We show that a language LL is is
decidable by a NDTM in time decidable by a NDTM in time O(T)O(T) and and space space O(S) iff LO(S) iff L is decidable by an online- is decidable by an online-NDTM with same time and space bounds.NDTM with same time and space bounds.
Use the guess string Use the guess string yy to determine which to determine which transition function to take every step.transition function to take every step.
Guess the content of the next cell in the Guess the content of the next cell in the guess string when read. Remember the guess string when read. Remember the last step’s guessed letter (using internal last step’s guessed letter (using internal state) when guess-tape-head doesn’t state) when guess-tape-head doesn’t move.move.
5.2
2828
NspaceNspaceon on vs. Nspacevs. Nspaceoffoff
Thm:Thm: NspaceNspaceonon(S) (S) Nspace Nspaceoffoff(log(S))(log(S))
We’ll simulate an online-NDTMWe’ll simulate an online-NDTM MMonon that uses space that uses space SS, using an offline-, using an offline-NDTMNDTM MMoffoff that uses space that uses space log(S)log(S)..
MMoffoff guesses a sequence of guesses a sequence of configurations of configurations of MMonon and then and then validates it to be an accepting runvalidates it to be an accepting run
5.3
2929
NspaceNspaceon on vs. Nspacevs. Nspaceoffoff
The guess string has blocks, each The guess string has blocks, each representing a configuration [of representing a configuration [of lengthlength (O(S)) (O(S))]]
with with ≤ 2≤ 2O(S)O(S) blocks blocks(any valid sequence of configurations (any valid sequence of configurations with more blocks, must have the with more blocks, must have the same configuration twice, therefore same configuration twice, therefore can be replaced by a shorter guess)can be replaced by a shorter guess)
guess string doesn’t count in
the space of MMoffoff
3030
NspaceNspaceon on vs. Nspacevs. Nspaceoffoff
MMoffoff will validate that: will validate that: The first block is a legal The first block is a legal
starting configuration.starting configuration. Last block is a legal accepting Last block is a legal accepting
configuration.configuration. Every block can result by a Every block can result by a
legal move applied to legal move applied to previous block previous block (carried out two (carried out two consequetive blocks at a time)consequetive blocks at a time)
3131
NspaceNspaceon on vs. Nspacevs. Nspaceoffoff
The (supposedly) configuration strings:The (supposedly) configuration strings:... $aaaabcaa$ aaaabchaa $ aaaabxaha $aaaabcaa$aaaab$...
$aaaabchaa$
$aaaabxaha$
1. Check (almost) all symbols in strings are identical, and string lengths identical.
2. Check that symbols marked with head position in 1st configuration transforms to a legal threesome on the 2nd.
O(log(|Con|))
O(1)
3232
NspaceNspaceon on vs. Nspacevs. Nspaceoffoff
The working tape holds a counter of The working tape holds a counter of the location in the configuration the location in the configuration checked - checked - log(O(S))log(O(S)), and , and O(1)O(1) additional space for the validation. additional space for the validation.
A counter for the number of A counter for the number of configuration checked - configuration checked - O(S)O(S) - is - is not not necessary!necessary!
3333
NspaceNspaceon on vs. Nspacevs. Nspaceoffoff
Note that this simulation can’t be Note that this simulation can’t be done by the online machine, as it has done by the online machine, as it has to read forwards & backwards on the to read forwards & backwards on the guess tape (block size being a guess tape (block size being a function of function of nn).).
3434
NspaceNspaceon on vs. Nspacevs. Nspaceoffoff
Thm:Thm: NspaceNspaceoffoff(S) (S) Nspace Nspaceonon(2(2O(S)O(S)))
Proof:Proof: The proof of this theorem The proof of this theorem also uses simulation of one also uses simulation of one machine using the other.machine using the other.
3535
Savitch’s TheoremSavitch’s TheoremThm:Thm: NL = Nspace(log(n)) NL = Nspace(log(n))
DSPACE(logDSPACE(log22(n))(n)) We later generalize the theorem to read:We later generalize the theorem to read: S(n)S(n)log(n)log(n) Nspace(S) Nspace(S) DSPACE(S DSPACE(S22))
Def:Def: aa Configuration GraphConfiguration Graph is a graph that, is a graph that, given a TMgiven a TM MM which works in space which works in space SS on on an input an input xx, has one vertex for every , has one vertex for every possible configuration of possible configuration of MM’s ’s computation on computation on xx, and an edge , and an edge (u,v) (u,v) ifif M M can change move from can change move from uu to to vv..
5.4
3636
Savitch’s Thm - Reducing Savitch’s Thm - Reducing Acceptance to ReachabilityAcceptance to Reachability
If there is more then one accepting If there is more then one accepting configuration, another vertex configuration, another vertex tt is added, is added, with edges with edges (u,t)(u,t) for all accepting for all accepting configurations’ vertices configurations’ vertices uu..
The starting configuration’s vertex is The starting configuration’s vertex is named named ss..
The question of The question of MM accepting accepting xx reduces to reduces to anan s-t reachability s-t reachability problem on the problem on the configuration graph.configuration graph.
We next show reachability in We next show reachability in DSPACE(logDSPACE(log22(n))(n))..
3737
Savitch’s TheoremSavitch’s TheoremThe TrickThe Trick: : If there is a path from vertex If there is a path from vertex uu to to vv of size of size d>0d>0, then there must be a , then there must be a
vertex vertex zz, s.t. there is a path from , s.t. there is a path from uu to to zz, shorter then , shorter then d/2d/2, and a path , and a path from from zz to to uu, shorter then , shorter then d/2d/2. .
Note:Note: As we try to save space, we As we try to save space, we
can afford trying ALL possible can afford trying ALL possible zz’s. ’s. Time complexity does not matter.Time complexity does not matter.
3838
The AlgorithmThe AlgorithmBooleanBoolean PATH(a,b,d)PATH(a,b,d) { {
if there is an edge from if there is an edge from aa to to bb then then return return TRUETRUE
else {else {if if d=1d=1 return return FALSE FALSEfor every vertex for every vertex vv (except (except a,b) a,b) { {
if if PATH(a,v, PATH(a,v, d/2d/2)) and and PATH(v,b, PATH(v,b, d/2d/2))then then return return TRUETRUE
} } return return FALSEFALSE
}}}}
Both use the same space
3939
Why logWhy log22(n)?(n)?
1.1. The binary representation of all The binary representation of all numbers used by the algorithm is at numbers used by the algorithm is at most of size of most of size of O(log(n))O(log(n))..
2.2. As the As the dd parameter is reduced to parameter is reduced to half at each recursive call, the half at each recursive call, the recursion tree is of depth recursion tree is of depth O(log(n))O(log(n))..
3.3. Therefore at each step of the Therefore at each step of the computation, we use at most computation, we use at most O(log(n))O(log(n)) numbers of size numbers of size O(log(n))O(log(n)) resulting in resulting in O(log2(n))O(log2(n)) total space. total space.
4040
Example of Savitch’s Example of Savitch’s algorithmalgorithm
(a,b,c)=Is there a path from a to b, that takes no more than c steps.
Log2(3)
1
4
32
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
(1,4,3)(1,4,3)(1,2,2)(1,4,3)(1,2,2)TRUE(1,4,3)(2,4,1)(1,4,3)(2,4,1)FALSE(1,4,3)(1,3,2)(1,4,3)(1,3,2)(1,2,1)(1,4,3)(1,3,2)(1,2,1)TRUE(1,4,3)(1,3,2)(2,3,1)(1,4,3)(1,3,2)(2,3,1)TRUE(1,4,3)(1,3,2)TRUE(1,4,3)(3,4,1)(1,4,3)(3,4,1)TRUE(1,4,3) TRUE
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
boolean PATH(a,b,d) { if there is an edge from a to b then return TRUE else { if (d=1) return FALSE for every vertex v (not a,b) { if PATH(a,v, d/2) and PATH(v,b, d/2) then return TRUE } return FALSE }}
4141
Applying s-t-reachability to Applying s-t-reachability to Savitch’s theorem.Savitch’s theorem.
Given a NDTMGiven a NDTM MMnn working in space working in space log(n)log(n), we construct a DTM, we construct a DTM MM working working in in loglog22(n) (n) in the following way:in the following way:
Given Given xx, , MM solves the solves the s-t reachabilitys-t reachability on the configuration graph of on the configuration graph of (M(Mnn,x),x)..
NoteNote: the graph is generated “on : the graph is generated “on demand”, reusing space, therefore demand”, reusing space, therefore MM never keeps the entire representation never keeps the entire representation of the graph.of the graph.
4242
Appling s-t-reachability to Appling s-t-reachability to Savitch’s thm.Savitch’s thm.
Since Since MMnn works in works in log(n)log(n) space it has space it has O(2O(2log(n)log(n))) configurations, its configurations, its configuration graph is of size configuration graph is of size O(2O(2log(n)log(n))) and reachability is and reachability is solved in solved in loglog22(O(2(O(2log(n)log(n))) )= )= loglog22(n) (n) space.space.
4343
Savitch’s theorem - Savitch’s theorem - conclusionconclusion
NL NL DSPACE(log DSPACE(log22(n))(n)) This is not just a special case of This is not just a special case of
Savitch Thm but equivalent.Savitch Thm but equivalent.
As we’ll see nextAs we’ll see next
4444
Generalization of the proofGeneralization of the proof Note that in the last argument, We could Note that in the last argument, We could
have substituted the have substituted the log(n)log(n) function by function by any function, and thus derive the general any function, and thus derive the general Savitch Theorem:Savitch Theorem:
S(n)S(n)log(n)log(n) Nspace(S) Nspace(S) DSPACE(S DSPACE(S22))..
We will next prove a lemma that will help We will next prove a lemma that will help us generalize any theorem proved for us generalize any theorem proved for small functions to larger ones. small functions to larger ones. Specifically, we will generalize the Specifically, we will generalize the NL NL DSPACE(logDSPACE(log22(n))(n)) theoremtheorem
4545
Translation Lemma-(Padding Translation Lemma-(Padding argument)argument)
Nspace(sNspace(s11(n)) (n)) DSPACE(sDSPACE(s22(n))(n))
Nspace(sNspace(s11(f(n))) (f(n))) SPACE(s SPACE(s22(f(n)))(f(n)))
5.5
For space constructible functions s1(n), s2(n) log(n), f(n) n:
4646
Padding argumentPadding argument Let Let LLNPspace(sNPspace(s11(f(n)))(f(n))) There is a 3-Tape-NDTM There is a 3-Tape-NDTM MMLL which which
acceptsaccepts LL in in NPspace (sNPspace (s11(f(n)))(f(n)))
babba������������������������
���������������������������
Input
Work
|x|
O(s1(f(|x|)))
4747
Padding argumentPadding argument Define Define L’ = { x0L’ = { x0f(|x|)-|x|f(|x|)-|x| | x | xL }L } We’ll show a NDTM We’ll show a NDTM MML’L’ which decides which decides L’L’
in the same space as in the same space as MMLL..
babba00000000000000000000000000000000���
���������������������������
Input
Work
n’=f(|x|)
O(s1(n’)) = O(s1(f(|x|))
4848
Padding argument – MPadding argument – ML’L’
1.1. Count Count 00’s backwards, mark end of ’s backwards, mark end of
xx and check and check f(|x|)-|x| = 0f(|x|)-|x| = 0’s length’s length
2.2. RunRun MMLL on on xx..
babba#0000000000000000000000000000000���
���������������������������
Input
Work
n'
O(s1(n’))
NSpace(log(n’))
NSpace(s1(f(n))) = NSpace(s1(n’))
4949
Padding argumentPadding argument
babba#0000000000000000000000000000000���
���������������������������
Input
Work
n'
O(s1(n’))
Total Nspace(O(s1(n’)))
5050
Padding argument – M’Padding argument – M’L’L’
MML’L’ NPspace(s NPspace(s11(n))(n))
using using Nspace(sNspace(s11(n)) (n)) DSPACE(s DSPACE(s22(n))(n)) : :
there is a there is a M’M’L’L’, deterministic TM, which , deterministic TM, which accept accept L’ L’ in in DSPACE(sDSPACE(s22(n))(n))
Given Given M’M’LL’’ , we will construct a DTM , we will construct a DTM M*M*LL that accept that accept LL in in O(s2(f(n))O(s2(f(n)) space. space.
5151
Padding argument – M*Padding argument – M*LL
1.1. Run Run M’M’LL’ ’ on input on input xx..
2.2. Whenever Whenever M’M’LL’ ’ head leaves the head leaves the xx part part of the input, use counter to simulate of the input, use counter to simulate the head position.the head position.
3.3. check that check that M’M’LL’’ doesn’t use more than doesn’t use more than ss22(f(|x|))(f(|x|)) space. space.
4.4. This can be checked because This can be checked because ss22 and and ff are constructible.are constructible.
M’M’L’ L’ can be simulated bycan be simulated by another DTM which receivesanother DTM which receives
the original input, by “imagining” the 0’s, the original input, by “imagining” the 0’s, and counting the place of the imaginary head, and counting the place of the imaginary head,
when “reading” to the right of the input.when “reading” to the right of the input.
5252
Padding argument – Padding argument – particular caseparticular case
L L Nspace(n) Nspace(n)
L’ L’ Nspace(Log(n’)) = NL(n’) Nspace(Log(n’)) = NL(n’)
L’ L’ Space(Log Space(Log22(n’))(n’))
L L Space(Log Space(Log22(2(2nn))))
L L Space(n Space(n22))
by NL DSPACE(log2(n))
n’ = 2n
n’ = 2n