A Linear Time Algorithm for the Feasibility of Pebble ... - CiteSeerX

6 downloads 0 Views 187KB Size Report
memory management in distributed systems, robot motion planning, and ... the feasibility problem of the Pebble Permutation problem on a Tree (the PPT.
A Linear Time Algorithm for the Feasibility of ? Pebble Motion on Trees Vincenzo Auletta1, Angelo Monti2, Mimmo Parente1 , Pino Persiano1 1 2

Dipartimento di Informatica ed Appl. \R.M. Capocelli", Universita di Salerno, 84081 Baronissi, Italy. Dipartimento di Informatica e Sistemistica, Universita \La Sapienza" di Roma

Abstract. We consider the following generalization of the popular \15

puzzle." Let T be a tree with n vertices and with k < n distinct pebbles numbered 1;   ; k on distinct vertices. A move consists in transferring a pebble from its current position to an adjacent unoccupied vertex. We ask the following question: Is a given arrangement of pebbles reachable from another? We present an algorithm that on input two arrangements of k pebbles on a tree with n vertices decides in time O(n) whether the two arrangements are reachable from one another. We also give an algorithm that, on input two reachable con gurations, return a sequence of moves that transforms one con guration into the other. The pebble motion problem on trees has various applications including memory management in distributed systems, robot motion planning, and de ection routing.

1 Introduction We consider the following generalization of the popular \15 puzzle" which we call the Pebble Motion problem on a Tree (PMT problem, in short). Let T be a tree with n vertices and with k < n distinct pebbles numbered 1;    ; k on distinct vertices. A move consists in transferring a pebble from its current position to an adjacent unoccupied vertex. We ask the following question: Is a given arrangement of pebbles reachable from another by executing a sequence of moves? The main contribution of this paper is a linear-time algorithm for deciding whether two arrangements of pebbles on a tree are reachable from one another. The PMT problem has applications to several elds. We can think of the pebbles as indivisible packets of data that need to be moved from one site to another of a communication network without exceeding the capacities of the communication bu ers of each site. Another application of the PMT problem is in the eld of motion planning of independent robots. Here, each pebble represents a robot that has to be moved from one vertex to another of a system of tracks. ?

Partially supported by Progetto MURST 40%, Algoritmi, Modelli di Calcolo e Strutture Informative. Part of this work was done while the last author was at International Computer Science Institute, Berkeley, CA, USA.

Due to its wide applicability, the problem of pebble motion has been studied in various contexts. Kornhauser, Miller, and Spirakis [2] proved that the decision problem for general graphs is decidable in polynomial time improving on an early work of Wilson [6] that considered only biconnected graphs and the case k = n ? 1. Recently, Papadimitriou, Raghavan, Sudan and Tamaki [3] have considered a related problem where there is a distinguished pebble (called robot) that has to be moved from its position to a destination and k ? 1 pebbles (called obstacles) that may end-up in any vertex of the graph. In [3] a simple feasibility criteria was given for trees. In [1] a O(n4 ) algorithm is given to nd an optimal solution to the 1 Pebble Problem of [3]. Several optimality problems (i.e., where we ask the shortest sequence of moves to reach one arrangement from another) relative to pebble motion problem are believed to be computationally intractable. Goldreich proved that computing the shortest sequence of moves that solves an instance of a generalization of Loyd's famous 15-puzzle (this corresponds to the case in which k = n ? 1) is NP-complete. This was later improved to the case in which the graph is a grid by Ratner and Warmuth [4]. The next theorem presents the main result of this paper. Theorem [Informal statement] It is possibile to decide in time O(n) if a given arrangement of pebbles on a tree with n vertices can be transformed into another arrangement.

Our algorithm improves on the previous algorithm of [2]. We next give an informal description of the linear-time algorithm for deciding feasibility of the PMT problem. We divide the presentation of the algorithm into three main conceptual steps. In Section 2 we show that the feasibility of the PMT problem is equivalent to the feasibility problem of the Pebble Permutation problem on a Tree (the PPT problem). In the PPT problem, each pebble has to be moved to the original position of another pebble. In other words, the pebbles have to be permuted among themselves and thus an instance J of the PPT problem is simply a permutation. We give a linear time algorithm that on input an instance I of the PMT problem outputs an instance J of the PPT problem which is feasible if and only if I is feasible. In Section 3, we reduce the feasibility problem for the PPT problem to the problem of feasibility of exchanges between pairs of pebbles. Indeed we have that a permutation  (representing an instance of the PPT problem) is feasible if and only if the exchanges (i; (i)) are feasible for i = 1;    ; k. An exchange (i; j) consists in exchanging the positions of the i-th and j-th pebble and moving back to their original position all other pebbles which have been moved for realizing the exchange. A linear-time algorithm for this task is then given in Section 4. In Section 5 we discuss some extensions of our main result. Basic de nitions and notation. The Pebble Motion problem on a Tree (in short the PMT problem) consists in deciding whether there exists a sequence of moves on a given tree T that takes each of k pebbles numbered 1; 2;    ; k from its source vertex to its destination vertex. No two pebbles start from the same source vertex. A move consists in taking a pebble from its current position to one of the adjacent vertices that is not occupied by another pebble. Thus, at

any given time, each vertex of T hosts at most one pebble. A vertex hosting a pebble is said to be occupied while a vertex not hosting any pebble is said to be a hole. We de ne a con guration on T as a sequence U = hu1 ; u2; : : :uk i of vertices where ui is the vertex hosting the i-th pebble. An instance of the PMT is described by a tree T and two con gurations: the starting (or source) con guration S = hs1 ;    ; sk i and the nal (or destination) con guration D = hd1;    ; dk i. A plan P is a sequence of moves. A plan P of l moves applied to a con guration U results in a series of con gurations U 0;    ; U l , where U 0 = U and con gurations U i and U i+1 di er exactly for the position of the pebble that has been moved by the i-th move of P. We say that a plan P solves, or realizes, an instance I = (T; S ; D) if applying P to S we obtain a sequence of con gurations leading to D. An instance is feasible if there exists a plan that realizes it. The feasibility problem of PMT consists in deciding if for a given instance I there exists a plan solving I . From now on we let T denote a given tree with n vertices and k be the number of pebbles. Without loss of generality, we assume that T is a rooted tree. For each vertex u we denote by Tu the subtree of T rooted in vertex u and by F(u) the forest obtained from T by deleting vertex u. Moreover, for any forest F and any vertex v belonging to F we denote by T(F; v) the subtree of F containing v. We let path (u; v) be the unique path in T between vertices u and v. In the rest of the paper, we use uppercase letters for con gurations of pebbles and, given a con guration U , we denote the i{th element of U by ui , that is the position of pebble i in U . Due to lack of space we omit some of the proofs.

2 The Pebble Permutation Problem In this section we present a linear time reduction algorithm Reduce from the PMT problem to the simpler Pebble Permutation Problem on a Tree. The Pebble Permutation Problem on a Tree (PPT problem, in short) is a special case of the PMT problem where the set of source vertices and the set of destination vertices coincide. Thus the problem consists in permuting the pebbles and an instance of the PPT problem is described by a tree T, a starting con guration S = hs1 ;    ; sk i and a permutation  on k objects. The destination of the i-th pebble that starts at si is the vertex di = s (i) . In the following when T and S are clear from the context, we will speak of a plan of moves which realizes or solves the permutation , meaning that it solves the instance (T; S ; ). Given an instance I = (T; S ; D) of the PMT problem, the algorithm Reduce returns an instance J = (T; S ; ) of the Pebble Permutation Problem on a Tree such that J is feasible if and only if I is feasible. The computation of algorithm Reduce can be divided into two main phases: Phase I. Construct a feasible instance I 0 = (T; S ; hdi1 ;    ; di i) of the PMT problem. k

Phase II. Let  be the permutation de ned as (j) = l if and only if di = dj . Return the instance J = (T; hdi1 ;    ; di i; ) of the PPT problem. l

k

We next prove that, provided that I 0 is feasible, instance J computed by Reduce is feasible if and only if I is feasible. In the next subsection we show how I 0 is constructed and prove that the algorithm takes time O(n) and that the instance I 0 is feasible. Lemma 1. Let I ; I 0, and J be as above. Then, I is feasible if and only if J is feasible.

Proof. Let P be a plan for I 0. If the instance J of the PPT problem is feasible then a plan for the instance I of the PMT problem is obtained by concatenating P and the plan for J. On the other side, if I is feasible, then a plan for J is

given by inverting the moves of P and executing them in the reverse order and then executing the plan for I .

2.1 Phase I of Algorithm Reduce

The algorithm computes a matching ((s1 ; di1 );    ; (sk ; di )) of source and destination vertices of I that naturally de nes the instance I 0. The matching is computed in a bottom-up way starting from the leaves of T. To this aim, the algorithm constructs two lists for each vertex v of the tree: a list of source vertices Sv and a list of destination vertices Dv . Roughly speaking, the list Sv contains two kinds of elements: source vertices that belong to Tv and to which no destination has been assigned yet; and pairs (u1; u2) constituting a match of one source and one destination vertex. Instead, Dv is the list of all the destination vertices of the subtree Tv to which no source has been assigned yet. During the proof of correctness of the algorithm, we will use terms as front and tail of the list and expression as \vertex v is ahead of vertex u" or \vertex v is behind vertex u" with the obvious meaning. The algorithm uses a global counter ` to assign a label to each pair of the matching; the counter is not actually needed to compute the matching between source and destination vertices, but it is used to show that the resulting instance I 0 is feasible. The lists relative to a leaf v are computed as follows. If v is both a source and a destination vertex, then the algorithm produces the triple (v; v; `), increments the counter `, and sets Sv and Dv equal to the empty list. If v is neither a source nor a destination then, again, both Sv and Dv are set equal to the empty list and no triplet is produced. Finally, if v is a source (resp., a destination) the list Sv (resp., Dv ) contains v, the list Dv (resp., Sv ) is empty, and no triplet is produced. Notice that, for the leaf v, at most one of the two lists is nonempty and, as we shall see, this invariant is maintained throughout the execution of the algorithm. Now, consider an internal vertex v, let v1 ;    ; vm be its children, and let Sv and Dv be the lists relative to vertex vi, for i = 1;    ; m. Call S the list obtained by concatenating the lists Sv and D the list obtained by concatenating the lists Dv . If v is a source vertex then v is inserted in front of the list S. If k

i

i

i

i

v is a destination vertex then we have to distinguish two cases: if S contains at least one single vertex, then the closest such vertex to the tail of S, call it u, is replaced with the pair (u; v); if the list S contains no single elements, then v is appended to the list D. Once S and D have been constructed, the algorithm executes the following main loop until S is empty or D is empty and the front element of S is a single vertex: Consider the front of the list S. 1. If the front of S consists of a single vertex u1 , then the algorithm extracts u1 and the vertex u2 at the front of D, produces the triplet (u1 ; u2; `), and increments `. 2. If the front of S is a pair (u1 ; u2) then the algorithm produces the triplet (u1 ; u2; `) and increments `; At the end of the loop Sv is set equal to S and Dv is set equal to D. We state the following easy to prove properties of the algorithm.

Lemma 2. The following properties hold:

1. For each vertex v at most one of the lists Sv and Dv is non empty. 2. For each vertex v and each source vertex u of S , it holds that all the source vertices along path (u; v) that belong to S are ahead of u. 3. For each vertex v and each destination vertex u of D, it holds that all the destination vertices along path (u; v) that belong to D are behind u.

In other words, property 2 above says that when a source vertex u gets to the front of S, then no other source vertex lying on path (u; v) is still in S. Property 3 instead states that when a destination vertex u gets to the front of D, then no other destination vertex descendant of u is still in D. To show that I 0 is feasible, we consider the plan Plan obtained by taking the triplets computed from the reduction algorithm in the order speci ed by the counter eld and executing for each triplet (u1 ; u2; `) the moves for moving a pebble from the source vertex u1 to the destination vertex u2 . We claim that Plan realizes I 0 . The proof of this claim is based on the following two lemmas. Lemma 3. Let v be a vertex of T and suppose that the pair (u1; u2) is at the front of S . Then each source vertex s of Tu2 that is in S is part of a pair (s; d) and u2 does not belong to path (s; d). The correctness of the plan follows from the following property of the triplets computed by Reduce. Lemma 4. For each triplet (u1; u2; `) computed by Reduce it holds that all source vertices on path (u1 ; u2) belong to a triplet with a counter eld less than ` and all destination vertices on path (u1 ; u2) belong to a triplet with a counter eld greater than `. We conclude with the following theorem.

Theorem 5. Algorithm Reduce, on input an instance I of the PMT problem, computes in time O(n) an instance J of the PPT problem that is feasible if and ony if I is feasible. Proof. By Lemma 1, to prove that the reduction algorithm works correctly it is sucient to show that Plan realizes the instance I 0 computed in phase I of the algorithm. By Lemma 4 when Plan moves a pebble from u1 to u2 the path P

is empty. In fact, all source vertices on P have no pebbles as they have already been moved; and no pebble has already been moved to a destination vertex on P. Therefore Plan is a feasible plan. An analysis of the running time of the algorithm is derived from the observations that each of the k source and destination vertices is inserted into and removed from the lists exactly once and, aside from insertion and extraction operations, the algorithm spends constant time for each vertex.

3 Reducing Permutations to Exchanges The algorithm for testing feasibility of an instance of the PPT problem is based on the concept of a good decomposition of a permutation. Given two con gurations U and V we de ne di (U ; V ) as the number of pebbles that are at di erent vertices in U and V . It is well known that any permutation  can be decomposed as a product of exchanges of two elements. Let (1; 2;    ; l ) be a decomposition of  in exchanges and let U j be the con guration obtained by applying the permutation j = 1  2      j to the initial con guration S , for j = 1; 2:    ; l. We say that (1 ; 2;    ; l ) is a good decomposition of  if and only if for each j it holds that di (U j ; (S )) < di (U j ?1; (S )). In other words, each exchange of a good decomposition of  brings at least one pebble to its nal destination. We say that the good decomposition (1; 2;    ; l ) of  is feasible if and only if for each j the permutation j can be applied to S . We rst prove that  is feasible if and only if all the good decompositions of  are feasible. Then, we show that the good decompositions of  are feasible if and only if in the con guration S it is possible to exchange pebbles in vertices si and s (i) , for 1  i  k, while leaving all the other pebbles in their original position. We would like to stress here that when we say that the other pebbles are left in their original positions this does not mean that they are not moved at all, but rather that at the end of the sequence of moves they are back in their original positions. Let us start by giving some de nitions. We say that two con gurations U and V are reachable from each other if there exists a permutation  such that V = (U ) and the instance T; U ; ) is feasible. In particular, when  consists only in the exchange of pebbles i and j we say that vertices ui and uj are equivalent with respect to U , meaning that there is a plan that starting from the con guration U exchanges pebbles i and j leaving all the other pebbles in their originl positions. In the sequel, we simply say that two vertices are equivalent

everytime the relative con guration is clear from the context. Given a move m which takes a pebble from vertex v1 to vertex v2 , de ne rev(m) as the move which takes a pebble from v2 to v1 . Given a sequence of moves H = (m1 ; m2 ; : : :; mh ), de ne rev(H) as the sequence (rev(mh ); : : :; rev(m2 ); rev(m1 )). We start by proving that for each feasible instance I = (T; S ; ) of the PPT problem there exist two vertices si and s (i) in S that are equivalent. To this aim we consider a simpler version of the PPT problem, that we call the 1 Pebble problem, that consists in a con guration of k pebbles on a tree and requires to move one speci ed pebble from its initial position s to a given vertex t. No restriction is imposed to the positions where all the other pebbles are moved. An instance of the 1 Pebble problem is described by the quadruple (T; U ; s; t). Let P be a sequence of moves that solves the instance (T; U ; s; t) of the 1 Pebble problem. We denote by R the set of vertices where the distinguished pebble is moved by the moves of P and denote by R the set of the remaining vertices of the tree. We say that P is a simple plan if and only if the following conditions hold:  P does not contain any move from vertices of R to vertices of R;  all moves from vertices of R to vertices of R \ T(F(s); t) are executed before the distinguished pebble starts moving;  the set R \ T(F(s); t) consists of vertices that either lie on the path path (s; t) or are adjacent to this path. Next Lemma states that for each instance of the 1-Pebble problem it can be given a simple plan that solves it. Lemma 6. For each instance H = (T; U ; s; t) of the 1 Pebble problem there is a simple plan that solves H . Lemma 7. Let U = hu1; u2; : : :; uk i be a con guration of k pebbles in T and suppose that the paths path (ui ; uj ) and path (uj ; uh ) are not edge-disjoint. If there exists a sequence of moves P that moves pebble i to uj and pebble j to uh then vertices ui and uj are equivalent with respect to U . Proof. Consider the rst occurence in P of a con guration V = hv1 ; : : :; vk i such that the path from the position vi of the i{th pebble to its destination uj and the path from the position vj of the j{th pebble to its destination uh are edge disjoint. Denote by Q the sequence of moves which reaches con guration V from U. Consider now the following plan P 0 to exchange the i{th and the j{th pebble: rst execute Q to reach con guration V , then execute a sequence of moves to reach a con guration reachable from V where the pebbles i and j are exchanged (and all the other pebbles are in the same position as in V ), and nally execute rev(Q). It can be easily seen that in the con guration obtained by applying this plan pebbles i and j are exchanged while all the other pebbles are in their original positions. It remains to prove that in V it is possible to exchange pebbles i and j. In the con guration of P just preceding V , at least one pebble, say the j{th, is between vi and uj . Call y the vertex common to path (vi ; vj ) and path (uj ; vj ) and distinct from vj , and let z and x be the vertices adjacent to y on path (vi ; vj )

and on path (uj ; vj ), respectively (see Figure 1). We show now that it is possible to reach a con guration in which pebble i is at vertex x, pebble j is at vertex vj and y and z are unoccuppied and then observe that in this con guration vertices vj and x are equivalent. Observe that, as the last move of Q takes pebble j from

vj

y

uj

x

T(y,vj) z

v

i

Fig. 1. The paths path( i j ) and path ( v ;v

u j ; vj

).

y to vj , in con guration V vertex y does not contain any pebble. Moreover, if in V there is a pebble at x, then it has been moved to x after the pebble j has reached y; from this it follows that in T(F(y); x) there is at least one empty vertex and hence x can be emptied by moving the pebble back into T(F(y); uj ). Call W the con guration reached. We observe that the problem of moving pebble i from vertex vi to x can be seen as an instance of the 1 Pebble problem. Thus, by Lemma 6, there exists a simple plan R that, starting from W , moves pebble i from vi to x. This is not enough for our purpose as R might move pebble j away from vj and move some pebble to z (y is free when the i-th pebble reaches x). In fact, pebble j might be moved in order to let other pebbles enter the subtree T(F(y); vj ); observe though that, by the properties of the simple plans, the pebbles distinct from the i-th that are moved to T(F(y); vj ) come from vertices visited by pebble i during his trip from vi to x and are moved before pebble i leaves vi for the rst time. On the other hand, vj is the only vertex of T(F(y); vj ) that pebble i could visit and we can nd a simple plan R that does not move pebble i to vj . In fact, pebble i is obliged to move in vj only if, arriving to y vertex x is occupied by another pebble h, moved in x during the plan, that has to be moved to a vertex previously visited by pebble i. Let u be the vertex where pebble j is moved. It can be easily seen that the plan that moves pebble h to u and leaves pebble j in vj is still a feasible plan that moves pebble i from vi to x. We can thus modify R so that pebble j is rst moved to x, then all pebbles that need to be moved are moved to T(F(y); vj ), and, nally, pebble j is moved back to vj . At the moment in which pebble i reaches x, z might be occupied. If this is so, then z must be occupied by a pebble h that was in x and was moved to z while i was standing in a vertex w adjacent to y other than x, vj and z. In this case we modify R by

moving pebble h to w while pebble i is in z and then moving pebble i from z to y and then from y to x. The next lemma proves that for each feasible permutation , there exists an i such that the pebbles i and (i) can be exchanged, leaving all other pebbles at their original position. Lemma 8. Let I = (T; S ; ) be a feasible instance of PPT. Then there exists i, 1  i  k, such that i 6= (i) and the instance I 0 = (T; S ; (i; (i))) is feasible too.

Lemma 9. The instance I = (T; S ; ) of PPT is feasible if and only if every good decomposition of  is feasible.

Finally, we can state the main result of this section. Theorem10. The instance I = (T; S ; ) is feasible if and only if, for 1  i  k, the exchange (i; (i)) is feasible.

4 The Algorithm for the PPT Problem In this section we give a linear time algorithm Verify for testing the feasibility of an instance J = (T; S ; ) of the PPT problem. By Theorem 10, the algorithm Verify has to test only whether the vertices si and s (i) are exchangeable, for i = 1;    ; k. To this aim the algorithm partitions the vertices of S into equivalence classes such that two vertices sl and sk are equivalent if and only if the pebbles in sl and sk are exchangeable. We give a linear time algorithm that computes the equivalence classes of S . For sake of clarity we assume that the tree T is binary, anyway all the arguments can be easily generalized. Let U = hu1 ; u2; : : :; uki be a con guration of k pebbles on T. For a vertex u of U containing a pebble, let seen (u) denote the set of vertices v containing a pebble and such that path (u; v) is empty. We assume that for each vertex v the number of holes contained in each subtree of T(v), the closest degree-3 vertex in each subtree, and, if v has a pebble, the set seen (v) are known. All this information can be easily computed in time O(n). The algorithm that computes the equivalence classes works in a top-down way by labelling the vertices occupied by a pebble in such a way that two vertices are equivalent if and only if they have the same label. Let class be a global variable used to assign the labels to the vertices initialized to 1. The algorithm works as follows. It assigns the label class to the rst vertex containing a pebble visited during the traversal and increments class . Then, for each labelled vertex ui , it labels in constant time each vertex of seen (ui ) which has not been labelled yet. For sake of simplicity we assume that ui has three adjacent vertices, x; y and z, and call Tx ; Ty and Tz the subtrees of F(ui) that contain x; y and z, respectively (we remind the reader that F(ui ) is the forest obtained by removing vertex ui). The algorithm distinguishes three cases, depending on how many

subtrees of F(ui) contain holes. If each subtree of F(ui) has at least one hole then all the vertices in seen (ui ) are given ui 's label. Suppose, now, that only one subtree of F(ui), say Tz , is full (that is has no holes). Then z, that is the only vertex of seen (ui ) belonging to Tz , is given the same label of ui . Moreover, all the vertices in seen (ui ) that belong to Tx are equivalent. If they are unlabelled, then take a vertex uj from this set and tests if it is equivalent to ui : if they are equivalent then all the vertices have the same label as ui, otherwise the algorithm assigns to each of them the label class and then increments class . The same steps are repeated for the set of vertices in seen (ui ) that belong to Ty . Finally, suppose that only one subtree of F(ui), say Tx , has holes and assume that it has at least two holes (otherwise no pebble can be exchanged). As we shall see later, y and z are equivalent and have the same label. If they are both unlabelled, the algorithm tests if y and ui are equivalent and assign to them either the same label of ui or the label class and then increments class . It remains to label the vertices of seen (ui ) that belong to Tx . The algorithm tests if each of these vertices is equivalent to ui and assigns the label of ui to the vertices equivalent to ui and class to the others. Then, if at least a vertex has been assigned a label distinct from ui , the variable class is incremented. It is easy to see that this algorithm takes time O(n) to label all the vertices containing a pebble. It remains to prove that it correctly computes the equivalence classes. Next we give necessary and sucient conditions to exchange two vertices. The conditions are very natural and the proof of the theorem is omitted. In the sequel we denote by C(F(u); v) the forest omprising all the trees of F(u) distinct from T(F(u); v). Theorem 11. Let U = hu1 ; u2; : : :; uk i be a con guration of the PPT problem and let ui and uj be vertices containing pebbles, and suppose that no pebble is contained in a vertex of path (ui ; uj ). The vertices ui and uj are equivalent if and only if at least one of the two vertices (say ui ) that satis es one of the following conditions:  there exists a degree three vertex v on path (ui ; uj ), distinct from ui and uj , such that the subtree not containing ui and uj has at least one hole;  there exists a degree three vertex v in C(F(ui); uj ) such that the distance from ui to v is d and C(F(ui); uj ) contains at least d + 2 holes;  ui is a degree three vertex and each subtree of C(F(ui); uj ) has at least one hole;  ui is a degree three vertex and the subtree T(F(ui); uj ) has at least one hole and one of the subtrees of C(F(ui); uj ) has at least two holes. Lemma 12. Let U = hu1 ; u2; : : :; uki be a con guration of PPT and let ui and ul be vertices of U such that path (ui ; ul ) contains only a vertex uj with a pebble. Let T 0 be the tree of F(uj ) not containing both ui and ul . If the vertices ui and ul are equivalent then either ui is equivalent to uj or T 0 has at least two holes. Lemma 13. Let U = hu1 ; u2; : : :; uki be a con guration of PPT and let ui and ul be vertices of U such that path (ui; ul ) contains r  2 vertices uj1 ;    ; uj other than ui and ul with pebbles. If the vertices ui and ul are equivalent then ui is equivalent to uj1 or to uj2 . r

By the above lemmas, the following corollary holds. Corollary14. Let U = hu1; u2; : : :; uk i be a con guration of PPT and let ui ; uj and ul be three vertices of U such that path (ui ; uj ) is empty, ul belongs to C(F(uj ); ui) and the subtree T(F(uj ); ui) has at least one hole. Then, ui and ul are equivalent if and only if they are both equivalent to uj .

Lemma 15. Let U = hu1; u2; : : :; uk i be a con guration of PPT. The algorithm Verify assigns the same label to two vertices of U if and only if they are equivalent. Proof's sketch: By Lemma 13 it is sucient to prove that for each vertex uj in U two vertices of seen (uj ) have the same label if and only if they are equivalent. In fact let ui and ul be a pair of vertices such that ui belongs to seen (uj ) and ul belongs to C(F(uj ); ui) but not to seen (uj ); if ui and ul are equivalent then ui is equivalent to uj or to the only vertex of seen (uj ) in path (uj ; ul ).

Without loss of generality we assume that uj has three adjacent vertices and call them x; y and z. Moreover, we call Tx ; Ty and Tz the subtrees of F(uj ) that contain x; y and z, respectively. We distinguish three cases, depending on the number of holes in F(uj ). If each of the three subtrees contains at least a hole, then, by Theorem 11, all the vertices of seen (uj ) are equivalent to uj and are correctly labelled with the same label as uj . Suppose, now, that a subtree of F(uj ), say Tz , has all vertices occupied by pebbles while now Tx and Ty contain each some holes. The vertex z (the unique in Tz belonging to seen (ui)) has the same label of ui as the third condition of Theorem 11 holds. All the verteces in Tx (Ty respectively) have the same label since for every such pair the rst condition of Theorem 11 holds. To determine these two labels (possibly equal), by Lemma 12 it is sucient to test whether conditions of Theorem 11 hold for uj and a witness vertex of seen (ui ) belonging to Tx and Ty . If they are equivalent all the vertices of seen (v) are equivalent, otherwise we assign a distinct label to the vertices of Tx and Ty . Finally suppose that only one subtree of F(uj ), say Tx , has holes and assume that it has at least two holes (if there is only one hole in T no vertices can be exchanged). By Lemma 12 y and z, that are the only vertices of seen (uj ) in Ty and Tz , are equivalent and they have the same label. The vertices of seen (uj ) in Tx can be divided into two sets. The vertices equivalent to uj have the same label as uj . By Theorem 11 all the vertices not equivalent to uj are in the same equivalence class and, by Corollary 14, they are not equivalent to any vertex in T(F(uj ); x).

5 Concluding Remarks Obstacles. Our feasibility algorithm works also if not all pebbles have a destination (in which case they can be moved to any vertex in the tree). As a straightforward application, we obtain an O(n) algorithm for the feasibility problem of the Tree Motion Planning Problem with k Robots (TMPR, in short) of [3].

Here, we have k1 robots each having its own destination (these correspond to pebbles with destination) and k2 obstacles (these correspond to pebbles with no destination). In [3] a simple feasibility criteria is given only for the case k1 = 1 and they leave as an open question to study the problem for more than 1 robot (i.e, the case k1 > 1). Finding a plan for solving the problem. It can be easily seen that our algorithm can be adapted to output, for each feasible instance, also a plan that solves the instance in which case the algorithm stops in time O(n + l) where l is the length of plan (a better running time can be obtained if a compact representation of the plan is sucient; we omit details). An analysis of the algorithm shows that the plan output consists of O(k2 (n ? k)) moves. The worst case is when k = n (0 < < 1), in which case the solution has O(n3 ) moves. In [2], it is claimed that all feasible instances admit an O(n2 )-move plan. We were unable to verify the claim. When k = n ? 1 we are able to improve this bound by computing in time proportional to the size of the tree an optimal plan that has length O(n). Open problems. Next we list some problems that seems to be worth investigating. First of all, we would like to ask whether our algorithm can be generalized to general graphs thus giving a linear time feasibility algorithm for the pebble motion problem on graphs. No much is known about the problem of computing the shortest plan on graphs. From a negative side it has been proved that the problem is NP-complete for k = n ? 1 even when restricted to the grid [4]. However, the cases k < n ? 1 have not been studied. Obtaining shortest plan for small k (i.e., k = 2; 3; 4:::) is trivial but the complexity of the algorithm seems to be exponential with k. On the positive side, algorithms for computing the shortest plan on trees have been given only by in [3] and [?] that considered the case of one pebble with destination and k ? 1 pebbles without destination.

References 1. V. Auletta, D. Parente, G. Persiano, Optimal Planning of Robot Motion on a Tree with Obstacles, T.R. 18, Dip. Informatica ed Applicazioni, Univ. di Salerno, 1995. 2. D. Kornhauser, G. Miller, and P. Spirakis, Coordinating pebble motion on graphs, the diameter of permutations groups, and applications, in Proc. of 25-th IEEE Symp. on Found. of Comp. Sc., 241{250, 1984. 3. C. Papadimitriou, P. Raghavan, M. Sudan and H. Tamaki, Motion Planning on a graph, in Proc. of 35-th IEEE Symp. on Found. of Comp. Sc., 511{520, 1994. 4. D. Ratner and M. Warmuth, The (n2 ?1)-Puzzle and Related Relocation Problems, Journal of Symbolic Computation, 10:111{137, 1990. 5. J.T. Schwartz, M. Sharir, and J. Hopcroft, Planning, Geometry, and Complexity of Robot Motion, Ablex, Norwood NJ, 1987. 6. R. M. Wilson, Graph puzzles, homotopy, and the alternating group, Journal of Comb. Theory Series B, 16, 86-94, 1974. This article was processed using the LaTEX macro package with LLNCS style