You are on page 1of 32

Theory of Computation

Lecture #43
Sarmad Abbasi
Virtual University

Sarmad Abbasi (Virtual University)

Theory of Computation

1 / 31

Space Complexity

Our goal today is to prove the following theorem:

Theorem
NL = co-NL.

Sarmad Abbasi (Virtual University)

Theory of Computation

2 / 31

Space Complexity

We will show that


1

There is a problem PATH that is NL-complete with respect to


LOGSPACE reducibility.

We will show that PATH is in NL. This means that PATH is in


co-NL.

Sarmad Abbasi (Virtual University)

Theory of Computation

3 / 31

Space Complexity

Note that

Theorem
A L B
if and only if
A L B

Sarmad Abbasi (Virtual University)

Theory of Computation

4 / 31

Space Complexity

This implies that PATH is co-NL complete. Since we will also show that
PATH
is in NL. This would tell us that NL = co NL.

Sarmad Abbasi (Virtual University)

Theory of Computation

5 / 31

Space Complexity

Let G be a directed graph and s and t be two designated vertices in G.


Let
PATH = {hG, s, ti : there is a path from s to t in G}.
Thus given two vertices in a graph we have to decide if there is a path
from s to t in a graph. This problem is also called s t-connectivity.

Sarmad Abbasi (Virtual University)

Theory of Computation

6 / 31

Space Complexity

Savatichs theorem tell us that


PATH DSPACE(log2 n).

Sarmad Abbasi (Virtual University)

Theory of Computation

7 / 31

Space Complexity

We want to show that


1

PATH is in NL.

PATH is NL-complete.

Sarmad Abbasi (Virtual University)

Theory of Computation

8 / 31

Space Complexity

To see that PATH is in NL we recall that non-determinism allows us to


guess. Thus given s and t we can try to guess the path from s to t and
accept if we find one. However, we are only allowed to use small
amount of space. So we have to be a bit more careful.

Sarmad Abbasi (Virtual University)

Theory of Computation

9 / 31

Space Complexity
Consider the following non-deterministic algorithm.
1

Input G = (V , E) and s, t V .

Set current vertex v = s;

For i = 1, . . . , n

Guess a vertex w V ;

if (v , w) 6 E reject;

else if w = t accept;

v = w;

The space used by this algorithm is the space to store i and v the
current vertex. The maximum value of i is n and there are n vertices in
the graph. Thus the total space used in O(log n).

Sarmad Abbasi (Virtual University)

Theory of Computation

10 / 31

Space Complexity

The algorithm is trying to guess a path. The trick is that it does so by


guessing one vertex at a time. It does not bother to remember the
previous vertices of the path thereby saving space.

Sarmad Abbasi (Virtual University)

Theory of Computation

11 / 31

Space Complexity

Now we would like to show that PATH is NL-complete. Let A L then


there is a non-deterministic TM M that accepts A.

Sarmad Abbasi (Virtual University)

Theory of Computation

12 / 31

Space Complexity

On an input x the NTM M performs a computation. Let think of making


a graph as follows:
1

The vertices in the graph are the configurations of M on the input


x.
A configuration c us connected to c 0 if and only if c yields c 0 in one
step.

Sarmad Abbasi (Virtual University)

Theory of Computation

13 / 31

Space Complexity

To find out if M accepts x all we have to is to find out if from the vertex
that corresponds to the initial configuration can we reach a vertex that
corresponds to the final configuration.

Sarmad Abbasi (Virtual University)

Theory of Computation

14 / 31

Space Complexity
Note that each configuration c of a NTM is specified by
1

The contents of the work tape.

The position of the head reading the work tape.

The position of the head reading the input tape.

Thus all configurations are given by


c = (w, i, j)
where w is the the contents of the work tape and the machine is
currently reading the i-th symbol on the work tape and the j-th symbol
of the input.

Sarmad Abbasi (Virtual University)

Theory of Computation

15 / 31

Space Complexity

Since M runs in LOGSPACE thus all such configurations can be


enumerated in LOGSPACE.
It is also easy to see that for any given configuration c we can compute
in LOGSPACE the configurations reachable from c in one step. Thus
we can output the edges of this whole graph.

Sarmad Abbasi (Virtual University)

Theory of Computation

16 / 31

Space Complexity

Let us denote by
GM (x)
the graph described above. Let us consider the following algorithm.
1

On input x.

Compute GM (x)

Output hGM (x), ci , cf )

Where ci is the initial configuration of M on x and cf is the final


configuration.

Sarmad Abbasi (Virtual University)

Theory of Computation

17 / 31

Space Complexity

This is a reducibility that shows that


A L PATH.
This implies that PATH is NL-complete.

Sarmad Abbasi (Virtual University)

Theory of Computation

18 / 31

Space Complexity

Next we will show that PATH is in NL. This is not a simple theorem. We
have to first understand the problem very carefully.

Sarmad Abbasi (Virtual University)

Theory of Computation

19 / 31

Space Complexity

