t s Computability and Complexity Nabil Mustafa Nondeterministic - - PowerPoint PPT Presentation

t s
SMART_READER_LITE
LIVE PREVIEW

t s Computability and Complexity Nabil Mustafa Nondeterministic - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Nondeterministic Space Complexity

Nabil Mustafa Computability and Complexity

Nabil Mustafa Nondeterministic Space Complexity

The 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 Complexity

REACHABILITY 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,

1

Set ai+1 = v

2

Answer = REACHABILITY (ai+1, t)

3

If 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 Complexity

REACHABILITY 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
slide-2
SLIDE 2

REACHABILITY is in NSPACE (log n)

Claim REACHABILITY is in NSPACE (log n) Proof. No need to store all ai, just check each condition one by one. Store two indices: current-vertex= s and next-vertex REACHABILITY ( s, t ): Repeat the following n times Guess the bits of next-vertex If (current-vertex, next-vertex) / ∈ E return 0. If next-vertex= t, return 1. Set current-vertex = next-vertex. If t reachable, one sequences of guesses will find t If t unreachable, no sequences of guesses will give the path. Space used: 2 vertex indices – O(log n)

Nabil Mustafa Nondeterministic Space Complexity

A Surprising Result

Claim REACHABILITY is in SPACE (log2 n) Proof. Again, save space via recursion. A proof by induction as follows, given n-vertex graph G To check for a path of length l between s and t: Try all possible ‘middle’ vertices vmid in this path. For each vmid, recursively check if path from s to vmid Recursively check if path from vmid to t reusing previous space If, for a fixed vmid, both return 1, return 1 Base case: when l = 1 Check if (s, t) ∈ E. Computed with no space.

Nabil Mustafa Nondeterministic Space Complexity

A Surprising Result

Proof. We have presented an algorithm for REACHABILITY The space used in O(log2 n) because At each recursive call, we halve the length of the path Therefore, number of consecutive calls: O(log n) We have to store vmid at each level: O(log n) bits Total space used: O(log2 n) Inductive hypothesis: path of length k uses log n log k space. Then, the total space used for path of length l is space for vmid + recursion = log n + log n log l/2 = log n log l Maximum length of path is n, so proof follows. Should remind you of: QSAT

Nabil Mustafa Nondeterministic Space Complexity

Follow-up on Savitch’s Theorem

Examining the time required, let T(k) be the worst-case time used by REACHABILITY with path of length at most k T(1) = O(n + m) T(k) = O(1) + n · 2 · T(k/2) This solves to T(k) = nO(logk), which is super polynomial. 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 known for undirected REACHABILITY .

Nabil Mustafa Nondeterministic Space Complexity
slide-3
SLIDE 3

Savitch’s Theorem

Savitch’s Theorem NSPACE (f (n)) ⊆ SPACE (f (n)2) Proof. It follows almost immediately from previous theorem. Why? Given NTM M deciding L in space f (n), construct GM,x Number of vertices: O(2f (n)) Number of bits to describe each vertex: O(f (n)) x ∈ L iff there exists a path from Cstart to Caccept Unluckily, configuration graph is Ω(2f (n)), cannot store it Luckily, our REACHABILITY algorithm doesn’t need to store G So we can use the previous REACHABILITY algorithm!

Nabil Mustafa Nondeterministic Space Complexity

Savitch’s Theorem

Proof. Given GM,x, check for a path from Cstart to Caccept To check for a path of length l between Cstart and Caccept: Try all possible ‘middle’ configurations Cmid in this path. For each Cmid, recursively check if path from Cstart to Cmid Recursively check if path from Cmid to Caccept reusing previous space If, for a fixed Cmid, both return 1, return 1 Base case: when l = 1, check if (Ci, Cj) ∈ E. Want to check if configuration Cj can be gotten by applying a valid transition table rule to Ci Can check in space f (n) Storing each configuration takes space: O(f (n)) Maximum path length: O(2f (n)) Total space used: O(f (n) · log 2f (n)) = O(f (n)2)

Nabil Mustafa Nondeterministic Space Complexity

