210 likes | 443 Views
Space Complexity. Guy Feigenblat Based on lecture by Dr. Ely Porat Complexity course Computer science department , Bar-Ilan university December 2008. Introduction. What is the space complexity of algorithm that verifies the sequences: A 1 = {a*b*} O(1)
E N D
Space Complexity Guy Feigenblat Based on lecture by Dr. Ely Porat Complexity course Computer science department , Bar-Ilan university December 2008
Introduction What is the space complexity of algorithm that verifies the sequences: A1 = {a*b*} O(1) A2 = {anbn | n > 0} O(log n)
Space Complexity of Algorithm Q O(1) Work S(n) Pointers log(n) + log (S(n)) O(S(n))
Definitions DSAPCE (S(n)) = {L| M, s.t. M is a deterministic Turing machine using space O(S(n)) and L=L(M) } NSAPCE (S(n)) = {L| M, s.t. M is a non-deterministic Turing machine using space O(S(n))) and L=L(M) } L = DSAPCE(O(logn)) NL = NSAPCE(O(logn)) L NL
DefinitionS S-T-Conn = {(G,s,t) | G is a directed Graph, there is a path from s to t } Claim: S-T-Conn NL
S-T-Conn NL Observation - If there exist a path, the “oracle” will find it. Attempt 1: Get from the “Oracle” the path and verify it. To much space – O( |V|log|V|) !!! Attempt 2: Start from an arbitrary edge (s,x1) Get from the oracle the next edge (x1,x2) , check it exist & dump s. Continue till reaching (xn,t). Total – 2log|V| - keeping at most 2 vertices at each time.
Theorem L P Each Turing machine, in L, works with O(logn) space. Namely, for some constant C, it uses Clogn bits. Since Turing machine, in L, is deterministic we will only perform each state once, otherwise going into loop. The total possible states is therefore O(nc).
Theorem NL NP If there exist a Turing machine solving the problem in O(log n) space then there exist a set of states bounded by O (nc). Recall that we need to return {0,1}. We count the number of steps the algorithm perform, if it exceeds O (nc) return 0. else return the algorithm output.
NL-Complete (NLC) Logarithmic space reduction
Problem ?! The reduction concatenate 2 machines. Is it allowed ? Using clogn memory, machine can produce input in the size of nc.
Solution Notice that the output stream of M is the input stream of . Pre-process: M run until it writes the first variable on its input stream. When needs to read another input, it calls M and runs it till M writes the next output variable.
Claim: S-T-Conn NLC We already proved א' condition. Still need to prove ב' condition
Intuition We need to build a graph, as an input to S-T-Conn. We will build it base on the possible transposition (configurations) of each L’. Since L’ NL, The transposition graph size will be at most: 2clogn = nc = |V|
Proof Clearly, the space used in the reduction is O(logn) Print to output stream
Conclusion: NL P S-T-Conn P Why ?? BFS / DFS S-T-Conn NLC Was proven NL P We can solve any problem in NL using S-T-Conn and S-T-Conn can be solved Polynomial time.
Claim: NL DSPACE (log2n) Enough to show S-T-Conn DSPACE (log2n) Consider the below algorithm: Is There a path between vertexes s,t in length less then d ?
Explanation • Clearly the algorithm is deterministic • While the algorithm’s running time is exponential, it only uses O(log2n) bits. • In each step, we have, maximum, O(logn) vertices, each in size of O(logn) bits Thus, the total space consumption is O(log2n) bits.
Definition Co-NL = Clearly, S-T-Conn Co-NL It is known that S-T-Conn Co-NLC Does Co-NL = NL ? S-T-Conn NL Co-NL NL NL=Co-NL Enough to show
Theorem: NL=Co-NL You will see in the Tirgul N is the group of vertexes in the connected component of S . This program shows that Non-S-T-Conn is also in NL: S-T-Conn NL From definition, we now get: S-T-Conn Co-NL Concluding that NL=Co-NL