Time and Space Crawling, on the planets face. Space Complexity - - PowerPoint PPT Presentation

time and space
SMART_READER_LITE
LIVE PREVIEW

Time and Space Crawling, on the planets face. Space Complexity - - PowerPoint PPT Presentation

Time and Space Crawling, on the planets face. Space Complexity Some insects, called the human race. Lost in time, and lost in space Nabil Mustafa ... and in meaning. Computability and Complexity Rocky Picture Horror Show (1973) Nabil


slide-1
SLIDE 1

Space Complexity

Nabil Mustafa Computability and Complexity

Nabil Mustafa Space Complexity

Time and Space

Crawling, on the planet’s face. Some insects, called the human race. Lost in time, and lost in space ... and in meaning. – Rocky Picture Horror Show (1973)

Nabil Mustafa Space Complexity

Defining Space Complexity

So far, concerned with the resource of time P : Class of algorithms running in at most polynomial time NP : Class of algorithms running in at most exponential time Space is the other resource Space-Bounded Complexity Given

1 A function S : N → N 2 A TM M that decides a language L

we say M has space complexity S(n) if M decides L using O(S(|x|)) distinct cells on the work-tape on input x. Note: Don’t count the space used in the read-only input tape.

Nabil Mustafa Space Complexity

Defining the Class SPACE

The Class SPACE SPACE (S(n)): set of functions computable in space at most c · S(n) for some constant c > 0. For example, SPACE (n2) is the set of all functions computable in at most O(n2) space. S1(n) = O(S2(n)) = ⇒ SPACE (S1(n)) ⊆ SPACE (S2(n)) The Class PSPACE PSPACE =

  • c≥1

SPACE (nc) The class PSPACE contains all classes SPACE (S(n)) where S(n) is a polynomial of finite degree.

Nabil Mustafa Space Complexity
slide-2
SLIDE 2

Relation to DTIME

Claim DTIME (F(n)) ⊆ SPACE (F(n)) In English: if a language L can be decided in O(F(n)) steps, then it can be decided using space O(F(n)) as well. Trivial: A TM running in t steps can only touch t cells. So the TM deciding L in time t can also only touch t cells. Note: SPACE (F(n)) ⊆ DTIME (F(n)) not true. Quicksort takes time O(n log n), but space O(n).

Nabil Mustafa Space Complexity

Relation to DTIME

Claim SPACE (F(n)) ⊆ DTIME (2F(n)) So assume TM M can decide L in space SPACE (F(n)) Given x, it will always halt with an accept or reject. Basic idea: Two positions on the tape cannot occur twice! Why?: Otherwise M would not halt! cs211a06 students: Did we see this idea in Discrete Math?

Nabil Mustafa Space Complexity

Defining Configurations

A configuration at time t is: The symbols in each cell of the tapes Head positions of all the tape-heads The TM state Define the directed graph GM,x given TM M and input x Each vertex is a configuration (vi, vj) ∈ E iff vj gotten by applying a transition rule to vi For a deterministic TM , each vertex has out-degree 1 Claim: If TM M decides L, then GM,x a DAG If not a DAG, a cycle = ⇒ infinite loop. Denote by C x

start the starting configuration given x.

By modifying M so that it erases all tapes before halting, we have a single configuration Caccept that, if reached, always means ‘accept’.

Nabil Mustafa Space Complexity

Representing Configurations

Claim: Each configuration can be described using cS(n) bits. Symbols in each cell of the tapes: O(S(n)) Position of the tape heads: O(log S(n)) The TM state: O(log |Q|) = O(1) Claim: There is an O(S(n))-size CNF formula φ such that φM,x(C, C ′) = 1 iff C and C ′ are neighbors in GM,x. Have a formula such that encodes a valid transition from C Then check if C ′ is a valid transition from C Exactly like the proof of Cook-Levin theorem.

Nabil Mustafa Space Complexity
slide-3
SLIDE 3

Relation between PSPACE and DTIME

Claim SPACE (S(n)) ⊆ DTIME (2S(n)) Each configuration can be described using O(S(n)) bits. Configurations cannot repeat. In the worst case, the TM could go over all possible configurations Total time: O(2S(n)). What We Know So Far DTIME (F(n)) ⊆ SPACE (F(n)) ⊆ DTIME (2F(n))

Nabil Mustafa Space Complexity

Relation between NP and PSPACE

Claim NP ⊆ PSPACE Only need to show for one NP complete function L Then how to compute any other language L′ ∈ NP : Since L NP hard, can reduce L′ to L Important: we use only polynomial space in the reduction since the reduction takes only polynomial time. Then solving L in PSPACE solves L′ in PSPACE Claim: 3-CNF SAT is in PSPACE Given a formula φ in n variables Start with the assignment v1 = 0, . . . , vn = 0 Check if φ satisfied If not, erase previous assignment, and try a new one Halt after at most 2n steps Total space used: n.

Nabil Mustafa Space Complexity

Defining QBF

So PSPACE includes all the functions in NP Now we describe a function in PSPACE , but not known to be in NP The function is a game played on a SAT formula φ: Lets order the variables of φ as x1, . . . , xn It is played by DemonHunter (DH) and BladeMaster (BM) DH moves first, and sets x1 to a fixed boolean value. BM moves second, and sets x2 to a fixed boolean value. DH then sets x3, BM sets x4 and so on. DH (BM) wins the game if the final formula is satisfied (not satisfied). The function is: given a SAT formula, can DH win the game?

