The Problem REACHABILITY REACHABILITY Input: A directed graph G = ( V , E ), | V | = n , | E | = m , and two vertices s , t ∈ V Nondeterministic Space Complexity Question: Is there a directed path from s to t in G ? Nabil Mustafa t s Computability and Complexity Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity REACHABILITY is in SPACE ( n log n ) REACHABILITY is in NSPACE (log n ) Claim Claim REACHABILITY is in SPACE ( n log n ) REACHABILITY is in NSPACE (log n ) Proof. Proof. Simply depth-first search starting from s Even simpler, no need to do any search – just ‘guess’ a i Global variables: a 0 , . . . , a n − 1 Global variables: a 0 , . . . , a n − 1 a i : i -th vertex on the path from s to t . a 0 = s , i = 0 a i : i -th vertex on the path from s to t . a 0 = s , i = 0 REACHABILITY ( a i , t ): 1 if t reachable from a i REACHABILITY ( s , t ): 1 if t reachable from s For each neighbor v ∈ V of a i , Guess the bits of a 1 , . . . , a n Set a i +1 = v 1 Check if ( a i , a i +1 ) ∈ E for all i 2 Answer = REACHABILITY ( a i +1 , t ) Check if a i = t for any i If Answer = 1, return 1 3 If both true, return yes. Otherwise return false. return 0 Space used: same a i , so same space O ( n log n ) Careful never to recurse more than n depth (loops) How to get this down to O (log n ) Total space used: n vertex indices – O ( n log n ) Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity
REACHABILITY is in NSPACE (log n ) A Surprising Result Claim Claim REACHABILITY is in NSPACE (log n ) REACHABILITY is in SPACE (log 2 n ) Proof. Proof. No need to store all a i , just check each condition one by one. Again, save space via recursion. Store two indices: current-vertex = s and next-vertex A proof by induction as follows, given n -vertex graph G REACHABILITY ( s , t ): Repeat the following n times To check for a path of length l between s and t : Guess the bits of next-vertex Try all possible ‘middle’ vertices v mid in this path. If ( current-vertex , next-vertex ) / ∈ E return 0. For each v mid , recursively check if path from s to v mid If next-vertex = t , return 1. Recursively check if path from v mid to t reusing previous space Set current-vertex = next-vertex . If, for a fixed v mid , both return 1, return 1 If t reachable, one sequences of guesses will find t Base case: when l = 1 If t unreachable, no sequences of guesses will give the path. Check if ( s , t ) ∈ E . Computed with no space. Space used: 2 vertex indices – O (log n ) Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity A Surprising Result Follow-up on Savitch’s Theorem Proof. We have presented an algorithm for REACHABILITY Examining the time required, let T ( k ) be the worst-case time The space used in O (log 2 n ) because used by REACHABILITY with path of length at most k At each recursive call, we halve the length of the path Therefore, number of consecutive calls: O (log n ) T (1) = O ( n + m ) We have to store v mid at each level: O (log n ) bits Total space used: O (log 2 n ) T ( k ) = O (1) + n · 2 · T ( k / 2) Inductive hypothesis: path of length k uses log n log k space. This solves to T ( k ) = n O ( logk ) , which is super polynomial. Then, the total space used for path of length l is space for v mid + recursion = log n + log n log l / 2 = log n log l This is still the one with the best known space bound. No known algorithm achieves polynomial log-space and polynomial time simultaneously, although such an algorithm is Maximum length of path is n , so proof follows. known for undirected REACHABILITY . Should remind you of: QSAT Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity
Savitch’s Theorem Savitch’s Theorem Proof. Savitch’s Theorem Given G M , x , check for a path from C start to C accept NSPACE ( f ( n )) ⊆ SPACE ( f ( n ) 2 ) To check for a path of length l between C start and C accept : Try all possible ‘middle’ configurations C mid in this path. For each C mid , recursively check if path from C start to C mid Proof. Recursively check if path from C mid to C accept reusing previous It follows almost immediately from previous theorem. Why? space Given NTM M deciding L in space f ( n ), construct G M , x If, for a fixed C mid , both return 1, return 1 Number of vertices: O (2 f ( n ) ) Base case: when l = 1, check if ( C i , C j ) ∈ E . Number of bits to describe each vertex: O ( f ( n )) Want to check if configuration C j can be gotten by applying a x ∈ L iff there exists a path from C start to C accept valid transition table rule to C i Unluckily, configuration graph is Ω(2 f ( n ) ), cannot store it Can check in space f ( n ) Luckily, our REACHABILITY algorithm doesn’t need to store G Storing each configuration takes space: O ( f ( n )) Maximum path length: O (2 f ( n ) ) So we can use the previous REACHABILITY algorithm! Total space used: O ( f ( n ) · log 2 f ( n ) ) = O ( f ( n ) 2 ) Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity Implications of Savitch’s Theorem The Class L Surprising Result SAT can be solved in polynomial space NP ⊆ PSPACE NPSPACE = PSPACE So polynomial space is very strong computationally Savitch’s theorem: NSPACE ( f ( n )) ⊆ SPACE ( f ( n ) 2 ) What about a more restricted sub-linear space class Therefore, if L is in polynomial nondeterministic space, its in polynomial deterministic space. L and NL L = SPACE ( O (log n )) So nondeterministic space isn’t more powerful than deterministic space NL = NSPACE ( O (log n )) Surprising result since we suspect nondeterministic time to be more powerful than deterministic time – P � = NP Note: Count space used on the work-tape, not on I/O tapes. Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity
An Example A Possible Misconception An example we have already seen: REACHABILITY ∈ NL NL – Is it related to NP somehow? Analogously with time-bounded complexity classes, one could What can be stored in logarithmic space? think that NL is exactly the set of decision problems that Constant number of counters up to input length have ‘solutions’ that can be verified in log-space. Constant number of pointers to input tape If so, NP ⊆ NL , since there is a log-space algorithm M that L = { 0 n 1 n | n ≥ 0 } . Claim: L ∈ L verifies solution to SAT . First count the number of 0’s, then 1’s. Check equality. However, this is unlikely to be true, because NL is contained Two counters, each can go upto at most log( | x | ) bits. in P . Claim: PAL ∈ L An intuitive reason why not all problems with a log-space Keep two pointers to the first and last element. ‘verifier’ can be simulated in NL is that an NL machine does not have enough memory to keep track of all the Check both bits, and move both counters to next elements. non-deterministic choices that it makes. Two points, each can go upto at most log( | x | ) bits. Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity Reductions for NL NL ⊆ P Proof: Defined the notion of reduction when dealing with class NP Let L be a language in NL and M be a non-deterministic The same notion works for the class NL log-space machine for L . Reductions Consider the computation of M ( x ). Language A is polynomial-time reducible to language B if there As we know from previous lecture, there are 2 O ( s ( n )) = n O (1) exists a poly-time function f such that possible configurations. Consider a directed graph whose vertices are configurations x ∈ A ⇐ ⇒ f ( x ) ∈ B and edges if transition from one state to other in single step We say A ≤ P B . This graph has polynomially many vertices, so in polynomial time we can do a depth-first search to see whether there is a A language B is NL-hard if A ≤ P B for every A ∈ NL path from the initial configuration that eventually leads to acceptance. A language B is NL-complete if B is NL-hard and B ∈ NL This describes a poly-time algorithm for deciding L Problem? NL ⊆ P Nabil Mustafa Nondeterministic Space Complexity Nabil Mustafa Nondeterministic Space Complexity
Recommend
More recommend