We prove NL = co-NL; the general case follows similarly. It suffices to show that co-NL ⊆ NL.
Let L ∈ co-NL, so L̅ ∈ NL. We'll construct an NL algorithm for L.
Consider the canonical NL-complete problem NON-PATH: given a directed graph G and vertices s,t, is there no path from s to t?
Key insight: Use an inductive counting argument. For i = 0, 1, ..., n, let Ci be the number of vertices reachable from s in exactly i steps.
Algorithm for NON-PATH:
- Set
C₀ = 1 (only s is reachable in 0 steps) - For
i = 1 to n:- Nondeterministically guess
Ci - Verify that exactly
Ci vertices are reachable in ≤ i steps - Verify that exactly
Ci - Ci-1 new vertices are reachable in exactly i steps
- Accept iff
t is not among the vertices reachable in ≤ n steps
Verification step: To verify that exactly k vertices satisfy property P:
- Nondeterministically guess
k vertices - Verify each satisfies
P - For each vertex
v, verify that if v satisfies P, then v is among the guessed vertices
Space analysis: At each step, we need O(log n) space to store counts and current vertex positions. The total space remains O(log n).
Correctness: The algorithm accepts iff there are exactly Cn vertices reachable from s and t is not among them, which is equivalent to no path existing.