Chapter 9
PSPACE: A Class of Problems beyond NP
Throughout the book, one of the main issues has been the notion oftimeas a computational resource. It was this notion that formed the basis for adopting polynomial time as our working definition of efficiency; and, implicitly, it underlies the distinction between P andNP. To some extent, we have also been concerned with thespace(i.e., memory) requirements of algorithms. In this chapter, we investigate a class of problems defined by treating space as the fundamental computational resource. In the process, we develop a natural class of problems that appear to be even harder thanNP and co-NP.
9.1 PSPACE
The basic class we study is PSPACE, the set of all problems that can be solved by an algorithm with polynomial space complexity—that is, an algorithm that uses an amount ofspacethat is polynomial in the size of the input.
We begin by considering the relationship of PSPACE to classes of problems we have considered earlier. First of all, in polynomial time, an algorithm can consume only a polynomial amount of space; so we can say
(9.1) P⊆PSPACE.
But PSPACE is much broader than this. Consider, for example, an algorithm that just counts from 0 to 2n−1 in base-2 notation. It simply needs to implement ann-bit counter, which it maintains in exactly the same way one increments an odometer in a car. Thus this algorithm runs for an exponential amount of time, and then halts; in the process, it has used only a polynomial amount of space. Although this algorithm is not doing anything particularly
interesting, it illustrates an important principle: Space can be reused during a computation in ways that time, by definition, cannot.
Here is a more striking application of this principle.
(9.2) There is an algorithm that solves 3-SAT using only a polynomial amount of space.
Proof. We simply use a brute-force algorithm that tries all possible truth assignments; each assignment is plugged into the set of clauses to see if it satisfies them. The key is to implement this all in polynomial space.
To do this, we increment ann-bit counter from 0 to 2n−1 just as described above. The values in the counter correspond to truth assignments in the following way: When the counter holds a value q, we interpret it as a truth assignmentν that setsxito be the value of theithbit ofq.
Thus we devote a polynomial amount of space to enumerating all possible truth assignments ν. For each truth assignment, we need only polynomial space to plug it into the set of clauses and see if it satisfies them. If it does satisfy the clauses, we can stop the algorithm immediately. If it doesn’t, we delete the intermediate work involved in this “plugging in” operation andreuse this space for the next truth assignment. Thus we spend only polynomial space cumulatively in checking all truth assignments; this completes the bound on the algorithm’s space requirements.
Since 3-SAT is an NP-complete problem, (9.2) has a significant conse- quence.
(9.3) NP⊆PSPACE.
Proof. Consider an arbitrary problem Y inNP. Since Y ≤P 3-SAT, there is an algorithm that solves Y using a polynomial number of steps plus a poly- nomial number of calls to a black box for 3-SAT. Using the algorithm in (9.2) to implement this black box, we obtain an algorithm for Y that uses only polynomial space.
Just as with the class P, a problem X is in PSPACE if and only if its complementary problemXis in PSPACE as well. Thus we can conclude that co-NP⊆PSPACE. We draw what is known about the relationships among these classes of problems in Figure 9.1.
Given that PSPACE is an enormously large class of problems, containing both NP and co-NP, it is very likely that it contains problems that cannot be solved in polynomial time. But despite this widespread belief, amazingly
9.2 Some Hard Problems in PSPACE
533
PSPACE
co–
Figure 9.1 The subset relationships among various classes of problems. Note that we don’t know how to prove the conjecture that all of these classes are different from one another.
it has not been proven thatP=PSPACE. Nevertheless, the nearly universal conjecture is that PSPACE contains problems that are not even inNPor co-NP.
9.2 Some Hard Problems in PSPACE
We now survey some natural examples of problems in PSPACE that are not known—and not believed—to belong toNPor co-NP.
As was the case with NP, we can try understanding the structure of PSPACE by looking forcomplete problems—the hardest problems in the class.
We will say that a problemXis PSPACE-complete if (i) it belongs to PSPACE;
and (ii) for all problemsY in PSPACE, we haveY≤PX.
It turns out, analogously to the case ofNP, that a wide range of natural problems are PSPACE-complete. Indeed, a number of the basic problems in artificial intelligence are PSPACE-complete, and we describe three genres of these here.
Planning
Planning problems seek to capture, in a clean way, the task of interacting with a complex environment to achieve a desired set of goals. Canonical applications include large logistical operations that require the movement of people, equipment, and materials. For example, as part of coordinating a disaster-relief effort, we might decide that twenty ambulances are needed at a particular high-altitude location. Before this can be accomplished, we need to get ten snowplows to clear the road; this in turn requires emergency fuel and snowplow crews; but if we use the fuel for the snowplows, then we may not have enough for the ambulances; and . . . you get the idea. Military operations
also require such reasoning on an enormous scale, and automated planning techniques from artificial intelligence have been used to great effect in this domain as well.
One can see very similar issues at work in complex solitaire games such as Rubik’s Cube or thefifteen-puzzle—a 4×4 grid with fifteen movable tiles labeled 1, 2, . . . , 15, and a singlehole, with the goal of moving the tiles around so that the numbers end up in ascending order. (Rather than ambulances and snowplows, we now are worried about things like getting the tile labeled 6 one position to the left, which involves getting the 11 out of the way; but that involves moving the 9, which was actually in a good position; and so on.) These toy problems can be quite tricky and are often used in artificial intelligence as a test-bed for planning algorithms.
Having said all this, how should we define the problem of planning in a way that’s general enough to include each of these examples? Both solitaire puzzles and disaster-relief efforts have a number of abstract features in common: There are a number ofconditionswe are trying to achieve and a set of allowableoperatorsthat we can apply to achieve these conditions. Thus we model the environment by a setC= {C1, . . . ,Cn}ofconditions: A given state of the world is specified by the subset of the conditions that currently hold. We interact with the environment through a set {O1, . . . ,Ok}ofoperators. Each operator Oi is specified by a prerequisite list, containing a set of conditions that must hold forOito be invoked; anadd list, containing a set of conditions that will become true afterOiis invoked; and adelete list, containing a set of conditions that will cease to hold afterOi is invoked. For example, we could model the fifteen-puzzle by having a condition for each possible location of each tile, and an operator to move each tile between each pair of adjacent locations; the prerequisite for an operator is that its two locations contain the designated tile and the hole.
The problem we face is the following: Given a setC0ofinitial conditions, and a setC∗ofgoal conditions, is it possible to apply a sequence of operators beginning withC0so that we reach a situation in which precisely the conditions in C∗ (and no others) hold? We will call this an instance of the Planning Problem.
Quantification
We have seen, in the 3-SAT problem, some of the difficulty in determining whether a set of disjunctive clauses can be simultaneously satisfied. When we add quantifiers, the problem appears to become even more difficult.
Let(x1, . . . ,xn)be a Boolean formula of the form C1∧C2∧. . .∧Ck,
9.2 Some Hard Problems in PSPACE
535
where eachCiis a disjunction of three terms (in other words, it is an instance of 3-SAT). Assume for simplicity thatnis an odd number, and suppose we ask
∃x1∀x2. . .∃xn−2∀xn−1∃xn(x1, . . . ,xn)?
That is, we wish to know whether there is a choice forx1, so that for both choices ofx2, there is a choice forx3, and so on, so thatis satisfied. We will refer to this decision problem asQuantified 3-SAT(or, briefly, QSAT).
The original 3-SAT problem, by way of comparison, simply asked
∃x1∃x2. . .∃xn−2∃xn−1∃xn(x1, . . . ,xn)?
In other words, in 3-SAT it was sufficient to look for a single setting of the Boolean variables.
Here’s an example to illustrate the kind of reasoning that underlies an instance of QSAT. Suppose that we have the formula
(x1,x2,x3)=(x1∨x2∨x3)∧(x1∨x2∨x3)∧(x1∨x2∨x3)∧(x1∨x2∨x3) and we ask
∃x1∀x2∃x3(x1,x2,x3)?
The answer to this question is yes: We can setx1so that for both choices of x2, there is a way to setx3so thatis satisfied. Specifically, we can setx1=1;
then ifx2is set to 1, we can setx3to 0 (satisfying all clauses); and ifx2is set to 0, we can setx3to 1 (again satisfying all clauses).
Problems of this type, with a sequence of quantifiers, arise naturally as a form ofcontingency planning—we wish to know whether there is a decision we can make (the choice ofx1) so that for all possible responses (the choice ofx2) there is a decision we can make (the choice ofx3), and so forth.
Games
In 1996 and 1997, world chess champion Garry Kasparov was billed by the media as the defender of the human race, as he faced IBM’s program Deep Blue in two chess matches. We needn’t look further than this picture to convince ourselves that computational game-playing is one of the most visible successes of contemporary artificial intelligence.
A large number of two-player games fit naturally into the following frame- work. Players alternate moves, and the first one to achieve a specific goal wins.
(For example, depending on the game, the goal could be capturing the king, removing all the opponent’s checkers, placing four pieces in a row, and so on.) Moreover, there is often a natural, polynomial, upper bound on the maximum possible length of a game.
The Competitive Facility Location Problem that we introduced in Chapter 1 fits naturally within this framework. (It also illustrates the way in which games can arise not just as pastimes, but through competitive situations in everyday life.) Recall that in Competitive Facility Location, we are given a graphG, with a nonnegativevalue biattached to each nodei. Two players alternately select nodes ofG, so that the set of selected nodes at all times forms an independent set. Player 2 wins if she ultimately selects a set of nodes of total value at least B, for a given boundB; Player 1 wins if he prevents this from happening. The question is: Given the graphGand the boundB, is there a strategy by which Player 2 can force a win?
9.3 Solving Quantified Problems and Games in Polynomial Space
We now discuss how to solve all of these problems in polynomial space. As we will see, this will be trickier—in one case, a lot trickier—than the (simple) task we faced in showing that problems like 3-SAT and Independent Set belong toNP.
We begin here with QSAT and Competitive Facility Location, and then consider Planning in the next section.
Designing an Algorithm for QSAT
First let’s show that QSAT can be solved in polynomial space. As was the case with 3-SAT, the idea will be to run a brute-force algorithm that reuses space carefully as the computation proceeds.
Here is the basic brute-force approach. To deal with the first quantifier∃x1, we consider both possible values for x1in sequence. We first setx1=0 and see, recursively, whether the remaining portion of the formula evaluates to 1.
We then setx1=1 and see, recursively, whether the remaining portion of the formula evaluates to 1. The full formula evaluates to 1 if and only ifeither of these recursive calls yields a 1—that’s simply the definition of the∃quantifier.
This is essentially a divide-and-conquer algorithm, which, given an input with n variables, spawns two recursive calls on inputs with n−1 variables each. If we were to save all the work done in both these recursive calls, our space usageS(n)would satisfy the recurrence
S(n)≤2S(n−1)+p(n),
where p(n) is a polynomial function. This would result in an exponential bound, which is too large.
9.3 Solving Quantified Problems and Games in Polynomial Space
537
Fortunately, we can perform a simple optimization that greatly reduces the space usage. When we’re done with the casex1=0, all we really need to save is the single bit that represents the outcome of the recursive call; we can throw away all the other intermediate work. This is another example of
“reuse”—we’re reusing the space from the computation forx1=0 in order to compute the casex1=1.
Here is a compact description of the algorithm.
If the first quantifier is ∃ xi then
Set xi=0 and recursively evaluate the quantified expression over the remaining variables
Save the result (0 or 1) and delete all other intermediate work Set xi=1 and recursively evaluate the quantified expression
over the remaining variables If either outcome yielded an evaluation of 1, then
return 1 Else return 0 Endif
If the first quantifier is ∀ xi then
Set xi=0 and recursively evaluate the quantified expression over the remaining variables
Save the result (0 or 1) and delete all other intermediate work Set xi=1 and recursively evaluate the quantified expression
over the remaining variables If both outcomes yielded an evaluation of 1, then
return 1 Else return 0 Endif
Endif
Analyzing the Algorithm
Since the recursive calls for the casesx1=0 andx1=1 overwrite the same space, our space requirement S(n) for an n-variable problem is simply a polynomial innplus the space requirement for one recursive call on an(n−1)- variable problem:
S(n)≤S(n−1)+p(n),
where againp(n)is a polynomial function. Unrolling this recurrence, we get S(n)≤p(n)+p(n−1)+p(n−2)+. . .+p(1)≤n·p(n).
Since p(n) is a polynomial, so is n·p(n), and hence our space usage is polynomial inn, as desired.
In summary, we have shown the following.
(9.4) QSAT can be solved in polynomial space.
Extensions: An Algorithm for Competitive Facility Location
We can determine which player has a forced win in a game such as Competitive Facility Location by a very similar type of algorithm.
Suppose Player 1 moves first. We consider all of his possible moves in sequence. For each of these moves, we see who has a forced win in the resulting game, with Player 2 moving first. If Player 1 has a forced win in any of them, then Player 1 has a forced win from the initial position. The crucial point, as in the QSAT algorithm, is that we can reuse the space from one candidate move to the next; we need only store the single bit representing the outcome.
In this way, we only consume a polynomial amount of space plus the space requirement for one recursive call on a graph with fewer nodes. As in the case of QSAT, we get the recurrence
S(n)≤S(n−1)+p(n) for a polynomialp(n).
In summary, we have shown the following.
(9.5) Competitive Facility Location can be solved in polynomial space.
9.4 Solving the Planning Problem in Polynomial Space
Now we consider how to solve the basic Planning Problem in polynomial space. The issues here will look quite different, and it will turn out to be a much more difficult task.
The Problem
Recall that we have a set ofconditionsC= {C1, . . . ,Cn}and a set ofoperators {O1, . . . ,Ok}. Each operatorOi has a prerequisite list Pi, an add list Ai, and adelete list Di. Note thatOi can still be applied even if conditions other than those inPiare present; and it does not affect conditions that are not inAiorDi. We define aconfigurationto be a subsetC′⊆C; the state of the Planning Problem at any given time can be identified with a unique configuration C′
9.4 Solving the Planning Problem in Polynomial Space
539
consisting precisely of the conditions that hold at that time. For an initial configurationC0and a goal configurationC∗, we wish to determine whether there is a sequence of operators that will take us fromC0toC∗.
We can view our Planning instance in terms of a giant, implicitly defined, directed graphG. There is a node ofGfor each of the 2npossible configurations (i.e., each possible subset ofC); and there is an edge ofGfrom configuration C′to configurationC′′if, in one step, one of the operators can convertC′toC′′. In terms of this graph, the Planning Problem has a very natural formulation:
Is there a path inG fromC0 to C∗? Such a path corresponds precisely to a sequence of operators leading fromC0toC∗.
It’s possible for a Planning instance to have a short solution (as in the example of the fifteen-puzzle), but this need not hold in general. That is, there need not always be a short path inGfromC0toC∗. This should not be so surprising, sinceGhas an exponential number of nodes. But we must be careful in applying this intuition, sinceGhas a special structure: It is defined very compactly in terms of thenconditions andkoperators.
(9.6) There are instances of the Planning Problem with n conditions and k operators for which there exists a solution, but the shortest solution has length 2n−1.
Proof. We give a simple example of such an instance; it essentially encodes the task of incrementing ann-bit counter from the all-zeros state to the all-ones state.
. We have conditionsC1,C2, . . . ,Cn.
. We have operatorsOifori=1, 2, . . . ,n.
. O1has no prerequisites or delete list; it simply addsC1.
. For i>1,Oi requires Cj for allj<i as prerequisites. When invoked, it addsCiand deletesCjfor allj<i.
Now we ask: Is there a sequence of operators that will take us fromC0=φto C∗= {C1,C2, . . . ,Cn}?
We claim the following, by induction oni:
From any configuration that does not contain Cjfor any j≤i, there exists a sequence of operators that reaches a configuration containing Cj for all j≤i; but any such sequence has at least2i−1steps.
This is clearly true fori=1. For largeri, here’s one solution.
. By induction, achieve conditions{Ci−1, . . . ,C1}using operatorsO1, . . . , Oi−1.
. Now invoke operatorOi, addingCibut deleting everything else.
. Again, by induction, achieve conditions {Ci−1, . . . ,C1}using operators O1, . . . ,Oi−1. Note that conditionCiis preserved throughout this process.
Now we take care of the other part of the inductive step—thatanysuch sequence requires at least 2i−1 steps. So consider the first moment whenCi is added. At this step,Ci−1, . . . ,C1must have been present, and by induction, this must have taken at least 2i−1−1 steps. Ci can only be added by Oi, which deletes allCjforj<i. Now we have to achieve conditions{Ci−1, . . . ,C1} again; this will take another 2i−1−1 steps, by induction, for a total of at least 2(2i−1−1)+1=2i−1 steps.
The overall bound now follows by applying this claim withi=n.
Of course, if every “yes” instance of Planning had a polynomial-length solution, then Planning would be inNP—we could just exhibit the solution.
But (9.6) shows that the shortest solution is not necessarily a good certificate for a Planning instance, since it can have a length that is exponential in the input size.
However, (9.6) describes essentially the worst case, for we have the following matching upper bound. The graphGhas 2nnodes, and if there is a path fromC0toC∗, then the shortest such path does not visit any node more than once. As a result, the shortest path can take at most 2n−1 steps after leavingC0.
(9.7) If a Planning instance with n conditions has a solution, then it has one using at most2n−1steps.
Designing the Algorithm
We’ve seen that the shortest solution to the Planning Problem may have length exponential inn, which is bad news: After all, this means that in polynomial space, we can’t even store an explicit representation of the solution. But this fact doesn’t necessarily close out our hopes of solving an arbitrary instance of Planning using only polynomial space. It’s possible that there could be an algorithm that decides the answer to an instance of Planning without ever being able to survey the entire solution at once.
In fact, we now show that this is the case: we design an algorithm to solve Planning in polynomial space.
Some Exponential Approaches To get some intuition about this problem, we first consider the following brute-force algorithm to solve the Planning instance. We build the graph G and use any graph connectivity algorithm—
depth-first search or breadth-first search—to decide whether there is a path fromC0toC∗.
9.4 Solving the Planning Problem in Polynomial Space
541
Of course, this algorithm is too brute-force for our purposes; it takes exponential space just to construct the graphG. We could try an approach in which we never actually buildG, and just simulate the behavior of depth-first search or breadth-first search on it. But this likewise is not feasible. Depth-first search crucially requires us to maintain a list of all the nodes in the current path we are exploring, and this can grow to exponential size. Breadth-first requires a list of all nodes in the current “frontier” of the search, and this too can grow to exponential size.
We seem stuck. Our problem is transparently equivalent to finding a path inG, and all the standard path-finding algorithms we know are too lavish in their use of space. Could there really be a fundamentally different path-finding algorithm out there?
A More Space-Efficient Way to Construct Paths In fact, there is a fundamen- tally different kind of path-finding algorithm, and it has just the properties we need. The basic idea, proposed by Savitch in 1970, is a clever use of the divide- and-conquer principle. It subsequently inspired the trick for reducing the space requirements in the Sequence Alignment Problem; so the overall approach may remind you of what we discussed there, in Section 6.7. Our plan, as before, is to find a clever way to reuse space, admittedly at the expense of increasing the time spent. Neither depth-first search nor breadth-first search is nearly ag- gressive enough in its reuse of space; both need to maintain a large history at all times. We need a way to solve half the problem, throw away almost all the intermediate work, and then solve the other half of the problem.
The key is a procedure that we will call Path(C1,C2,L). It determines whether there is a sequence of operators,consisting of at most L steps, that leads from configuration C1to configuration C2. So our initial problem is to determine the result (yes or no) ofPath(C0,C∗, 2n). Breadth-first search can be viewed as the following dynamic programming implementation of this procedure: To determinePath(C1,C2,L), we first determine allC′for which Path(C1,C′,L−1)holds; we then see, for each suchC′, whether any operator leads directly fromC′toC2.
This indicates some of the wastefulness, in terms of space, that breadth- first search entails. We are generating a huge number of intermediate config- urations just to reduce the parameter L by one. More effective would be to try determining whether there is any configurationC′that could serve as the midpointof a path fromC1toC2. We could first generate all possible midpoints C′. For each C′, we then check recursively whether we can get fromC1toC′ in at mostL/2 steps; and also whether we can get fromC′ toC2in at most L/2 steps. This involves two recursive calls, but we care only about the yes/no outcome of each; other than this, we can reuse space from one to the next.
Does this really reduce the space usage to a polynomial amount? We first write down the procedure carefully, and then analyze it. We will think ofLas a power of 2, which it is for our purposes.
Path(C1,C2,L) If L=1 then
If there is an operator O converting C1 to C2 then return ‘‘yes’’
Else
return ‘‘no’’
Endif Else (L>1)
Enumerate all configurations C′ using an n-bit counter For each C′ do the following:
Compute x = Path(C1,C′,⌈L/2⌉)
Delete all intermediate work, saving only the return value x Compute y = Path(C′,C2,⌈L/2⌉)
Delete all intermediate work, saving only the return value y If both x and y are equal to ‘‘yes’’, then return ‘‘yes’’
Endfor
If ‘‘yes’’ was not returned for any C′ then Return ‘‘no’’
Endif Endif
Again, note that this procedure solves a generalization of our original question, which simply asked forPath(C0,C∗, 2n). This does mean, however, that we should remember to view L as an exponentially large parameter:
logL=n.
Analyzing the Algorithm
The following claim therefore implies that Planning can be solved in polyno- mial space.
(9.8) Path(C1,C2,L) returns “yes” if and only if there is a sequence of operators of length at most L leading fromC1toC2. Its space usage is polynomial in n, k, andlogL.
Proof. The correctness follows by induction onL. It clearly holds whenL=1, since all operators are considered explicitly. Now consider a larger value of L. If there is a sequence of operators from C1to C2, of length L′≤L, then there is a configurationC′ that occurs at position⌈L′/2⌉in this sequence. By
9.5 Proving Problems PSPACE-Complete
543
induction,Path(C1,C′,⌈L/2⌉)andPath(C′,C2,⌈L/2⌉)will both return “yes,”
and soPath(C1,C2,L)will return “yes.” Conversely, if there is a configuration C′so thatPath(C1,C′,⌈L/2⌉)andPath(C′,C2,⌈L/2⌉)both return “yes,” then the induction hypothesis implies that there exist corresponding sequences of operators; concatenating these two sequences, we obtain a sequence of operators fromC1toC2of length at mostL.
Now we consider the space requirements. Aside from the space spent inside recursive calls, each invocation ofPathinvolves an amount of space polynomial inn, k, and logL. But at any given point in time, only a single recursive call is active, and the intermediate work from all other recursive calls has been deleted. Thus, for a polynomial functionp, the space requirement S(n,k,L)satisfies the recurrence
S(n,k,L)≤p(n,k, logL)+S(n,k,⌈L/2⌉).
S(n,k, 1)≤p(n,k, 1).
Unwinding the recurrence forO(logL)levels, we obtain the boundS(n,k,L)= O(logL·p(n,k, logL)), which is a polynomial inn,k, and logL.
If dynamic programming has an opposite, this is it. Back when we were solving problems by dynamic programming, the fundamental principle was to save all the intermediate work, so you don’t have to recompute it. Now that conserving space is our goal, we have just the opposite priorities: throw away all the intermediate work, since it’s just taking up space and it can always be recomputed.
As we saw when we designed the space-efficient Sequence Alignment Algorithm, the best strategy often lies somewhere in between, motivated by these two approaches: throw away some of the intermediate work, but not so much that you blow up the running time.
9.5 Proving Problems PSPACE-Complete
When we studiedNP, we had to prove afirst problem NP-complete directly from the definition ofNP. After Cook and Levin did this for Satisfiability, many other NP-complete problems could follow by reduction.
A similar sequence of events followed for PSPACE, shortly after the results forNP. Recall that we defined PSPACE-completeness, by direct analogy with NP-completeness, in Section 9.1. The natural analogue of Circuit Satisfiability and 3-SAT for PSPACE is played by QSAT, and Stockmeyer and Meyer (1973) proved
(9.9) QSAT is PSPACE-complete.
This basic PSPACE-complete problem can then serve as a good “root” from which to discover other PSPACE-complete problems. By strict analogy with the case ofNP, it’s easy to see from the definition that if a problemY is PSPACE- complete, and a problemXin PSPACE has the property thatY≤PX, thenXis PSPACE-complete as well.
Our goal in this section is to show an example of such a PSPACE- completeness proof, for the case of the Competitive Facility Location Problem;
we will do this by reducing QSAT to Competitive Facility Location. In addition to establishing the hardness of Competitive Facility Location, the reduction also gives a sense for how one goes about showing PSPACE-completeness results for games in general, based on their close relationship to quantifiers.
We note that Planning can also be shown to be PSPACE-complete by a reduction from QSAT, but we will not go through that proof here.
Relating Quantifiers and Games
It is actually not surprising at all that there should be a close relation between quantifiers and games. Indeed, we could have equivalently defined QSAT as the problem of deciding whether the first player has a forced win in the following Competitive 3-SAT game. Suppose we fix a formula(x1, . . . ,xn)consisting, as in QSAT, of a conjunction of length-3 clauses. Two players alternate turns picking values for variables: the first player picks the value of x1, then the second player picks the value of x2, then the first player picks the value of x3, and so on. We will say that the first player wins if(x1, . . . ,xn)ends up evaluating to 1, and the second player wins if it ends up evaluating to 0.
When does the first player have a forced win in this game (i.e., when does our instance of Competitive 3-SAT have a yes answer)? Precisely when there is a choice forx1so that for all choices ofx2there is a choice forx3so that . . . and so on, resulting in(x1, . . . ,xn)evaluating to 1. That is, the first player has a forced win if and only if (assumingnis an odd number)
∃x1∀x2. . .∃xn−2∀xn−1∃xn(x1, . . . ,xn).
In other words, our Competitive 3-SAT game is directly equivalent to the instance of QSAT defined by the same Boolean formula , and so we have proved the following.
(9.10) QSAT≤PCompetitive 3-SAT and Competitive 3-SAT≤PQSAT.
Proving Competitive Facility Location is PSPACE-Complete
Statement (9.10) moves us into the world of games. We use this connection to establish the PSPACE-completeness of Competitive Facility Location.
9.5 Proving Problems PSPACE-Complete
545
(9.11) Competitive Facility Location is PSPACE-complete.
Proof. We have already shown that Competitive Facility Location is in PSPACE.
To prove it is PSPACE-complete, we now show that Competitive 3-SAT≤PCom- petitive Facility Location. Combined with the fact that QSAT≤P Competitive 3-SAT, this will show that QSAT≤P Competitive Facility Location and hence will establish the PSPACE-completeness result.
We are given an instance of Competitive 3-SAT, defined by a formula . is the conjunction of clauses
C1∧C2∧. . .∧Ck;
eachCj has length 3 and can be writtenCj=tj1∨tj2∨tj3. As before, we will assume that there is an odd number n of variables. We will also assume, quite naturally, that no clause contains both a term and its negation; after all, such a clause would be automatically satisfied by any truth assignment. We must show how to encode this Boolean structure in the graph that underlies Competitive Facility Location.
We can picture the instance of Competitive 3-SAT as follows. The players alternately select values in a truth assignment, beginning and ending with Player 1; at the end, Player 2 has won if she can select a clauseCj in which none of the terms has been set to 1. Player 1 has won if Player 2 cannot do this.
It is this notion that we would like to encode in an instance of Competitive Facility Location: that the players alternately make a fixed number of moves, in a highly constrained fashion, and then there’s a final chance by Player 2 to win the whole thing. But in its general form, Competitive Facility Location looks much more wide-open than this. Whereas the players in Competitive 3- SAT must set one variable at a time, in order, the players in Competitive Facility Location can jump all over the graph, choosing nodes wherever they want.
Our fundamental trick, then, will be to use the valuesbion the nodes to tightly constrain where the players can move, under any “reasonable” strategy.
In other words, we will set things up so that if the either of the players deviates from a particular narrow course, he or she will lose instantly.
As with our more complicated NP-completeness reductions in Chapter 8, the construction will have gadgets to represent assignments to the variables, and further gadgets to represent the clauses. Here is how we encode the variables. For each variable xi, we define two nodes vi,v′i in the graph G, and include an edge(vi,v′i), as in Figure 9.2. Selectingviwill represent setting xi=1; selectingv′iwill representxi=0. The constraint that the chosen variables
Goal: 101 Variable 1
Clause 1
1000 1000
Variable 2 100 100
Variable 3 10 10
1
Figure 9.2 The reduction from Competitive 3-SAT to Competitive Facility Location.
must form an independent set naturally prevents both vi and vi′ from being chosen. At this point, we do not define any other edges.
How do we get the players to set the variables in order—firstx1, thenx2, and so forth? We place values on v1 and v1′ so high that Player 1 will lose instantly if he does not choose them. We place somewhat lower values onv2 andv′2, and continue in this way. Specifically, for a valuec≥k+2, we define the node valuesbviandbv′
ito bec1+n−i. We define the bound that Player 2 is trying to achieve to be
B=cn−1+cn−3+. . .+c2+1.
Let’s pause, before worrying about the clauses, to consider the game played on this graph. In the opening move of the game, Player 1 must select one of v1 orv′1(thereby obliterating the other one); for if not, then Player 2 will immediately select one of them on her next move, winning instantly.
Similarly, in the second move of the game, Player 2 must select one ofv2or v2′. For otherwise, Player 1 will select one on his next move; and then, even if Player 2 acquired all the remaining nodes in the graph, she would not be able to meet the boundB. Continuing by induction in this way, we see that to avoid an immediate loss, the player making theithmove must select one ofviorvi′. Note that our choice of node values has achieved precisely what we wanted:
The players must set the variables in order. And what is the outcome on this graph? Player 2 ends up with a total of value ofcn−1+cn−3+. . .+c2=B−1:
she has lost by one unit!
We now complete the analogy with Competitive 3-SAT by giving Player 2 one final move on which she can try to win. For each clauseCj, we define a nodecj with valuebc
j=1 and an edge associated with each of its terms as
Solved Exercises
547
follows. Ift=xi, we add an edge(cj,vi); if t=xi, we add an edge(cj,v′i). In other words, we joincjto the node that represents the termt.
This now defines the full graphG. We can verify that, because their values are so small, the addition of the clause nodes did not change the property that the players will begin by selecting the variable nodes {vi,v′i}in the correct order. However, after this is done, Player 2 will win if and only if she can select a clause nodecjthat is not adjacent to any selected variable node—in other words, if and only the truth assignment defined alternately by the players failed to satisfy some clause.
Thus Player 2 can win the Competitive Facility Location instance we have defined if and only if she can win the original Competitive 3-SAT instance. The reduction is complete.
Solved Exercises
Solved Exercise 1
Self-avoiding walksare a basic object of study in the area of statistical physics;
they can be defined as follows. LetLdenote the set of all points inR2with integer coordinates. (We can think of these as the “grid points” of the plane.) A self-avoiding walk W of length n is a sequence of points(p1,p2, . . . ,pn) drawn fromLso that
(i) p1=(0, 0).(The walk starts at the origin.)
(ii) No two of the points are equal.(The walk “avoids” itself.)
(iii) For eachi=1, 2, . . . ,n−1, the pointspiandpi+1are at distance 1 from each other.(The walk moves between neighboring points inL.)
Self-avoiding walks (in both two and three dimensions) are used in physical chemistry as a simple geometric model for the possible conformations of long- chain polymer molecules. Such molecules can be viewed as a flexible chain of beads that flops around, adopting different geometric layouts; self-avoiding walks are a simple combinatorial abstraction for these layouts.
A famous unsolved problem in this area is the following. For a natural number n≥1, let A(n) denote the number of distinct self-avoiding walks of length n. Note that we view walks as sequences of points rather than sets; so two walks can be distinct even if they pass through the same set of points, provided that they do so in different orders. (Formally, the walks (p1,p2, . . . ,pn)and(q1,q2, . . . ,qn)are distinct if there is somei (1≤i≤n) for whichpi=qi.) See Figure 9.3 for an example. In polymer models based on self-avoiding walks,A(n)is directly related to theentropyof a chain molecule,
(a)
(0,1) (1,1)
(0,0) (1,0)
(b)
(0,1) (1,1)
(0,0) (1,0)
(c)
(2,1)
(1,0) (2,0)
(0,0)
Figure 9.3 Three distinct self-avoiding walks of length 4. Note that although walks (a) and (b) involve the same set of points, they are considered different walks because they pass through them in a different order.
and so it appears in theories concerning the rates of certain metabolic and organic synthesis reactions.
Despite its importance, no simple formula is known for the valueA(n). In- deed, no algorithm is known for computingA(n)that runs in time polynomial inn.
(a) Show thatA(n)≥2n−1for all natural numbersn≥1.
(b) Give an algorithm that takes a numbernas input, and outputsA(n)as a number in binary notation, using space (i.e., memory) that is polynomial inn.
Solved Exercises
549
(Thus the running time of your algorithm can be exponential, as long as its space usage is polynomial. Note also thatpolynomialhere means “polynomial inn,” not “polynomial in logn.” Indeed, by part (a), we see that it will take at leastn−1 bits to write the value ofA(n), so clearlyn−1 is a lower bound on the amount of space you need for producing a correct answer.)
Solution We consider part (b) first. One’s first thought is that enumerating all self-avoiding walks sounds like a complicated prospect; it’s natural to imagine the search as growing a chain starting from a single bead, exploring possible conformations, and backtracking when there’s no way to continue growing and remain self-avoiding. You can picture attention-grabbing screen-savers that do things like this, but it seems a bit messy to write down exactly what the algorithm would be.
So we back up; polynomial space is a very generous bound, and we can afford to take an even more brute-force approach. Suppose that instead of trying just to enumerate all self-avoiding walks of length n, we simply enumerateallwalks of lengthn, and then check which ones turn out to be self- avoiding. The advantage of this is that the space of all walks is much easier to describe than the space of self-avoiding walks.
Indeed, any walk(p1,p2, . . . ,pn)on the setLof grid points in the plane can be described by the sequence of directions it takes. Each step frompitopi+1 in the walk can be viewed as moving in one of four directions: north, south, east, or west. Thus any walk of lengthncan be mapped to a distinct string of lengthn−1 over the alphabet{N,S,E,W}. (The three walks in Figure 9.3 would be ENW, NES, and EEN.) Each such string corresponds to a walk of lengthn, but not all such strings correspond to walks that are self-avoiding:
for example, the walk NESW revisits the point(0, 0).
We can use this encoding of walks for part (b) of the question as follows.
Using a counter in base 4, we enumerate all strings of lengthn−1 over the alphabet{N,S,E,W}, by viewing this alphabet equivalently as{0, 1, 2, 3}. For each such string, we construct the corresponding walk and test, in polynomial space, whether it is self-avoiding. Finally, we increment a second counterA (initialized to 0) if the current walk is self-avoiding. At the end of this algorithm, Awill hold the value ofA(n).
Now we can bound the space used by this algorithm as follows. The first counter, which enumerates strings, hasn−1 positions, each of which requires two bits (since it can take four possible values). Similarly, the second counter holdingAcan be incremented at most 4n−1times, and so it too needs at most 2n bits. Finally, we use polynomial space to check whether each generated walk is self-avoiding, but we can reuse the same space for each walk, and so the space needed for this is polynomial as well.
The encoding scheme also provides a way to answer part (a). We observe that all walks that can be encoded using only the letters{N,E}are self-avoiding, since they only move up and to the right in the plane. As there are 2n−1strings of lengthn−1 over these two letters, there are at least 2n−1self-avoiding walks;
in other words,A(n)≥2n−1.
(Note that we argued earlier that our encoding technique also provides an upper bound, showing immediately thatA(n)≤4n−1.)
Exercises
1. Let’s consider a special case of Quantified 3-SAT in which the underlying Boolean formula has no negated variables. Specifically, let(x1, . . . ,xn) be a Boolean formula of the form
C1∧C2∧. . .∧Ck,
where eachCi is a disjunction of three terms. We sayismonotone if each term in each clause consists of a nonnegated variable—that is, each term is equal toxi, for somei, rather thanxi.
We define Monotone QSAT to be the decision problem
∃x1∀x2. . .∃xn−2∀xn−1∃xn(x1, . . . ,xn)?
where the formulais monotone.
Do one of the following two things: (a) prove that Monotone QSAT is PSPACE-complete; or (b) give an algorithm to solve arbitrary instances of Monotone QSAT that runs in time polynomial inn. (Note that in (b), the goal is polynomialtime, not just polynomial space.)
2. Consider the following word game, which we’ll callGeography. You have a set of names of places, like the capital cities of all the countries in the world. The first player begins the game by naming the capital cityc of the country the players are in; the second player must then choose a city c′that starts with the letter on whichc ends; and the game continues in this way, with each player alternately choosing a city that starts with the letter on which the previous one ended. The player who loses is the first one who cannot choose a city that hasn’t been named earlier in the game.
For example, a game played in Hungary would start with “Budapest,”
and then it could continue (for example), “Tokyo, Ottawa, Ankara, Ams- terdam, Moscow, Washington, Nairobi.”
This game is a good test of geographical knowledge, of course, but even with a list of the world’s capitals sitting in front of you, it’s also a major strategic challenge. Which word should you pick next, to try forcing
Notes and Further Reading
551
your opponent into a situation where they’ll be the one who’s ultimately stuck without a move?
To highlight the strategic aspect, we define the following abstract version of the game, which we callGeography on a Graph. Here, we have a directed graph G=(V,E), and a designated start node s∈V. Players alternate turns starting froms; each player must, if possible, follow an edge out of the current node to a node that hasn’t been visited before. The player who loses is the first one who cannot move to a node that hasn’t been visited earlier in the game. (There is a direct analogy toGeography, with nodes corresponding to words.) In other words, a player loses if the game is currently at nodev, and for edges of the form(v,w), the nodew has already been visited.
Prove that it is PSPACE-complete to decide whether the first player can force a win inGeography on a Graph.
3. Give a polynomial-time algorithm to decide whether a player has a forced win inGeography on a Graph, in the special case when the underlying graphGhas no directed cycles (in other words, whenGis a DAG).
Notes and Further Reading
PSPACE is just one example of a class of intractable problems beyond NP;
charting the landscape of computational hardness is the goal of the field of complexity theory. There are a number of books that focus on complexity theory; see, for example, Papadimitriou (1995) and Savage (1998).
The PSPACE-completeness of QSAT is due to Stockmeyer and Meyer (1973).
Some basic PSPACE-completeness results for two-player games can be found in Schaefer (1978) and in Stockmeyer and Chandra (1979). The Com- petitive Facility Location Problem that we consider here is a stylized example of a class of problems studied within the broader area offacility location; see, for example, the book edited by Drezner (1995) for surveys of this topic.
Two-player games have provided a steady source of difficult questions for researchers in both mathematics and artificial intelligence. Berlekamp, Conway, and Guy (1982) and Nowakowski (1998) discuss some of the math- ematical questions in this area. The design of a world-champion-level chess program was for fifty years the foremost applied challenge problem in the field of computer game-playing. Alan Turing is known to have worked on devising algorithms to play chess, as did many leading figures in artificial intelligence over the years. Newborn (1996) gives a readable account of the history of work
on this problem, covering the state of the art up to a year before IBM’s Deep Blue finally achieved the goal of defeating the human world champion in a match.
Planning is a fundamental problem in artificial intelligence; it features prominently in the text by Russell and Norvig (2002) and is the subject of a book by Ghallab, Nau, and Traverso (2004). The argument that Planning can be solved in polynomial space is due to Savitch (1970), who was concerned with issues in complexity theory rather than the Planning Problem per se.
Notes on the Exercises Exercise 1 is based on a problem we learned from Maverick Woo and Ryan Williams; Exercise 2 is based on a result of Thomas Schaefer.