Nabil Mustafa Space Complexity

An Example

(x1 ∨ x2) ∧ (x1 ∨ x2) Who wins this game? DH sets x1 = 1 , BM sets x2 = 1 . BM wins. DH sets x1 = 0 , BM sets x2 = 0 . BM wins. (x1 ∨ x2 ∨ x3) ∧ (x1 ∨ x2 ∨ x3) ∧ (x1 ∨ x2 ∨ x3) ∧ (x1 ∨ x2 ∨ x3) Who wins this game? DH sets x1 = 1 , BM sets x2 = 1 . DH sets x3 =? . BM wins. DH sets x1 = 0 , BM sets x2 = 1 . DH sets x3 = 1 . DH wins. DH sets x1 = 0 , BM sets x2 = 0 . DH sets x3 = 0 . DH wins.

Nabil Mustafa Space Complexity
slide-4
SLIDE 4

QBF

(x1 ∨ x2 ∨ x3) ∧ (x1 ∨ x2 ∨ x3) ∧ (x1 ∨ x2 ∨ x3) ∧ (x1 ∨ x2 ∨ x3) Basically, DH won because There existed some value of x1 that DH could set so that no matter how BM set x2, there existed some value of x3 so that formula was satisfied. DH first picked the wrong value for x1, but doesn’t matter. In general, DH wins if there exists a value of x1 so that for every value BM sets for x2, there exists a value of x3 so that for every value BM sets for x4 and so on. ∃x1∀x2∃x3∀x4 . . . φ(x1, . . . , xn) is satisfied

Nabil Mustafa Space Complexity

QSAT

QBF A Quantified Boolean Formula (QBF ) is of the form: Φ = (Q1x1)(Q2x2)(Q3x3) . . . (Qnxn) φ(x1, . . . , xn) where xi are variables, each Qi ∈ {∀, ∃}, φ is CNF formula. Φ is valid if φ is satisfied for all quantifications Qi. For example, ∃x1∀x2∀x3φ(x1, x2, x3) is valid iff there exists a value of x1 such that for all values of x2 and all values of x3, φ is satisfied. QSAT Given a QBF formula Φ, is it valid?

Nabil Mustafa Space Complexity

QSAT is in PSPACE

Claim QSAT is in PSPACE Given a QBF Φ, can check if its valid in polynomial space Is it any different from SAT ? Just cycle through all 2n variable assignments After checking each assignment, re-use the space for n vars Problem: Have to ‘remember’ lots of bits Assume QBF is ∀x1∃x2∀x3∀x4 . . . Then have to remember the result for 2 values of x1, 2 values for x3, 2 values for x4, etc. In the worst case, have Ω(2n) bits to remember Exponential space! Solution: Compute the formula recursively so reuse space

Nabil Mustafa Space Complexity

Computing a QBF

Given Φ = (Q1x1)(Q2x2)(Q3x3) . . . (Qnxn) φ(x1, . . . , xn) Set i = 1. Compute Φ recursively as follows: If Qi = ∃ Set xi = 1, run (Qi+1xi+1) . . . (Qnxn) φ(. . . , 1, xi+1, . . . , xn) Set xi = 0, run (Qi+1xi+1) . . . (Qnxn) φ(. . . , 0, xi+1, . . . , xn) If at least one of the answers is 1, return 1. Otherwise return 0. If Qi = ∀ Set xi = 1, run (Qi+1xi+1) . . . (Qnxn) φ(. . . , 1, xi+1, . . . , xn) Set xi = 0, run (Qi+1xi+1) . . . (Qnxn) φ(. . . , 0, xi+1, . . . , xn) If both the answers is 1, return 1. Otherwise return 0. Re-use space for each recursive call. Space: S(n) = 2 bits for the two answers + S(n − 1) S(n) = O(n + m).

Nabil Mustafa Space Complexity
slide-5
SLIDE 5

A Way to Think About QBF

∃ x1 ∀ x2 ∃ x3 φ(x1, x2, x3)

∃ ∀ ∀ ∃ ∃ ∃ ∃ x1 = 1 x1 = 0

x1 = 0, x2 = 0 x1 = 0, x2 = 1 x1 = 1, x2 = 0 x1 = 1, x2 = 1 x2 = 1 x3 = 1 x3 = 0 x1 = 0 x1 = 0 x1 = 0 x1 = 0 x1 = 1 x1 = 1 x1 = 1 x1 = 1 x2 = 1 x2 = 1 x2 = 1 x2 = 0 x2 = 0 x2 = 0 x2 = 0 x3 = 0 x3 = 0 x3 = 0 x3 = 1 x3 = 1 x3 = 1 1 Nabil Mustafa Space Complexity

QBF is PSPACE complete

QBF is in PSPACE It can also be shown that QBF is PSPACE complete The Cook-Levin reduction does not work The number of variables should be polynomial (otherwise space used is super-polynomial) In Cook-Levin, number of variables is a function of the running time For problems in P running time is polynomial For problems in PSPACE running time could be exponential Intuitively: have to ‘reuse variables’ (exactly like we re-used space to solve QBF ) Read from Arora-Barak. We skip the reduction, since its very similar to what we do next, Savitch’s Theorem.

Nabil Mustafa Space Complexity