\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{relsize}
\newcounter{lecnum}
\usepackage{graphicx}
\graphicspath{./}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{csquotes}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand{\abs}[1]{\lvert #1 \rvert}
\newcommand{\lecture}[4]{
   \newpage
   \setcounter{lecnum}{#1}
   \noindent

   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 16cm { {\bf CS760 Topics in Computational Complexity
                        \hfill 2024-25 Sem I} }
       \vspace{4mm}
       \hbox to 16cm { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 16cm { {\it Scribe: #4  \hfill  Lecturer: #3} }
      \vspace{2mm}}
   }
   \end{center}
   \vspace*{4mm}
}

\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}

% custom
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{commath}
\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\F}{\mathbb{F}}
\newcommand{\E}{\mathbb{E}}
\newcommand{\restr}[2]{\ensuremath{\left.#1\right|_{#2}}}
\newcommand{\aw}{\operatorname{aw}}

\begin{document}

\lecture{8}{Space Complexity (27-08-2024)}{Rohit Gurjar}{Sai Bhanu Teja, Anumalasetty Varshith}

Just like for time where we had \textbf{DTIME}($T(n)$), for space we can define a complexity class \textbf{SPACE}($S(n)$), as the set of problems for which there is a TM with working space $O(S(n)))$ at any instant of execution, where $S$ : $\N \rightarrow \N$ is a function. Below here we define working space of a TM

\section{Space requirements in TMs}
The Turing Machines is considered to have 3 Tapes, namely \textbf{Input tape }(Read only), \textbf{Working Tape }(Read and Write) and \textbf{Output Tape }(Write only).

\begin{figure}[h]
    \centering
    \includegraphics[width=0.7\linewidth]{TM_spaces.png}
    \caption{
    %\centering
        Space bounded computation \\ 
        (Image Credits: \textit{Computational Complexity: A Modern Approach} by Sanjeev Arora and Boaz Barak)
   }
    \label{fig:tm_spaces}
\end{figure}

\begin{itemize}
    \item Note that in some programs, Working tape takes significantly less space compared to input tapes and also output tape, some others might have working tape in polynomial of input tape length and output is arbitrary.
    \item Only the length (i.e., no of cells) of working tape are taken into consideration for calculating Space Complexity $S(n)$ of a problem.
    \item For decision problems, the output is only 0/1, so we don't need a separate output tape. 
\end{itemize}

\section{SPACE($S(n)$) and NSPACE($S(n)$) complexity classes}

\begin{theorem}
\[ \emph{\textbf{DTIME}}(S(n)) \subseteq \emph{\textbf{SPACE}}(S(n)) \]
\end{theorem}

\textbf{Proof:}
In the context of Deterministic Turing Machines (DTMs), if the Turing
Machines operate within a Time complexity of $T(n)$ then the space complexity $S(n)$ is at most $T(n)$ i.e., A problem solved in $S(n)$ time must be solved in $S(n)$ space. This is because, a machine running in time $T(n)$ can only access that many cells of the tape. 

In particular, \textbf{P} $\subseteq$ \textbf{PSPACE} (i.e., if you run only polytime, you can take only poly space)

\begin{definition}
    \emph{\textbf{NSPACE}}$(S(n)):$ Similar to \emph{\textbf{SPACE}}$(S(n))$, but Non-Deterministic TM instead.
\end{definition}

\begin{theorem}
\[ \emph{\textbf{NSPACE}}(S(n)) \subseteq \emph{\textbf{DTIME}}(2^{O(S(n))}) \]
\end{theorem}

\textbf{Proof:}
To prove this, we use the notion of a \emph{configuration graph} of a TM. A configuration of a TM consists of 1) Content on tape 2) State 3) Head position. For a TM with space-bound $S(n)$, the length of tape in TM is $S(n)$, so 
the number of possibilities for the contents of the tape is $2^{S(n)}$, number of possible head positions on the work tape is $S(n)$, and number of head positions on the input tape is $n$.  So, the total number of possible Turing Machine configurations is $n \times S(n) \times 2^{S(n)}$. Note that we will consider $n \times S(n) \times  2^{S(n)}$ as $2^{O(S(n))}$ because, in general, we assume $S(n) = \Omega (\log n)$. 


The configuration graph of $M$ on input $x$, denoted $G_{M,x}$ is a directed graph with various configurations as nodes and there is an edge from C$^\prime$ and C$^{\prime\prime}$ iff C$^{\prime\prime}$ is among the next possible configurations after  C$^\prime$. After constructing $G_{M,x}$ in $2^{O(S(n))}$-time, check whether $C_{start}$ is connected to $C_{accept}$ in $G_{M,x}$ using the standard (linear in the number of edges of the graph) BFS algorithm.



