04.09.2013 Views

Algorithm Design

Algorithm Design

Algorithm Design

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

548<br />

Chapter 9 PSPACE: A Class of Problems beyond NP<br />

(0,0) (I,0)<br />

Figure 9.3 Three distinct self-avoiding walks of length 4. Note that although walks (a)<br />

and (b) involve the same set of points, they are considered different walks because they<br />

pass through them in a different order.<br />

and so it appears in theories concerning the rates of certain metabolic and<br />

organic synthesis reactions.<br />

Despite its importance, no simple formula is known for the value A(n). Indeed,<br />

no algorithm is known for computing A(n) that runs in time polynomial<br />

0,0)<br />

(I,I)<br />

(I,0)<br />

(a) Show that A(n) > 2n-1 for all natural numbers n >_ 1.<br />

(b) Give an algorithm that takes a number n as input, and outputs A(n) as a<br />

number in binary notation, using space (i.e., memory) that is polynomial<br />

Solved Exercises<br />

(Thus the running time of your algorithm can be exponential, as long as its<br />

space usage is polynomial. Note also that polynomial here means "polynomial<br />

in n," not "polynomial in log n." Indeed, by part (a), we see that it will take<br />

at least n - 1 bits to write the value of A(n), so clearly n - 1 is a lower bound<br />

on the amount of space you need for producing a correct answer.)<br />

Solution We consider part (b) first. One’s first thought is that enumerating all<br />

self-avoiding walks sounds like a complicated prospect; it’s natural to imagine<br />

the search as grov#ing a chain starting from a single bead, exploring possible<br />

conformations, and backtracking when there’s no way to continue growing<br />

and remain self-avoiding. You can picture attention-grabbing screen-savers that<br />

do things like this, but it seems a bit messy to write down exactly what the<br />

algorithm would be.<br />

So we back up; polynomial space is a very generous bound, and we<br />

can afford to take an even more brute-force approach. Suppose that instead<br />

of trying just to enumerate all self-avoiding walks of length n, we simply<br />

enumerate all walks of length n, and then check which ones turn out to be selfavoiding.<br />

The advantage of this is that the space of all walks is much easier<br />

to describe than the space of self-avoiding walks.<br />

Pn) on the set 2~ of grid points in the plane<br />

can be described by the sequence of directions it takes. Each step frompi to<br />

in the walk can be viewed as moving in one of four directions: north, south,<br />

east, or west. Thus any walk of length n can be mapped to a distinct string<br />

of length n - 1 over the alphabet [N, S, E, W}. (The three walks in Figure 9.3<br />

would be ENW, NES, and EEN.) Each such string corresponds to a walk of<br />

length n, but not al! such strings correspond to walks that are self-avoiding:<br />

for example, the walk NESW revisits the point (0, 0).<br />

We can use this encoding of walks for part (b) of the question as follows.<br />

Using a counter in base 4, we enumerate all strings of length n - 1 over the<br />

alphabet {N, S, E, W}, by viewing this alphabet equivalently as {0, 1, 2, 3}. For<br />

each such string, we construct the corresponding walk and test, in polynomial<br />

space, whether it is self-avoiding. Finally, we increment a second counter A<br />

(initialized to 0) if the current walk is self-avoiding. At the end of this algorithm,<br />

A will hold the value of A(n).<br />

Now we can bound the space used by this algorithm is follows. The first<br />

counter, which enumerates strings, has n - 1 positions, each of which requires<br />

two bits (since it can take four possible values). Similarly, the second counter<br />

holding A can be incremented at most 4 n-1 times, and so it too needs at most<br />

2n bits. Finally, we use polynomial space to check whether each generated<br />

walk is self-avoiding, but we can reuse the same space for each walk, and so<br />

the space needed for this is polynomial as well.<br />

549

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!