Implications of Savitch’s Theorem

Surprising Result NPSPACE = PSPACE Savitch’s theorem: NSPACE (f (n)) ⊆ SPACE (f (n)2) Therefore, if L is in polynomial nondeterministic space, its in polynomial deterministic space. So nondeterministic space isn’t more powerful than deterministic space Surprising result since we suspect nondeterministic time to be more powerful than deterministic time – P = NP

Nabil Mustafa Nondeterministic Space Complexity

The Class L

SAT can be solved in polynomial space NP ⊆ PSPACE So polynomial space is very strong computationally What about a more restricted sub-linear space class L and NL L = SPACE (O(log n)) NL = NSPACE (O(log n)) Note: Count space used on the work-tape, not on I/O tapes.

Nabil Mustafa Nondeterministic Space Complexity
slide-4
SLIDE 4

An Example

An example we have already seen: REACHABILITY ∈ NL What can be stored in logarithmic space? Constant number of counters up to input length Constant number of pointers to input tape L = {0n1n | n ≥ 0}. Claim: L ∈ L First count the number of 0’s, then 1’s. Check equality. Two counters, each can go upto at most log(|x|) bits. Claim: PAL ∈ L Keep two pointers to the first and last element. Check both bits, and move both counters to next elements. Two points, each can go upto at most log(|x|) bits.

Nabil Mustafa Nondeterministic Space Complexity

A Possible Misconception

NL – Is it related to NP somehow? Analogously with time-bounded complexity classes, one could think that NL is exactly the set of decision problems that have ‘solutions’ that can be verified in log-space. If so, NP ⊆ NL, since there is a log-space algorithm M that verifies solution to SAT. However, this is unlikely to be true, because NL is contained in P. An intuitive reason why not all problems with a log-space ‘verifier’ can be simulated in NL is that an NL machine does not have enough memory to keep track of all the non-deterministic choices that it makes.

Nabil Mustafa Nondeterministic Space Complexity

Reductions for NL

Defined the notion of reduction when dealing with class NP The same notion works for the class NL Reductions Language A is polynomial-time reducible to language B if there exists a poly-time function f such that x ∈ A ⇐ ⇒ f (x) ∈ B We say A ≤P B. A language B is NL-hard if A ≤P B for every A ∈ NL A language B is NL-complete if B is NL-hard and B ∈ NL Problem? NL ⊆ P

Nabil Mustafa Nondeterministic Space Complexity

NL ⊆ P

Proof: Let L be a language in NL and M be a non-deterministic log-space machine for L. Consider the computation of M(x). As we know from previous lecture, there are 2O(s(n)) = nO(1) possible configurations. Consider a directed graph whose vertices are configurations and edges if transition from one state to other in single step This graph has polynomially many vertices, so in polynomial time we can do a depth-first search to see whether there is a path from the initial configuration that eventually leads to acceptance. This describes a poly-time algorithm for deciding L

Nabil Mustafa Nondeterministic Space Complexity
slide-5
SLIDE 5

Problem with using polynomial time

Reductions: computing A can be reduced to computing B So B is the ‘hard’ part – if can compute B, can compute A Lets make a trivial language B: Output: first bit of the input. Claim: Any A ∈ NL is polynomial-time reducible to B We know that NL ⊆ P So given polynomial time, just solve for x ∈ A If x ∈ A, give a ‘1’ input to B If x / ∈ A, give a ‘0’ input to B Problem is that giving polynomial-time is too strong The resources used for the reduction must be weaker than those required to solve A For NP , we used polynomial-time. So, for NL , we use logarithmic space.

Nabil Mustafa Nondeterministic Space Complexity

Log-space Reductions

Log-space computability A function f : {0, 1}∗ = ⇒ {0, 1} is log-space computable if there exists a TM M that computes f (x) using log(|x|) space. Note: Output head moves only to right, and finally has f (x). Log-space Reductions, A ≤L B Language A is log-space reducible to language B if there exists a log-space function f such that x ∈ A ⇐ ⇒ f (x) ∈ B A language B is NL-hard if A ≤L B for every A ∈ NL A language B is NL-complete if B is NL-hard and B ∈ NL Because of our previous discussion, the following is trivial: L1 ≤L L2 = ⇒ L1 ≤P L2