So combining both the above results

\[ \text{\textbf{DTIME}}(S(n)) \subseteq \text{\textbf{SPACE}}(S(n)) \subseteq \text{\textbf{NSPACE}}(S(n)) \subseteq \text{\textbf{DTIME}}(2^{O(S(n))}) \]

\section{Some space complexity classes}

\begin{definition}
    \[ \emph{\textbf{PSPACE}} = \cup_{c>0} \emph{\textbf{SPACE}}(n^c) \]
    \[ \emph{\textbf{NPSPACE}} = \cup_{c>0} \emph{\textbf{NSPACE}}(n^c) \]
    \[ \emph{\textbf{L}} = \emph{\textbf{SPACE}}(\log n) \]
    \[ \emph{\textbf{NL}} = \emph{\textbf{NSPACE}}(\log n) \]
\end{definition}

Interestingly, many problems can be solved with space $S(n) < n$, but this is not the case with time. $T(n) < n$, doesn't make sense as we need at least n time to read input. \\

Can we prove \textbf{NP} $\subseteq$ \textbf{PSPACE}?

Yes, We know that any problem in \textbf{NP} reduces to 3SAT. If we prove 3SAT $\in$ \textbf{PSPACE}, then we are done. We can solve 3SAT by iterating over all possible assignments which takes $O(|\text{input}|)$ space (like all 0's to all 1's i.e., 0 to $2^n-1$). Hence \textbf{NP} $\subseteq$ \textbf{PSPACE}. \\

\begin{theorem}
    \[ \emph{\textbf{L}} \subseteq \emph{\textbf{NL}} \subseteq \emph{\textbf{P}} \subseteq \emph{\textbf{NP}} \subseteq \emph{\textbf{PSPACE}} \subseteq \emph{\textbf{NPSPACE}} \subseteq \emph{\textbf{EXP}} \]
\end{theorem}

Analogous to time hierarchy theorem, there is a space hierarchy theorem. 
By these hierarchy theorems, 
we definitely know that \textbf{L} $\neq$ \textbf{PSPACE} and \textbf{P} $\neq$ \textbf{EXP}. We don't know about equality or strict subsets for others (for now).

\subsection{Some examples of problems in L}
Some straightforward examples are
\begin{itemize}
    \item Finding the index of minimum value in an array
    \item Verifying if $(a + b)$ is equal to c
\end{itemize}
Now let us see some Non-obvious examples. Both the problems are Homework. A suggestion is to first try to prove composition and later try multiplication.
\begin{itemize}
    \item Verifying if $(a \times b)$ is equal to c
    \item Let $f, g$ : $\N \rightarrow \N$ be two functions such that (computing $f$) $\in$ \textbf{L} and (computing $g$) $\in$ \textbf{L}, then computing the composition $f(g(x)) \in$ \textbf{L}
\end{itemize}

It seems difficult to conceive of any complicated computations use only $O(\log n)$ space. Nevertheless, we cannot currently even rule out that 3SAT $\in$ \textbf{L}. For example, the path problems below.

\begin{enumerate}
    \item In 2005, Reingold showed that the undirected graph st-connectivity problem described below is in \textbf{L} without using random walks
    \[ \text{\textbf{USTCON}} = \{ \langle G, s, t \rangle : G \text{ is an undirected graph in which there is a path from }
    s \text{ to } t \} \]
    \item Similar problem in case of directed graph is showed to be in \textbf{NL}
     \[ \text{\textbf{DSTCON}} = \{ \langle G, s, t \rangle : G \text{ is an a directed graph in which there is a path from }
    s \text{ to } t \} \]
\end{enumerate}

The reason is that a non-deterministic machine can take a \enquote{non-deterministic walk} (Not random walk). With starting at $s$, non-deterministically selecting a neighbour to go to the next node. The machine accepts iff the walk ends at $t$ in at most $n$ steps, where $n$ is the number of nodes. If the non-deterministic walk has run for $n$ steps already and $t$ has not been encountered, the machine rejects. The space complexity is $O(\log n)$ because we only
need to remember the index of the current node. \\

Is \textbf{DSTCON} $\in$ L? Open question. \\ 

Why don't random walks work in case of directed graph? Because they do not ensure high probability. For example,

