Lecture 2: Logspace

Webpage of the course

Last week:

  • $TIME(f(n)), SPACE(f(n)), NTIME, NSPACE, ..$
  • Speedup Theorem (2.2)
  • $REACH$ (for directed graphs) aka $GAP$ is in $NL$ aka $NSPACE(log(n))$
  • $REACH$ is in $SPACE(log^2(n))$

Th: \(NL ⊆ P\) i.e. \(∀ℳ ∈ NL, ∃M'_ℳ ∈ P \text{ running in } P_L(n), M'_ℳ \text{ recognizes } L(ℳ)\)

Proof: the number of possible configurations of the TM is exponential in the space used. So if logarithmic space is used ⟶ polynomial time.

ndTM in Logspace:

\[M ≝ ⟨Q, Σ, k \text{ working tapes}, q_{accept}, q_{reject}, Δ⟩\]

on input $x∈Σ^\ast$

The set of configurations depends on the input: a configuration is of the form:

\[(q, \underbrace{i}_{\text{position on the lecture tape}}, \underbrace{w_1}_{\text{word on the first working tape}}, \underbrace{l_1}_{\text{position on the first working tape}}, \ldots, w_k, l_k)\]

number of configurations:

\[\vert Q \vert × \underbrace{n}_{\text{ for } i} \underbrace{\log(n)^k}_{\text{ positions on the working tapes}} × \underbrace{\vert Σ \vert^{k \log(n)}}_{\text{as the sum of the lengths is bounded by } \log(n), \text{to be more precise: } \vert Σ \vert^{ \log(n)}}\]

bounded by:

\[k_M × n^2 × n^{k \log(\vert Σ \vert)} ∈ O(n^{k_M})\]

it is polynomial in the size of the input, since the polynomial may depend on $M$ (or $L$ when considering the language)

The machine $M’_ℳ$ creates the graph of configurations so that each edge from one configuration to another match according to the transition table of $ℳ$

⟶ then: is there a path from an initial configuration to a final one ? ⟹ in polynomial time with respect to the input $x$ (the polynomial depending on $ℳ$)

Savitch Theorem (1970)

Savitch: \(NSPACE(f(n)) ⊆ SPACE(f^2(n))\)

for every space constructible $f$ (or $f(n) ≥ \log(n)$)

Space constructible ⟹ $f ≥ \log$

Proof: we will reduce this problem to $REACH$ in $SPACE(\log^2(n))$

Lemma: Let

  • $M’$ that computes $G: A^\ast ⟶ B^\ast$ in space $g(n)$ ($≥ \log(n)$)
  • $M$ that computes $F: C^\ast ⟶ A^\ast$ in space $h(n)$ (space constructible, $≥ \log(n)$)

then $∃ M’’$ that computes $G \circ F$ in space $g(\vert Γ \vert^{h(n)})$


  1. one does not write on the output tape nor does one reuse anything already written on it (one cannot scan it)
  2. it’s useless to compose the machine “naively”: the output of the first one might be too long for the second one.
  3. the output of the first one is bounded by the running time, which is bounded by the number of configurations $≤ \vert Γ \vert^{h(n)}$ since it doesn’t loop (since it terminates)

The problem is that if $g ≤ id$, $\vert Γ \vert^{h(n)}$ may be greater than $g(\vert Γ \vert^{h(n)})$

The thing is that $M’$ doesn’t even need to modify the output tape of $M$: it just needs to scan it.

$M’$ will write on the “output” tape of $M$: $i$ (remembered for later) to mean “$M$, give me $F(x)[i]$”.

Then, $M$ computes on $x$ and keeps up to date a counter to keep track of the current letter being output, then compares this counter with the $i$ of $M’$.

One doesn’t use $Γ^{h(n)}$ anymore, but just $2 \cdot h(n)$.

Then, since $g ≥ \log$,

\[h(n) = O(g(Γ^{h(n)}))\]

so that the final space complexity is $O(g(Γ^{h(n)}))$

NB: if $M’$ is non deterministic, it works exactly the same way, and $M’’$ is then non deterministic as well: $M’’$ is of the same “nature” than $M’$ (whether it be deterministic or not)

Coming back to our proof:

we want to show that $L ∈ NSPACE(f(n))$


  • $M’’$ in $SPACE(f^2(n))$
  • $M’$ : REACH in $\log^2(n)$
  • $M$ (deterministic) : generates the graph of configurations of the machine $M_L$ in $NSPACE(f(n))$ for $L$ running on $x$: $h(n) = O(f(n))$, and the size of the output (not needed) is $Γ^{f(n)}$

Corollary: \(\underbrace{PSPACE}_{≝ \bigcup_k SPACE(n^k) = SPACE(n^{O(1)})} = NPSPACE = coNPSPACE\)

trivial inclusion: $⊆$ since deterministic TMs are a special case of non-deterministic ones.

other inclusion: Savitch theorem:

\[\bigcup_k NSPACE(n^k) ⊆ \bigcup_k SPACE(n^{2k}) ⊆ \bigcup_k SPACE(n^k)\]



(co-class: you switch answers “yes” and “no” ⟶ for deterministic TM: reverse accepting and rejecting states)

Usually, non-deterministic space/time classes are NOT closed by complementation (since existentials are turned into universals)

But here, it is the case.


If $P_1, P_2$ are problems/languages $⊆ A^\ast$

$P_1$ reduces to $P_2$ in Logspace: $P_1 ≼_L P_2$:

iff there exists an $F : A^\ast ⟶ A^\ast$ logspace-computable s.t. \(∀x, x∈ P_1 ⟺ F(x) ∈ P_2\)


  • $SAT ≼_L 3\text{-}SAT$
  • the general graph accessibility problem can be reduced to the one where $s = 0, t=n$ and the number of edges is $n$

Corollary: if $P_1 ≼_L P_2$ and $P_2 ∈ P \text{ resp. } NL$, then $P_1 ∈ P \text{ resp. } NL$

Proof: application of the lemma of composition seen just before.


\[≼_L \text{ is transitive}\]

Proof: lemma of composition again.

Complete problems

$L$ is complete for $𝒞$ (under logspace reduction) iff:
\[L ∈ 𝒞 ⟺ ∀L'∈ 𝒞, L' ≼_L L\]
  • REACH aka GAP is complete for $NL$

    • to reduce any problem in $NL$: build the graph of configurations of the TM, and then: reachability problem in this graph
  • SAT is complete for $NP$: Cook-Levin Theorem (1971)

    • in $NP$: guess valuation for the variable and evaluate to check if it gives “true” or “false”
    • $NP \ni L ⊆ A^\ast$ ($M_L$ nd TM recognizing $L$) \(F_L: \begin{cases} A^\ast ⟶ B^\ast (\supset SAT) \\ x ⟼ φ_x \text{ boolean formula} \\ \end{cases}\) s.t. \(x ∈ L \text{ iff } φ \text{ is satisfiable }\)

    One constructs boolean formulas

    • $b_{t, i, a}$ which is true iff at time $t$, on position $t$, the current letter is $a$. We have $p(n) × n × \vert A \vert$ such formulas.
    • $b_{t, q}$ true iff in state $q$ at time $t$
    • $b_{t, j}$ true iff in position $j$ at time $t$

    Then we encode the conditions enforced by the transition table of the TM, so that:

    • if there is an accepting run, there will a truth valuation for the formula
    • if there is a truth valuation for the formula, on can just read the execution table to check that the word is accepted

Leave a comment