Our goal is to design a non-deterministic TM (algorithm) that takes as


input a graph G and two vertices s and t. The TM M must have the
following properties:
1

If s is connected to t then all branches of M must reject.

If s is not connected to t then at least one branch of M must


accept.

M must run in (non-deterministic) LOGSPACE.

Sarmad Abbasi (Virtual University)

Theory of Computation

20 / 31

Space Complexity

What is the major difficulty? The problem is that non-deterministic TMs


are very good at finding things. However, this time a non-determnistic
TM has to accept is there is no path from s to t. So, it is a counter
intuitive problem from the point of view of non-determinism.

Sarmad Abbasi (Virtual University)

Theory of Computation

21 / 31

Space Complexity

This is a difficult problem to solve. So, we start with solving a much


simpler problem. Let us say we are given the following information.
1

We are given an input graph G = (V , E) and two vertices s and t.

We are told a number c. This is the number of vertices in G that


are reachable from s.

We have to design a LOGSPACE NTM.

The TM will reject all inputs where s is connected to t.

At least one branch of M will accept if s is not connected to t.

Sarmad Abbasi (Virtual University)

Theory of Computation

22 / 31

Space Complexity
This problem is easier to solve. Let us look at a overview of a
non-deterministic TM that solves this problem and then we will improve
it.
1

Input G, s, t and a number c (It is promised that there are exactly c


vertices that are reachable from s)

Guess c vertices v1 , . . . , vc

if t = vi for some i reject.

For i = 1, . . . , c

Guess a path from s to vi

Verify the path from s to t by checking edges of G.

If the path is not valid reject.

Accept.

Sarmad Abbasi (Virtual University)

Theory of Computation

23 / 31

Space Complexity

This machine solves the problem. Lets see why! For it to reach accept
state it would verify that at least c vertices are reachable from s and t
is not one of them. Furthermore, if t is not reachable from s and the
machine makes all the right guesses it will accept. Thus at least one
branch will accept if and only if t is not reachable from s. But how
much space does this algorithm take?

Sarmad Abbasi (Virtual University)

Theory of Computation

24 / 31

Space Complexity
There are two problems in the algorithm.
1

It has to guess and remember {v1 , . . . , vc }.

It has to guess a path from s to vi and remember and verify it.

This is too space wasteful. So, we use the previous trick that we used
to solve PATH. We do not need to guess the whole set
{v1 , . . . , vc }
and similarly we do not need to guess the whole path. We can guess
them as we go along. Thus saving space. Let us look at these ideas
clearly.

Sarmad Abbasi (Virtual University)

Theory of Computation

25 / 31

Space Complexity

Let V = {v1 , . . . , vn } be a set of vertices. What we want to do is think


about choosing a subset of size c from these vertices. A subset can be
encoded in a 0/1 vector. Let
(g1 , . . . , gn )
be a 0/1 vector. Then
G = {vi : gi = 1}
is a subset of V .

Sarmad Abbasi (Virtual University)

Theory of Computation

26 / 31

Space Complexity

What we can do is guess the current bit of this vector one at a time.
Thus if gi = 1 we are guessing that the vertex is in G otherwise not.
Also, as we did previously we can forget all the previous bits and only
remember the number of them which were in G this way we will know
the size of G at the end of the loop.

Sarmad Abbasi (Virtual University)

Theory of Computation

27 / 31

Space Complexity
1

2
3
4
5
6
7
8
9
10
11
12
13
14

Input G, s, t and a number c (It is promised that there are exactly c


vertices that are reachable from s)
Set d = 0.
For each vertex x V .
Guess a bit g.
If g = 1 (The algorithm has guessed that x is connected to s).
Set current vertex v = s;
For i = 1, . . . , n
Guess a vertex w V ;
if (v , w) 6 E reject;
else if w = x exit the For i loop.
v = w;
if x = t reject;
d = d + 1;
if d = c then accept.

Sarmad Abbasi (Virtual University)

Theory of Computation

28 / 31

Space Complexity

The previous algorithm tells us that given a graph G = (V , E) and a


source s if we can compute in LOGSPACE a number of vertices
reachable form s then we can solve the PATH problem in
non-deterministic LOGSPACE.

Sarmad Abbasi (Virtual University)

Theory of Computation

29 / 31

Space Complexity

Now, our task is a bit simpler. But we notice that it is even simpler than
we thought. What we want is an non-deterministic algorithm that does
the following.
1

On input G and s.

At least one branch of M should output a number c the number of


nodes reachable from s.

All other branches should reject.

Sarmad Abbasi (Virtual University)

Theory of Computation

30 / 31

Space Complexity

If we can accomplish the previous task we could run our algorithm at


the branches that output c and get our algorithm.

Sarmad Abbasi (Virtual University)

Theory of Computation

31 / 31

Space Complexity

However, solving this problem requires another similar idea. We will


study that idea in the next lecture.

Sarmad Abbasi (Virtual University)

Theory of Computation

32 / 31

You might also like