\begin{center}
    \begin{tikzpicture}[->, >=stealth, node distance=1.5cm, main/.style = {circle, draw, minimum size=0.5cm}]

    % Nodes in a line
    \node[main] (s) {s};
    \node[main] (a) [right of=s] {a};
    \node[main] (b) [right of=a] {b};
    \node[main] (c) [right of=b] {c};
    \node[main] (d) [right of=c] {d};
    \node[main] (e) [right of=d] {e};
    \node[main] (t) [right of=e] {t};
    
    % Node below
    \node[main] (trap) [below of=c, yshift=-1cm] {trap};
    
    % Directed edges in a line
    \path (s) edge (a);
    \path (a) edge (b);
    \path (b) edge (c);
    \path (c) edge (d);
    \path (d) edge (e);
    \path (e) edge (t);
    
    % Directed edges to the extra node
    \path (a) edge (trap);
    \path (b) edge (trap);
    \path (c) edge (trap);
    \path (d) edge (trap);
    \path (e) edge (trap);
    
    \end{tikzpicture}
\end{center}

At any position $a$ or $b$ etc, we have half the probability of taking right direction. But once we take wrong step, we can't go back again (not the case with undirected). So the probability of taking required path in random walk is very low.

Also similar to \textbf{P = NP}?, we have \textbf{L} = \textbf{NL}? as an open question. If someone wishes to solve former, it is suggested to start with latter one.

\subsection{Some examples of problems in PSPACE}
What are some interesting problems in \textbf{PSPACE}? \enquote{Interesting} means problems with polynomial time algorithm is not known but can be solved in polynomial space. Some obvious examples are SAT $\in$ \textbf{PSPACE} and UNSAT $\in$ \textbf{PSPACE}. Some other examples are

\begin{itemize}
    \item Quantified Boolean Formula (QBF)
    \[\text{Is there a satisfying assignment for this QBF }\psi = \exists x_1 \ \forall x_2 \ \exists x_3 \ \forall x_4 \ \dots \ Q x_n \ \phi(x_1, x_2,\dots,x_n)\]
\end{itemize}
To show that this problem in \textbf{PSPACE}, we can write a recursive solution $x_1$ = 0 and check for subproblem recursively. If done, then good. If not assign $x_1$ = 1 and continue. This way it takes $O(|\text{input}|)$ space

\begin{itemize}
    \item Combinatorial games (chess)
\end{itemize}

We have $8 \times 8$ standard chess board. But theoretical people work on a generalised chess with $n \times n$ size. If we observe, Asking if there is a winning strategy for player 1 is like QBF i.e., Is there a move for player 1 such that for all moves of player 2 (and so on) player 1 can win. Similarly, it was shown that all Two-player games with perfect information (no randomness) and polynomial stopping time were shown to be in \textbf{PSPACE}. Next ones are other examples of this.

\clearpage

\begin{itemize}
    \item Chocolate poison game (Chomp)
\end{itemize}

\begin{figure}[h]
    \centering
    \includegraphics[width=\linewidth]{chocolate_poisson.png}
    \caption{
    %\centering
        Chocolate poison game \\ 
        (Image Credits: Chomp - Wikipedia)
    }
    \label{fig:enter-label}
\end{figure}

The players take it in turns to choose one block and \enquote{eat it} (remove from the board), together with those that are below it and to its right. The top left block is \enquote{poisoned} and the player who eats this loses

\begin{itemize}
    \item POSET games
\end{itemize}

In such games, two players start with a poset (a partially ordered set) and take turns choosing one point in the poset, removing it and all points that are greater. The player who is left with no point to choose, loses. (This is infact generalization of above Chomp game). \\

\subsection{Towards PSPACE-completeness}

We don't know if \textbf{P} and \textbf{PSPACE} are equal or not. We even don't know is POSET game is in \textbf{P} or not. (If we would like to prove \textbf{P} = \textbf{PSPACE}, it might be a good start to prove POSET game is in \textbf{P}). \\

To compare \textbf{NP} and \textbf{PSPACE}, we don't have any proof for not being equal. But we can see puzzles are like \textbf{NP} and games are like \textbf{PSPACE}. Proving \textbf{NP} and \textbf{PSPACE} are equal is like saying winning games is like solving puzzles. It is also stated in the book \textit{Games, Puzzles, and Computation} by  Robert A. Hearn and Erik D. Demaine as \\

\enquote{The problem of solving a general Sudoku puzzle is \textbf{NP-complete} and Determining the outcome of a generalized Chess game played on an $n \times n$ board is \textbf{PSPACE-complete}}.\\

Since complete problems can help capture the essence of a complexity class, we'll next define a class of problems called \textbf{PSPACE-complete}. In fact POSET game is a \textbf{PSPACE-complete} problem.



\end{document}