Université Paris 5 – René Descartes LIPADE
Algorithmic Complexity Space Complexity
Jean-Guy Mailly ([email protected])
2017 Outline 1
Basics on Space Complexity
Main Space Complexity Classes Deterministic and Non-Deterministic Space Space-Time Relations
Determining Space Complexity Hardness and Completeness Well-Known Problems
J.-G. Mailly | Complexity – Space Space Used by a Turing Machine 2
I If M is a Turing Machine and x an input word, the space used by M on x is the number of different squares visited by M during the computation. I For f : N → N, we say that a Turing Machine M works with space O(f (n)) if
I M stops for every input x
I on every input x, M uses on x a space s(n) with s(n) ∈ O(f (n))
J.-G. Mailly | Complexity – Space Space Complexity Classes 3
I For f : N → N, DSPACE(f (n)) is the set of languages which are decided by a deterministic Turing Machine M working with space O(f (n)). I For f : N → N, NSPACE(f (n)) is the set of languages which are decided by a non-deterministic Turing Machine M working with space O(f (n)).
J.-G. Mailly | Complexity – Space Deterministic vs Non-Deterministic Space 4
Intuition: Non-determinism is not “so important” for space complexity... Theorem [Savitch 1970] For all function f space-constructible,
DSPACE(f (n)) ⊆ NSPACE(f (n)) ⊆ DSPACE(f (n)2)
J.-G. Mailly | Complexity – Space Complement Classes 5
Proposition For all function f (n) space-constructible,
DSPACE(f (n)) = CODSPACE(f (n))
Theorem [Immerman 1988, Szelepcsényi 1988] For all function f (n) ≥ log(n) space-constructible,
NSPACE(f (n)) = CONSPACE(f (n))
J.-G. Mailly | Complexity – Space Outline 6
Basics on Space Complexity
Main Space Complexity Classes Deterministic and Non-Deterministic Space Space-Time Relations
Determining Space Complexity Hardness and Completeness Well-Known Problems
J.-G. Mailly | Complexity – Space L ⊆ PSPACE
Deterministic Space Complexity 7
I L = DSPACE(log(n)) is the class of decision problems that can be solved by a DTM using logarithmic space S k I PSPACE = k>0 DSPACE(n ) is the class of decision problems that can be solved by a DTM using polynomial space
J.-G. Mailly | Complexity – Space Deterministic Space Complexity 7
I L = DSPACE(log(n)) is the class of decision problems that can be solved by a DTM using logarithmic space S k I PSPACE = k>0 DSPACE(n ) is the class of decision problems that can be solved by a DTM using polynomial space L ⊆ PSPACE
J.-G. Mailly | Complexity – Space NL ⊆ NPSPACE
Non-Deterministic Space Complexity 8
I NL = NSPACE(log(n)) is the class of decision problems that can be solved by a NDTM using logarithmic space S k I NPSPACE = k>0 NSPACE(n ) is the class of decision problems that can be solved by a NDTM using polynomial space
J.-G. Mailly | Complexity – Space Non-Deterministic Space Complexity 8
I NL = NSPACE(log(n)) is the class of decision problems that can be solved by a NDTM using logarithmic space S k I NPSPACE = k>0 NSPACE(n ) is the class of decision problems that can be solved by a NDTM using polynomial space NL ⊆ NPSPACE
J.-G. Mailly | Complexity – Space Proof:
I For any k > 0, NSPACE(nk ) ⊆ DSPACE((nk )2) = DSPACE((n2k ) ⊆ PSPACE, so NPSPACE ⊆ PSPACE k k I For any k > 0, DSPACE(n ) ⊆ NSPACE(n ) ⊆ NPSPACE, so PSPACE ⊆ NPSPACE
PSPACE vs NPSPACE 9
Proposition
PSPACE = NPSPACE
J.-G. Mailly | Complexity – Space PSPACE vs NPSPACE 9
Proposition
PSPACE = NPSPACE Proof:
I For any k > 0, NSPACE(nk ) ⊆ DSPACE((nk )2) = DSPACE((n2k ) ⊆ PSPACE, so NPSPACE ⊆ PSPACE k k I For any k > 0, DSPACE(n ) ⊆ NSPACE(n ) ⊆ NPSPACE, so PSPACE ⊆ NPSPACE
J.-G. Mailly | Complexity – Space Corollary
NP ⊆ PSPACE
Relations Between Time and Space (1/3) 10
Proposition For any mapping f : N → N, NTIME(f (n)) ⊆ DSPACE(f (n))
J.-G. Mailly | Complexity – Space Relations Between Time and Space (1/3) 10
Proposition For any mapping f : N → N, NTIME(f (n)) ⊆ DSPACE(f (n))
Corollary
NP ⊆ PSPACE
J.-G. Mailly | Complexity – Space Relations Between Time and Space (2/3) 11
Polynomial Hierarchy vs Polynomial Space
PH ⊆ PSPACE
Intuition For each class of the polynomial hierharchy, there is a complete problem ∀i QBF or ∃i QBF. All these problems are special instances of TQBF, so they are in PSPACE.
J.-G. Mailly | Complexity – Space Relations Between Time and Space (3/3) 12
P NP P Σ2 L ⊆ NL ⊆ P ⊆ coNP ⊆ ∆2 ⊆ P ⊆ · · · ⊆ PH ⊆ PSPACE ⊆ EXP ⊆ NEXP Π2 We also know that some inclusions are strict:
I NL ⊂ PSPACE
I P ⊂ EXP
J.-G. Mailly | Complexity – Space Outline 13
Basics on Space Complexity
Main Space Complexity Classes Deterministic and Non-Deterministic Space Space-Time Relations
Determining Space Complexity Hardness and Completeness Well-Known Problems
J.-G. Mailly | Complexity – Space 0 P I A problem P is C-hard if for every problem P’ in C, P ≤f P, i.e. there is a polynomial reduction from any problem in C to P
I A problem is C-complete if it is in C and it is C-hard
I This definition works for PSPACE-hardness and PSPACE-completeness
I It does not work for L and NL
Completeness for Space Complexity Classes 14
The notions of hardness and completeness exist for space complexity classes.
I For most of the complexity classes, the definition is exactly the same as hardness and completeness for time complexity
J.-G. Mailly | Complexity – Space I A problem is C-complete if it is in C and it is C-hard
I This definition works for PSPACE-hardness and PSPACE-completeness
I It does not work for L and NL
Completeness for Space Complexity Classes 14
The notions of hardness and completeness exist for space complexity classes.
I For most of the complexity classes, the definition is exactly the same as hardness and completeness for time complexity 0 P I A problem P is C-hard if for every problem P’ in C, P ≤f P, i.e. there is a polynomial reduction from any problem in C to P
J.-G. Mailly | Complexity – Space I This definition works for PSPACE-hardness and PSPACE-completeness
I It does not work for L and NL
Completeness for Space Complexity Classes 14
The notions of hardness and completeness exist for space complexity classes.
I For most of the complexity classes, the definition is exactly the same as hardness and completeness for time complexity 0 P I A problem P is C-hard if for every problem P’ in C, P ≤f P, i.e. there is a polynomial reduction from any problem in C to P
I A problem is C-complete if it is in C and it is C-hard
J.-G. Mailly | Complexity – Space I It does not work for L and NL
Completeness for Space Complexity Classes 14
The notions of hardness and completeness exist for space complexity classes.
I For most of the complexity classes, the definition is exactly the same as hardness and completeness for time complexity 0 P I A problem P is C-hard if for every problem P’ in C, P ≤f P, i.e. there is a polynomial reduction from any problem in C to P
I A problem is C-complete if it is in C and it is C-hard
I This definition works for PSPACE-hardness and PSPACE-completeness
J.-G. Mailly | Complexity – Space Completeness for Space Complexity Classes 14
The notions of hardness and completeness exist for space complexity classes.
I For most of the complexity classes, the definition is exactly the same as hardness and completeness for time complexity 0 P I A problem P is C-hard if for every problem P’ in C, P ≤f P, i.e. there is a polynomial reduction from any problem in C to P
I A problem is C-complete if it is in C and it is C-hard
I This definition works for PSPACE-hardness and PSPACE-completeness
I It does not work for L and NL
J.-G. Mailly | Complexity – Space L P Observation: If P1 ≤f P2, then P1 ≤f P2
NL-Hardness and NL-Completeness 0 0 L I A problem P is NL-hard iff ∀P ∈ NL, P ≤f P I A problem P is NL-complete iff P is NL-hard and P ∈ L
Logarithmic Space and Completeness 15
Logarithmic-Space Functional Reduction A logarithmic-space functional reduction f is a total computable function from a problem P1 to a problem P2 such that, for any instance i of P1,
I f (i) can be computed in logarithmic-space in the size of i
I i is a positive instance of P1 iff f (i) is a positive instance of P2 L Notation: P1 ≤f P2
J.-G. Mailly | Complexity – Space NL-Hardness and NL-Completeness 0 0 L I A problem P is NL-hard iff ∀P ∈ NL, P ≤f P I A problem P is NL-complete iff P is NL-hard and P ∈ L
Logarithmic Space and Completeness 15
Logarithmic-Space Functional Reduction A logarithmic-space functional reduction f is a total computable function from a problem P1 to a problem P2 such that, for any instance i of P1,
I f (i) can be computed in logarithmic-space in the size of i
I i is a positive instance of P1 iff f (i) is a positive instance of P2 L Notation: P1 ≤f P2 L P Observation: If P1 ≤f P2, then P1 ≤f P2
J.-G. Mailly | Complexity – Space Logarithmic Space and Completeness 15
Logarithmic-Space Functional Reduction A logarithmic-space functional reduction f is a total computable function from a problem P1 to a problem P2 such that, for any instance i of P1,
I f (i) can be computed in logarithmic-space in the size of i
I i is a positive instance of P1 iff f (i) is a positive instance of P2 L Notation: P1 ≤f P2 L P Observation: If P1 ≤f P2, then P1 ≤f P2
NL-Hardness and NL-Completeness 0 0 L I A problem P is NL-hard iff ∀P ∈ NL, P ≤f P I A problem P is NL-complete iff P is NL-hard and P ∈ L
J.-G. Mailly | Complexity – Space To define a meaningful notion of L-completeness, the hardness must be defined with another kind of functional reductions More details in [Garey and Johnson 1979]
What About L-Completeness? 16
Theorem L Any problem in L is L-complete with respect to ≤f !
J.-G. Mailly | Complexity – Space What About L-Completeness? 16
Theorem L Any problem in L is L-complete with respect to ≤f !
To define a meaningful notion of L-completeness, the hardness must be defined with another kind of functional reductions More details in [Garey and Johnson 1979]
J.-G. Mailly | Complexity – Space Complexity of TQBF [ TQBF = (∃nQBF ∪ ∀nQBF) n≥1 TQBF is PSPACE-complete
Canonical PSPACE-Complete Problem 17
Reminder:
I A canonical QBF is a formula Q1X1, Q2X2,... QnXn, φ:
I Qi ∈ {∀, ∃} and Qi 6= Qi+1 I X1,... Xn form a partition of the Boolean variables in φ I φ is a propositional formula
I ∃nQBF: is the QBF ∃X1, ∀X2,... QnXn, φ true?
I ∀nQBF: is the QBF ∀X1, ∃X2,... QnXn, φ true?
J.-G. Mailly | Complexity – Space Canonical PSPACE-Complete Problem 17
Reminder:
I A canonical QBF is a formula Q1X1, Q2X2,... QnXn, φ:
I Qi ∈ {∀, ∃} and Qi 6= Qi+1 I X1,... Xn form a partition of the Boolean variables in φ I φ is a propositional formula
I ∃nQBF: is the QBF ∃X1, ∀X2,... QnXn, φ true?
I ∀nQBF: is the QBF ∀X1, ∃X2,... QnXn, φ true?
Complexity of TQBF [ TQBF = (∃nQBF ∪ ∀nQBF) n≥1 TQBF is PSPACE-complete
J.-G. Mailly | Complexity – Space Complexity of (m, n, k)-STRAT (m − n − k)-STRAT is the decision problem: “Is there a winning strategy for player X in the (m, n, k) game?” (m − n − k)-STRAT is PSPACE-complete
PSPACE vs Games Tic-Tac-Toe 18
I Classical Tic-Tac-Toe: In a 3 × 3 grid, two players must draw some marks (X or O). The winner is the first who has placed three marks in a horizontal, vertical or diagonal row
I Generalized Tic-tac-toe ((m, n, k) game): In a m × n grid, a player wins when he has placed k marks in a row
I A winning strategy at time t for a player is a sequence of moves (drawing a mark in the grid) such that the player wins.
J.-G. Mailly | Complexity – Space PSPACE vs Games Tic-Tac-Toe 18
I Classical Tic-Tac-Toe: In a 3 × 3 grid, two players must draw some marks (X or O). The winner is the first who has placed three marks in a horizontal, vertical or diagonal row
I Generalized Tic-tac-toe ((m, n, k) game): In a m × n grid, a player wins when he has placed k marks in a row
I A winning strategy at time t for a player is a sequence of moves (drawing a mark in the grid) such that the player wins.
Complexity of (m, n, k)-STRAT (m − n − k)-STRAT is the decision problem: “Is there a winning strategy for player X in the (m, n, k) game?” (m − n − k)-STRAT is PSPACE-complete
J.-G. Mailly | Complexity – Space I This can be represented as a QBF formula
PSPACE vs Games Tic-Tac-Toe: Intuition 19
I Determining if there is a winning strategy for player X is like asking the question: Is there a way to draw an X at step 1, such that for all possible moves of the O player at step 2, there is a way to draw an X at step 3, such that for all possible moves of the O player at step 4, there is ... such that X player wins?
J.-G. Mailly | Complexity – Space PSPACE vs Games Tic-Tac-Toe: Intuition 19
I Determining if there is a winning strategy for player X is like asking the question: Is there a way to draw an X at step 1, such that for all possible moves of the O player at step 2, there is a way to draw an X at step 3, such that for all possible moves of the O player at step 4, there is ... such that X player wins?
I This can be represented as a QBF formula
J.-G. Mailly | Complexity – Space Generalized Super Mario Bros. [Demaine et al. 2016] 20
FIGURE: Super Mario Bros. is PSPACE-complete
J.-G. Mailly | Complexity – Space Lemmings [Viglietta 2015] 21
FIGURE: Lemmings is PSPACE-complete
J.-G. Mailly | Complexity – Space NL-Complete Problem in Graphs 22
Reach
Given a directed graph G = hN, Ei and two nodes n1, n2 ∈ N, is there a path from n1 to n2 in G?
Theorem [Papadimitriou 1994] Reach is NL-complete
J.-G. Mailly | Complexity – Space NL-Complete Problem in Logics 23
Reminder on 2SAT 2SAT is a special case of satisfiability problem where only CNF formulas with binary clauses are considered
Theorem [Papadimitriou 1994] 2SAT is NL-complete
J.-G. Mailly | Complexity – Space References 24
[Savitch 1970] W. J. Savitch, Relationships between nondeterministic and deterministic tape complexities. Journal of Computer and System Sciences, 177–192, 1970. [Immerman 1988] N. Immerman, Nondeterministic space is closed under complementation. SIAM Journal on Computing 17, 935–938, 1988. [Szelepcsényi 1988] R. Szelepcsényi, The Method of Forced Enumeration for Nondeterministic Automata. Acta Informatica vol. 26, no 3, 279–284, 1988.
J.-G. Mailly | Complexity – Space References 25
[Garey and Johnson 1979] M. R. Garey and D. S. Johnson, Computers and Intractability: A Guide to the Theory of NP-Completeness. W.H. Freeman. Section 7.5: Logarithmic Space, 177–181, 1979. [Papadimitriou 1994] C.H Papadimitriou, Computational Complexity. Addison-Wesley, 1994. [Demaine et al. 2016] E.D. Demaine, G. Viglietta and A. Williams, Super Mario Bros. Is Harder/Easier than We Thought. Proceedings of the 8th International Conference on Fun with Algorithms, 2016. [Viglietta 2015] G. Viglietta, Lemmings Is PSPACE-Complete. Theor. Comput. Sci. 586: 120-134, 2015.
J.-G. Mailly | Complexity – Space