Lecture Slides for MAT-73006 Theoretical computer science PART IIIa: Space Complexity Henri Hansen March 20, 2014 1
Space complexity • Let M be a TM that halts on all inputs. The space com- plexity of M is the function f : N �→ N where f ( n ) is the maximum number of tape cells that M scans on any input of length n (on any branch, if M is nondeterministic) • If L is the language decided by M , and f is the space com- plexity of M , then we say that M decides L in f ( n ) space, and that L is decided in f ( n ) space. • If f : N �→ R + , the space complexity class SPACE ( f ( n )) is the set of languages that are decided in O ( f ( n )) space 2
by a deterministic turing machine, and NSPACE ( f ( n )) is the set of languages that are decided in O ( f ( n )) space by a nondeterministic turing machine. • Space is more powerful than time, because space can be reused. • Example: Let M 1 be defined as a TM that receives a boolean formula ( φ ) as input, and 1. For each truth assignment x 1 , ldots, x m of the variables of φ : 2. Evaluate φ
3. If φ was ever evaluated as 1 , accept, otherwise reject. • Clearly M 1 decides SAT , and it uses only O ( m ) space, where m is the number of variables in φ , which means that the space consumption is O ( n ) (because n > m ). • Example: Recall that ALL DFA is the language of NFAs that accept all strings. (this language is not known to be in NP or coNP ) • This can be decided in nondeterministic O ( n ) space as fol- lows: 1. Mark the start state
2. Repeat 2 q times: 3. Select an input symbol nondeterministically and change the position of markers according to where markers might end up if the input symbol was read 4. Accept if the markers are ever distributed in such a way that no accepting state is marked, otherwise reject. • Space requirement is clearly O ( n ) , and this kind of nonde- terministic machine accepts the complement of ALL DFA .
Savitch’s theorem ¯ • We know from the previous example that ALL DFA ∈ NSPACE ( n ) . • For deterministic space the answer would immediately give the space complexity of ALL DFA , but if one considers the asymmetry of NP and coNP it is not immediately obvious what the result means for ALL DFA itself. • We can, however prove a theorem that connects nondeter- ministic and deterministic space classes in a way that does not seem to be the case for time classes. 3
• Savitch’s Theorem : For every function f : N �→ R + , such that f ( n ) ≥ n , NSPACE ( f ( n )) ⊆ SPACE ( f ( n ) 2 ) • The proof is not particularly hard to understand, but some- what technical. The main idea is the we simulate the non- deterministic Turing machine N with a deterministic Turing machine M , by using a matrix that contains f ( n ) different configurations of N ; because the N works in f ( n ) space, the space requirement of M will be f ( n ) 2 , as claimed in the theorem. • Let N decide A in f ( n ) space nondeterministically. M is constructed so that is implements a procedure C ANYIELD ( c 1 , c 2 , t ) ,
that tests if the N can get from configuration c 1 to c 2 using t steps. • In a nondeterministic machine C ANYIELD ( c 1 , c 2 , t ) would be easy to implement, because all it would have to do, would be to nondeterministically guess the correct steps. But we show that we can do this deterministically as fol- lows: • C ANYIELD ( c 1 , c 2 , t ) takes the three inputs and 1. If t = 1 , it checks if c 1 = c 2 , or, if one of the transitions of N yields c 2 from c 1 ; accept if any of these is possible, reject otherwise.
2. If t > 1 , one by one generate every configuration c m of N that fits in f ( n ) space, and: (a) Check C ANYIELD ( c 1 , c m , t/ 2) (b) Check C ANYIELD ( c m , c 2 , t/ 2) If both accept, then accept. 3. If you tried them all without accepting, reject • Since N decides a language in NSPACE ( f ( n )) , then for some d , the length of a configuration of N never exceeds cf ( n ) for some constant, and we can define another con- f ( n ) different stant d such that N cannot have mode than 2 d configurations.
• M works so that given an input w of length n , it calculates C ANYIELD ( c 0 , c a , 2 d f ( n ) ) , i.e., checks if N can yield an ac- cepting configuration from the initial configuration. • We still need to show that M works in O ( f ( n ) 2 ) space! • You need f ( n ) space for each active recursive copy of C ANYIELD . • How many recursive copies of C ANYIELD are there at any time? • Let us look at the values of t : Initially there is only one, one with t = 2 d f ( n ) .
• When there is one recursion running with t , then there is at most one recursive call running with t/ 2 at a time. • The ”active” values of t are then 2 d f ( n ) , 2 d f ( n ) − 1 , . . . , 2 0 , i.e., the number of calls is then at most d f ( n ) • Each requires f ( n ) space, so that the total space needed is f ( n ) 2 , meaning that M decides the language in O ( f ( n ) 2 ) d time. • We have just proven the theorem!
PSPACE • We define the set PSPACE as the class of languages that are decided in polynomial space by deternimistic Turing ma- chines. I.e., SPACE ( n k ) � PSPACE = k • We can define NPSPACE in a similar manner, by allowing for the Turing machine to be nondeterministic, but Savitch theorem has the following corollary: PSPACE = NPSPACE ! • As we have shown that SAT is in PSPACE , we have es- tablished that NP ⊆ PSPACE , and we have: P ⊆ NP ⊆ PSPACE = NPSPACE . 4
• We actually do not know if these containments are proper or if in fact the classes are all equal! • It is, however, plausible that at least not all of them are equal.
PSPACE-completeness • We define the language B as being PSPACE -complete if it satisfies the following conditions: 1. B ∈ PSPACE , and 2. Every A ∈ PSPACE is polynomial time reducible to B • If only the second condition is satisfied, we use the term PSPACE -hard. • Please note that we use the same polynomial time reducibil- ity as we did for NP -completeness. 5
• The reason for this is that ”complete” problems are consid- ered important because they are in some sense ”the most difficult” or most powerful problems of the class. • For it to be powerful, it would mean that it can be used to solve all the problems in the same class through a simple or easy transformation. • So, the reduction that is used in completeness definitions should be deterministic and simpler than the class itself. • Example: the TQBF-problem.
• Recall that Boolean formulas are expressions over boolean variables, using operators ∨ , ∧ , ¬ . • A quantifier is either ∀ or ∃ followed by a variable. A quan- tified Boolean formula or QBF , is defined as follows: 1. Every Boolean formula φ is a QBF 2. If φ is a QBF and x is a variable, then ∀ x ( φ ) and ∃ x ( φ ) are QBFs. • This kind of formula is actually a restricted QBF , in that it is in prenex normal form , meaning that all the quantifiers appear only in the front of the formula (please check that this is so!)
• If Q is some quantifier and Qx appears in the formula φ , then we say x is bound in φ . • A formula is fully quantified if every variable in it is bound. • Let φ x =1 mean the formula that results, when x is given the value 1 in φ . The meaning of the quantifiers is defined as – ∀ xφ is true iff φ x =1 ∧ φ x =0 is true. – ∃ xφ is true iff φ x =1 ∨ φ x =0 is true. • Then we define the language TBQF = { ( φ ) | φ is a true fully quantified boolean formula }
• Theorem: TBQF is PSPACE -complete • Proof: First we show that TBQF is in PSPACE . Consider the following algorithm, with ( φ ) as input: 1. If φ has no quantifiers, then it contains only constants, and we can evaluate it, and accept if true 2. If φ = ∃ xψ , we recursively decide the truth values of ψ x =0 and ψ x =1 and accept if one of them is true, oth- erwise reject 3. If φ = ∀ xψ , we recursively decide the truth values of ψ x =0 and ψ x =1 and accept if both are true, otherwise reject
• Again, the number of recursive calls needed is less than n , and even if we store all the intermediate formulas, we only use n 2 space. (in fact, we can make it run in O ( n ) space) • To show PSPACE -hardness, assume A is a language that can be decided in n k space by a Turing machine M • A string w is then mapped into a QBF φ that is true iff M accepts w • Let c 1 and c 2 represent configurations of M , and t be a number. We define a QBF φ c 1 ,c 2 ,t that is true iff c 1 yields c 2 in t steps.
• We build the same kind of matrix of cells as in the proof that SAT is NP -complete. The matrix has n 2 k cells: there are n k rows in the matrix, each row containing a configuration, that has length n k . We have one variable for each cell • For t = 1 , φ c 1 ,c 2 ,t is constructed for triplets of cells: either the configurations are equal, or there is some transition of M that yields c 2 from c 1 . The number of these formulas is the square of the number of the variables. • For t > 1 , we should define φ c 1 ,c 2 ,t as a formula that is equivalent to ∃ m ( φ c 1 ,m,t/ 2 ∧ φ c 1 ,c 2 ,t/ 2 ) , but this has one problem: we would need to start with t = 2 dn k (as this is the maximum number of steps) which would result in
Recommend
More recommend