Nondeterministic Space Complexity
Nabil Mustafa Computability and Complexity
Nabil Mustafa Nondeterministic Space ComplexityThe Problem REACHABILITY
REACHABILITY Input: A directed graph G = (V , E), |V | = n, |E| = m, and two vertices s, t ∈ V Question: Is there a directed path from s to t in G?
t s
Nabil Mustafa Nondeterministic Space ComplexityREACHABILITY is in SPACE (n log n)
Claim REACHABILITY is in SPACE (n log n) Proof. Simply depth-first search starting from s Global variables: a0, . . . , an−1 ai: i-th vertex on the path from s to t. a0 = s, i = 0 REACHABILITY ( ai, t ): 1 if t reachable from ai For each neighbor v ∈ V of ai,
1Set ai+1 = v
2Answer = REACHABILITY (ai+1, t)
3If Answer = 1, return 1 return 0
Careful never to recurse more than n depth (loops) Total space used: n vertex indices – O(n log n)
Nabil Mustafa Nondeterministic Space ComplexityREACHABILITY is in NSPACE (log n)
Claim REACHABILITY is in NSPACE (log n) Proof. Even simpler, no need to do any search – just ‘guess’ ai Global variables: a0, . . . , an−1 ai: i-th vertex on the path from s to t. a0 = s, i = 0 REACHABILITY ( s, t ): 1 if t reachable from s Guess the bits of a1, . . . , an Check if (ai, ai+1) ∈ E for all i Check if ai = t for any i If both true, return yes. Otherwise return false. Space used: same ai, so same space O(n log n) How to get this down to O(log n)
Nabil Mustafa Nondeterministic Space Complexity