# Immerman–Szelepcsényi theorem

In computational complexity theory, the Immerman–Szelepcsényi theorem was proven independently by Neil Immerman and Róbert Szelepcsényi in 1987, for which they shared the 1995 Gödel Prize. In its general form the theorem states that NSPACE(s(n)) = co-NSPACE(s(n)) for any function s(n) ≥ log n. The result is equivalently stated as NL = co-NL; although this is the special case when s(n) = log n, it implies the general theorem by a standard padding argument[citation needed]. The result solved the second LBA problem.

In other words, if a nondeterministic machine can solve a problem, it can solve its complement problem (with the yes and no answers reversed) in the same asymptotic amount of space. No similar result is known for the time complexity classes, and indeed it is conjectured that NP is not equal to co-NP.

## Proof

Theorem: Let s(n) ≥ log n be any function. Then NSPACE[s(n)] = co-NSPACE[s(n)].

The first step is to demonstrate that NL = co-NL. This can be accomplished by taking the st-connectivity problem (known to be NL-complete), and showing that the complement of this problem (called st-non-connectivity) is also in NL.

Definition: Given a directed graph G with n vertices, and vertices s and t in G, the st-non-connectivity problem is to determine whether there is no directed path between vertex s and t:

$\text{st-non-connectivity}=\{\langle G=\langle V,E\rangle,s,t\rangle\colon \text{there is no path from }s\text{ to }t\text{ in graph }G\}.$

In order to illustrate that st-non-connectivity is in NL, one can construct a non-deterministic algorithm that, in logarithmic space, decides whether two given vertices are not connected. To prove correctness of this algorithm, one must show two things:

• If the non-deterministic choices are made "correctly" and s and t are disconnected, then the algorithm accepts.
• If s and t are connected, no matter what non-deterministic choices are made the algorithm does not accept.

Here are the key ideas of the proof of the second condition. For sake of contradiction assume that s and t are connected but the algorithm accepts. To keep the adversary controlling the non-determinism "honest", the algorithm is designed so that if the non-determinism is uncooperative, the algorithm rejects at the end of the ENUMERATE subroutine. Therefore since we assumed that the algorithm accepts, the non-determinism must have been cooperative, which implies by the design of the algorithm that we should have rejected, a contradiction.

First, define Ai as follows: Ai = {v: there is a path from s to v of length ≤ i}. In other words, Ai will include all vertices that are reachable from s in i or fewer hops. Let ri = |Ai|. Note that if t is not in An−1, where n = |V|, then there is no path from s to t in G, i.e., $\langle G,s,t\rangle$ ∈ st-non-connectivity.

Lemma: An algorithm can be constructed that given ri will enumerate vertices in Ai and ACCEPT in logarithmic space. Note that if the given ri is larger than the true number of vertices in Ai, then the algorithm REJECTs; however, if ri is less than the true number of vertices in Ai the algorithm would ACCEPT but enumerate only a subset of Ai.

ENUMERATE(s,i,r_i,G)
1: Counter := 0
2: FOR ALL vertices v in G
3:    Nondeterministically either CONTINUE or guess a path of length less than or equal to i from s to v
4:    Counter := Counter + 1
5:    Output v
6:    IF Counter ≥ r_i
7:       ACCEPT
8: REJECT


ENUMERATE goes through all vertices of graph G in logarithmic space, since the representation of each vertex and the Counter requires only log |G| bits and nondeterministically selecting a path also requires only logarithmic space.

Now, with ENUMERATE at hand it is possible to compute the actual ri in log-space using an algorithm that is based on the principle of mathematical induction. When using ENUMERATE as a subroutine, replace ACCEPT in ENUMERATE with RETURN while leaving REJECT as REJECT.

Obviously r0 = 1 since Ai includes only the vertex s itself.

Now, assume ri is given. Then ri+1 can be calculated by the following algorithm in log-space:

INDUCTIVE-COUNTING (s,i,r_i,G)
1: r := 1
2: FOR ALL vertices v ≠ s:
3:    FOR EACH u such that (u,v) is an edge in G
4:       ENUMERATE (s,i,r_i,G)
5:       IF u is ever output
6:          r := r + 1
7:          BREAK
8: Output r


This algorithm first accounts for the initial vertex s, and then goes through all other vertices v of the graph G. In lines 3–6 the algorithm tries to find a vertex u in Ai directly connected to the vertex v by simulating ENUMERATE. If such vertex is found, that means that v is in Ai+1, so the result is incremented to account for this vertex. Note that the algorithm does not need to store all of the output of ENUMERATE every time it is called as a sub-routine. It can only store one vertex at a time and check if u is ever output. Thus, this algorithm runs in logarithmic space.

With this algorithm at hand we can devise an algorithm for st-non-connectivity consisting of two parts. The first part would compute rn by starting with r0 = 1 and then using INDUCTIVE-COUNTING n − 1 times. In the second part the algorithm just simulates ENUMERATE with the computed rn and if t is ever output that means it can be reached from v, and the algorithm REJECTs.

NOT-CONNECTED (G,s,t)
1: r_n := 1;
2: FOR i := 1 TO n
3:    r_n := INDUCTIVE-COUNTING (s,i,r_n,G)
4: ENUMERATE (s,n,r_n,G)
5: IF t is ever output
6:    REJECT
8: ELSE
9:    ACCEPT


This algorithm runs in logarithmic space, since we need log |G| bits for storing i and rn. As was shown above, the ENUMERATE and INDUCTIVE-COUNTING algorithms also run in logarithmic space and again we do not need to store all of the output of ENUMERATE in line 4, but need only to check if t is ever output. Thus, NOT-CONNECTED can decide if there exists no path from vertex s to t in logarithmic space. I.e., st-non-connectivity is in NL. Since we can reduce each problem in NL to st-connectivity and each problem in co-NL to st-non-connectivity we conclude that NL = co-NL.

Now, for s(n) ≥ log n we can transform the computations of any non-deterministic Turing machine M on language L into a graph of its states and simulate M using st-connectivity algorithm. Analogously we can transform any co-language into st-non-connectivity problem. Both of these graphs would have 2O(s(n)) vertices if L ∈ NSPACE(s(n)). Thus, we can decide both reachability and non-reachability of the ACCEPT state in log(2O(s(n))) = O(s(n)) space and NSPACE(s(n)) = co-NSPACE(s(n)).

## Logspace hierarchy

As a corollary, in the same article, Immerman proved that, using descriptive complexity's equality between NL and FO(Transitive Closure), the logarithmic hierarchy, i.e. the languages decided by alternating Turing machine in logarithm space with a bounded number of alternation, is the same class as NL.