Nabil Mustafa Nondeterministic Space Complexity

Properties of log-space reductions ≤L

We know that polynomial-time reductions are transitive: If A ≤P B and B ≤P C, then A ≤P C We also crucially used the following similar property: If A ≤P B and B ∈ NP , then A ∈ NP This is not true for log-space reductions. Why? Go back to why it is true for ≤P

Input: x nc-time function f(x) nd-time function g(x) g(f(x)) f(x) Size: |x|c Size: |x|cd

Total time for A ≤P C: O(|x|cd) – a polynomial

Nabil Mustafa Nondeterministic Space Complexity

Problem With Transitivity of Log-space Reductions

Input: x log-space function f(x) log-space function g(x) g(f(x)) f(x) Size: |x|c Size: |x|cd WT Space: log |x| WT Space: log |x|c

Total space used: O(log |x| + log |x|c) = O(log |x|). Problem? For log-space, stipulated that output space doesn’t count Here, we have to store intermediate result f (x) of size |x|c Solution: Do not store the intermediate output Claim: For log-space function f , can get f (x)i in log-space. f (·) uses log-space on the work-tape to first output f (x)1 Then the output-tape head moves right, writes f (x)2. And so on. Keeps moving right and writing f (x)i To get f (x)i: no need to store earlier f (x)j, j < i.

Nabil Mustafa Nondeterministic Space Complexity
slide-6
SLIDE 6

Proving Transitivity

Goal: To compute the string g(f (x)), given x Imagine that we have computed f (x), and its on Tape 1 The tape-head for Tape 1 is at the start position. Now, given this imaginary input string, start computing g(f (x)) on Tape 2, just like before We know that the work tape Tape 2 needs log |f (x)| space At each step: Read one bit of f (x) from Tape 1 from tape-head position Read one bit of work-tape from tape-head position Move Tape 1, Tape 2 heads by transition function Write one bit on Tape 2, maybe write one bit on Output tape Read one bit of f (x) from Tape 1 from tape-head position Don’t have f (x) lying around on the imaginary Tape 1 Instead, store position of Tape 1 head: O(log |f (x)|) space Need to read f (x)i: compute using log |x| space Increment or decrement the pointer for Tape 1 head

Nabil Mustafa Nondeterministic Space Complexity

Picture From AB

| | | | | | | |

Input tape Work tape Output tape > 0 0 1 1 0 1 0 0 1 0 0 0 read only head read/write head

Mf

Work tape Output tape Virtual input tape

Mg

Nabil Mustafa Nondeterministic Space Complexity

A NL complete problem

Claim REACHABILITY is NL complete. Already seen that REACHABILITY is in NL To show REACHABILITY is NL hard, reduce A ∈ NL to it. x ∈ A if a NTM N decides x ∈ A in space log(|x|). Look at the configuration graph of N x ∈ A iff there is a path in configuration graph from the starting configuration to accepting configuration Since A ∈ NL , encode each configuration with log(|x|) bits The log-space reduction constructs the configuration graph Enumerate over all log(|x|) bits and output each vertex By checking if Cj can be derived from Ci for each pair of vertices, output the edges of configuration graph Given graph, REACHABILITY can now decide x ∈ A

Nabil Mustafa Nondeterministic Space Complexity

Undirected REACHABILITY

Given undirected graph G = (V , E) and two vertices s, t ∈ V , the question is whether there is a path between s and t in G. While not known to be complete for NL, and it probably is not, undirected REACHABILITY is complete for the class SL of decision problems that are solvable by symmetric non-deterministic machines that use O(log n) space. A non-deterministic machine is symmetric if whenever it can make a transition from a global state s to a global state s′ then the transition from s′ to s is also possible. The proof of SL-completeness of undirected REACHABILITY is identical to the proof of NL-completeness of REACHABILITY except for the observation that the transition graph of a symmetric machine is undirected.

Nabil Mustafa Nondeterministic Space Complexity