Sie sind auf Seite 1von 23

Theory of Computation

Lecture #43
Sarmad Abbasi
Virtual University

Sarmad Abbasi (Virtual University)

Theory of Computation

1 / 21

Space Complexity

Recall that our goal was to prove that

Theorem
NL = co-NL.
We simplified this problem by observing that

Theorem
PATH is NL-complete (with respect to logspace reducibility).

Sarmad Abbasi (Virtual University)

Theory of Computation

2 / 21

Space Complexity

Thus our goal was just to prove that

Theorem
PATH is in NL.
Thus by showing that only one problem belongs to NL we could show
that two complexity classes were equal.

Sarmad Abbasi (Virtual University)

Theory of Computation

3 / 21

Space Complexity

In the previous lecture we studied an non-deterministic algorithm. The


algorithm almost did the job. But it required an extra piece of
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.

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

4 / 21

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

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.

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

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 |.

Sarmad Abbasi (Virtual University)

Theory of Computation

7 / 21

Space Complexity

R0 is the set of all vertices reachable from s via path of length 0.

R1 is the set of all vertices reachable from s via path of length 1.

R2 is the set of all vertices reachable from s via path of length 2.

R3 is the set of all vertices reachable from s via path of length 3.

and so on..

What we want to do is to find out the value of cn .

Sarmad Abbasi (Virtual University)

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 .

Sarmad Abbasi (Virtual University)

Theory of Computation

9 / 21

Space Complexity

This algorithm is going to be a simple loop.


1

ci = 0.

for i = 1, . . . , n 1

Compute ci+1 from ci .

if the computation succeeds continue.

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.

Sarmad Abbasi (Virtual University)

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

There is a vertex w Ri and (w, x) is an edge in the graph.

Lets start with a simple idea and then refine it. We will use the
previous ideas again and again.

Sarmad Abbasi (Virtual University)

Theory of Computation

11 / 21

Space Complexity

What we want to do is to count the number of vertices in Ri+1 . There is


a simple way to do this....
1

count = 0;

For each vertex v V

if v Ri+1 count = count+1;

The only problem is to check if v Ri+1 . We do not know Ri+1 .

Sarmad Abbasi (Virtual University)

Theory of Computation

12 / 21

Space Complexity

Now, given a vertex v V all we want to do is to check if v Ri+1 . We


can use the previous observation and do this job as follows:
1
2
3
4

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.

Sarmad Abbasi (Virtual University)

Theory of Computation

13 / 21

Space Complexity

We are given non-determinism at our disposal. So, we can use it over


and over again. Let us try something.....
1

For each w V

Guess if w Ri

Check if w Ri if not reject.

4
5

if w = v or (w, v ) an edge then v Ri+1 .


v 6 Ri+1 .

The problem is how do we check if w Ri . Here we use our old trick.

Sarmad Abbasi (Virtual University)

Theory of Computation

14 / 21

Space Complexity

Note that our subset Ri can be specified by n-bits


(r1 , . . . , rn )
where ri = 1 if and only if i Ri . Suppose we could guess a bit vector
(r1 , . . . , rn ).

Sarmad Abbasi (Virtual University)

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;

Sarmad Abbasi (Virtual University)

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

verify if there is a path of length i from s to w.

if verification fails reject.

count = count+1;

if count 6= ci reject (the guess of rv s was wrong);

Sarmad Abbasi (Virtual University)

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.

if verification fails reject.

count = count+1;

if count 6= ci reject (the guess of rv s was wrong);

10

if b = 1 then v Ri+1 else it is not.

Sarmad Abbasi (Virtual University)

Theory of Computation

18 / 21

Space Complexity

This non deterministic program has the following property.


1

On input v and the number ci .

At least one of the branch outputs a number b {0, 1} such that


b = 1 if and only if b Ri+1 .

All other branches reject.

Critically we can use this program to count the size of Ri+1 . This is
what we wanted to show.

Sarmad Abbasi (Virtual University)

Theory of Computation

19 / 21

Space Complexity

Lets look at this program again. It is a highly non-deterministic


program. But it only uses counters! It is one of the most wonderful
programs and has only theoretical implications. Lets revisit it. Now, we
will not use indicies anymore to make it clear that only counters are
used.

Sarmad Abbasi (Virtual University)

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

Sarmad Abbasi (Virtual University)

Theory of Computation

21 / 21

Space Complexity

At the end of the algorithm we have computed cn . Its value is stored in


D. Note that one of the loop is not shown in this program. The loop
that guesses the path of length at most i. Thus this is a program with
four nested loops! It is quite complicated.

Sarmad Abbasi (Virtual University)

Theory of Computation

22 / 21

Space Complexity

Once we have computed cn we know how many vertices are reachable


from s. Now, we can use the program of the previous lecture to write
our non-deterministic program that we require. This ends our proof.

Sarmad Abbasi (Virtual University)

Theory of Computation

23 / 21

Das könnte Ihnen auch gefallen