Beruflich Dokumente
Kultur Dokumente
Lecture #43
Sarmad Abbasi
Virtual University
Theory of Computation
1 / 21
Space Complexity
Theorem
NL = co-NL.
We simplified this problem by observing that
Theorem
PATH is NL-complete (with respect to logspace reducibility).
Theory of Computation
2 / 21
Space Complexity
Theorem
PATH is in NL.
Thus by showing that only one problem belongs to NL we could show
that two complexity classes were equal.
Theory of Computation
3 / 21
Space Complexity
Theory of Computation
4 / 21
Space Complexity
Theory of Computation
5 / 21
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.
Theory of Computation
6 / 21
Space Complexity
Today we will design this algorithm. Let us start. We first break up the
problem into simpler pieces (by now you should be used to of this!
Given a graph G and a vertex s let us define:
Ri = {v : there is a path from s to v of lenght at most i}.
and define
ci = |Ri |.
Theory of Computation
7 / 21
Space Complexity
and so on..
Theory of Computation
8 / 21
Space Complexity
Let us now note that c0 = 1 and in fact, the only vertex reachable from
s in 0 steps is s itself. Now, suppose we can design an algorithm that
does the following.
Given ci as an input it at least one of its branch computes ci+1
correctly and all other branches reject.
Then we can use this algorithm to eventually come up with an
algorithm that computes cn from c0 .
Theory of Computation
9 / 21
Space Complexity
ci = 0.
for i = 1, . . . , n 1
Output cn .
A few things about the algorithm. The indices are only there for clarity.
We can forget the previous ci s so the space requirements are
logarithmic.
Theory of Computation
10 / 21
Space Complexity
Now we show how we can compute ci+1 from ci . For that let us try to
see why a vertex will be in Ri+1 . We observe that a vertex x is in Ri+1
if and only if
1
It is in Ri or
Lets start with a simple idea and then refine it. We will use the
previous ideas again and again.
Theory of Computation
11 / 21
Space Complexity
count = 0;
Theory of Computation
12 / 21
Space Complexity
For each w V
If w Ri then
if w = v or (w, v ) an edge then v Ri+1 .
v 6 Ri+1 .
This idea does not work! We do not know Ri but we do know its size ci .
So, we do something cleverer.
Theory of Computation
13 / 21
Space Complexity
For each w V
Guess if w Ri
4
5
Theory of Computation
14 / 21
Space Complexity
Theory of Computation
15 / 21
Space Complexity
Consider the following program.
1
count = 0;
For w = 1, . . . , n
Guess rw {0, 1}
If rw = 1 then
l = s;
For j = 1, . . . , i
guess a vertex z
if z = l or (z, l) E then l = z;
if l 6= w then reject.
10
count = count+1;
11
if count 6= ci reject;
Theory of Computation
16 / 21
Space Complexity
A simplified version of this program is as follows.
1
count = 0;
For w = 1, . . . , n
Guess rw {0, 1}
If rw = 1 then
count = count+1;
Theory of Computation
17 / 21
Space Complexity
Now we can use this program to finish our task.
1
count = 0;
For w = 1, . . . , n
Guess rw {0, 1}
4
5
6
If rw = 1 then
verify if there is a path of length i from s to v .
if w = v or (w, v ) E then v Ri+1 we can set a bit b = 1.
count = count+1;
10
Theory of Computation
18 / 21
Space Complexity
Critically we can use this program to count the size of Ri+1 . This is
what we wanted to show.
Theory of Computation
19 / 21
Space Complexity
Theory of Computation
20 / 21
Space Complexity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
C = 1; ( c0 = 0 we know that)
For i = 1, . . . , n 1
C has ci = |Ri | and we want to compute D = ci+1
D = 0;
For v = 1, . . . , n (For each vertex lets check if it is in Ri+1 )
b = 0;
count = 0;
For w = 1, . . . , n
guess rw {0, 1}
if rw = 1
verify if there is a path of length at most i from s to w.
If verification fails reject.
else count = count+1;
if v = w or (v , w) E then b = 1;
if count 6= C reject.
D =D+b
C=D
Theory of Computation
21 / 21
Space Complexity
Theory of Computation
22 / 21
Space Complexity
Theory of Computation
23 / 21