Shortest Reconfiguration of Sliding Tokens on a Caterpillar

# Shortest Reconfiguration of Sliding Tokens on a Caterpillar

## Abstract

Suppose that we are given two independent sets and of a graph such that , and imagine that a token is placed on each vertex in . Then, the sliding token problem is to determine whether there exists a sequence of independent sets which transforms into so that each independent set in the sequence results from the previous one by sliding exactly one token along an edge in the graph. The sliding token problem is one of the reconfiguration problems that attract the attention from the viewpoint of theoretical computer science. The reconfiguration problems tend to be PSPACE-complete in general, and some polynomial time algorithms are shown in restricted cases. Recently, the problems that aim at finding a shortest reconfiguration sequence are investigated. For the 3SAT problem, a trichotomy for the complexity of finding the shortest sequence has been shown; that is, it is in P, NP-complete, or PSPACE-complete in certain conditions. In general, even if it is polynomial time solvable to decide whether two instances are reconfigured with each other, it can be NP-complete to find a shortest sequence between them. Namely, finding a shortest sequence between two independent sets can be more difficult than the decision problem of reconfigurability between them. In this paper, we show that the problem for finding a shortest sequence between two independent sets is polynomial time solvable for some graph classes which are subclasses of the class of interval graphs. More precisely, we can find a shortest sequence between two independent sets on a graph in polynomial time if either is a proper interval graph, a trivially perfect graph, or a caterpillar. As far as the authors know, this is the first polynomial time algorithm for the shortest sliding token problem for a graph class that requires detours.

## 1Introduction

Recently, the reconfiguration problems attract the attention from the viewpoint of theoretical computer science. The problem arises when we wish to find a step-by-step transformation between two feasible solutions of a problem such that all intermediate results are also feasible and each step abides by a fixed reconfiguration rule, that is, an adjacency relation defined on feasible solutions of the original problem. The reconfiguration problems have been studied extensively for several well-known problems, including independent set [12], satisfiability [11], set cover, clique, matching [14], vertex-coloring [2], shortest path [15], and so on.

The reconfiguration problem can be seen as a natural “puzzle” from the viewpoint of recreational mathematics. The 15 puzzle is one of the most famous classic puzzles, that had the greatest impact on American and European society of any mechanical puzzle the word has ever known in 1880 (see [23] for its rich history). It is well known that the 15 puzzle has a parity; for any two placements, we can decide whether two placements are reconfigurable or not by checking the parity. Therefore, we can solve the reconfiguration problem in linear time just by checking whether the parity of one placement coincides with the other or not. Moreover, we can say that the distance between any two reconfigurable placements is , that is, we can reconfigure from one to the other in sliding pieces when the size of the board is . However, surprisingly, for these two reconfigurable placements, finding a shortest path is NP-complete in general [22]. Namely, although we know that it is , finding a shortest one is NP-complete. Another interesting property of the 15 puzzle is in another case of generalization. In the 15 puzzle, every peace has the same unit size of . We have the other famous classic puzzles that can be seen as a generalization of this viewpoint. That is, when we allow to have rectangles, we have the other classic puzzles, called “Dad puzzle” and its variants (see Figure 1). Gardner said that “These puzzles are very much in want of a theory” in 1964 [10], and Hearn and Demaine have gave the theory after 40 years [12]; they prove that these puzzles are PSPACE-complete in general using their nondeterministic constraint logic model [13]. That is, the reconfiguration of the sliding block puzzle is PSPACE-complete in general decision problem, and linear time solvable if every block is the unit square. However, finding a shortest reconfiguration for the latter easy case is NP-complete. In other words, we can characterize these three complexity classes using the model of sliding block puzzle.

From the viewpoint of theoretical computer science, one of the most important problems is the 3SAT problem. For this 3SAT problem, a similar trichotomy for the complexity of finding a shortest sequence has been shown recently; that is, for the reconfiguration problem of 3SAT, finding a shortest sequence between two satisfiable assignments is in P, NP-complete, or PSPACE-complete in certain conditions [19]. In general, the reconfiguration problems tend to be PSPACE-complete, and some polynomial time algorithms are shown in restricted cases. In the reconfiguration problems, finding a shortest sequence can be a new trend in theoretical computer science because it has a great potential to characterize the class NP from a new viewpoint.

Beside the 3SAT problem, one of the most important problems in theoretical computer science is the independent set problem. Recall that an independent set of a graph is a vertex-subset of in which no two vertices are adjacent. (See Figure 2 which depicts five different independent sets in the same graph.) For this notion, the natural reconfiguration problem is called the sliding token problem introduced by Hearn and Demaine [12]: Suppose that we are given two independent sets and of a graph such that , and imagine that a token (coin) is placed on each vertex in . Then, the sliding token problem is to determine whether there exists a sequence of independent sets of such that

Figure 2 illustrates a sequence of independent sets which transforms into . Hearn and Demaine proved that the sliding token problem is PSPACE-complete for planar graphs.

(We note that the reconfiguration problem for independent set have some variants. In [16], the reconfiguration problem for independent set is studied under three reconfiguration rules called “token sliding,” “token jumping,” and “token addition and removal.” In this paper, we only consider token sliding model, and see [16] for the other models.)

For the sliding token problem, some polynomial time algorithms are investigated as follows: Linear time algorithms have been shown for cographs (also known as -free graphs) [16] and trees [7]. Polynomial time algorithms are shown for bipartite permutation graphs [9], and claw-free graphs [4]. On the other hand, PSPACE-completeness is also shown for graphs of bounded tree-width [21], and planar graphs [13].

In this context, we investigate for finding a shortest sequence of the sliding token problem, which is called the shortest sliding token problem. That is, our problem is formalized as follows:

We note that is not necessarily in polynomial of ; this is an issue how we formalize the problem, and if we do not know that is in polynomial or not. If the length is given as a part of input, we may be able to decide whether in polynomial time even if itself is not in polynomial. However, if we have to output the sequence itself, it cannot be solved in polynomial time if is not in polynomial.

In this paper, we will show that the shortest sliding token problem is solvable in polynomial time for the following graph classes:

Proper interval graphs: We first prove that any two independent sets of a proper interval graph can be transformed into each other. In other words, every proper interval graph with two independent sets and is a yes-instance of the problem if . Furthermore, we can find the ordering of tokens to be slid in a minimum-length sequence in time (implicitly), even though there exists an infinite family of independent sets on paths (and hence on proper interval graphs) for which any sequence requires length.

Trivially perfect graphs: We then give an -time algorithm for trivially perfect graphs which actually finds a shortest sequence if such a sequence exists. In contrast to proper interval graphs, any shortest sequence is of length for trivially perfect graphs. Note that trivially perfect graphs form a subclass of cographs, and hence its polynomial time solvability has been known [16].

Caterpillars: We finally give an -time algorithm for caterpillars for the shortest sliding token problem. To make self-contained, we first show a linear time algorithm for decision problem that asks whether two independent sets can be transformed into each other. (We note that this problem can be solved in linear time for a tree [7].) For a yes-instance, we next show an algorithm that finds a shortest sequence of token sliding between two independent sets.

We here remark that, since the problem is PSPACE-complete in general, an instance of the sliding token problem may require the exponential number of independent sets to transform. In such a case, tokens should make detours to avoid violating to be independent (as shown in Figure 2). As we will see, caterpillars certainly require to make detours to transform. Therefore, it is remarkable that any yes-instance on a caterpillar requires a sequence of token-slides of polynomial length. This is still open even for a tree. That is, in a tree, we can determine if two independent sets are reconfigurable in linear time due to [7], however, we do not know if the length of the sequence is in polynomial.

As far as the authors know, this is the first polynomial time algorithm for the shortest sliding token problem for a graph class that requires detours of tokens.

## 2Preliminaries

In this section, we introduce some basic terms and notations. In the sliding token problem, we may assume without loss of generality that graphs are simple and connected. For a graph , we let and .

### 2.1Sliding token

For two independent sets and of the same cardinality in a graph , if there exists exactly one edge in such that and , then we say that can be obtained from by sliding a token on the vertex to its adjacent vertex along the edge , and denote it by . We remark that the tokens are unlabeled, while the vertices in a graph are labeled.

A reconfiguration sequence between two independent sets and of is a sequence of independent sets of such that for . We denote by if there exists a reconfiguration sequence between and . We note that a reconfiguration sequence is reversible, that is, we have if and only if . Thus we say that two independent sets and are reconfigurable into each other if . The length of a reconfiguration sequence is defined as the number of independent sets contained in . For example, the length of the reconfiguration sequence in Figure 2 is .

The sliding token problem is to determine whether two given independent sets and of a graph are reconfigurable into each other. We may assume without loss of generality that ; otherwise the answer is clearly “no.” Note that the sliding token problem is a decision problem asking for the existence of a reconfiguration sequence between and , and hence it does not ask an actual reconfiguration sequence. In this paper, we will consider the shortest sliding token problem that computes a shortest reconfiguration sequence between two independent sets. Note that the length of a reconfiguration sequence may not be in polynomial of the size of the graph since the sequence may contain detours of tokens.

We always denote by and the initial and target independent sets of , respectively, as an instance of the (shortest) sliding token problem; we wish to slide tokens on the vertices in to the vertices in . We sometimes call the vertices in blue, and the vertices in red; each vertex in is blue and red.

### 2.2Target-assignment

We here give another notation of the sliding token problem, which is useful to explain our algorithm.

Let be an initial independent set of a graph . For the sake of convenience, we label the tokens on the vertices in ; let be the token placed on for each , . Let be a reconfiguration sequence between and an independent set of , and hence . Then, for each token , , we denote by the vertex in on which the token is placed via the reconfiguration sequence . Notice that .

Let be a target independent set of , which is not necessarily reconfigurable from . Then, we call a mapping a target-assignment between and . The target-assignment is said to be proper if there exists a reconfiguration sequence such that for all , . Note that there is no proper target-assignment between and if . Therefore, the sliding token problem can be seen as the problem of determining whether there exists at least one proper target-assignment between and .

### 2.3Interval graphs and subclasses

The neighborhood of a vertex in a graph is the set of all vertices adjacent to , and we denote it by . Let . For any graph , two vertices and are called strong twins if , and weak twins if . In our problem, strong twins have no meaning: when and are strong twins, only one of them can be used by a token. Therefore, in this paper, we only consider the graphs without strong twins. That is, for any pair of vertices and , we have . (We have to take care about weak twins; see Section 5 for the details.)

A graph with is an interval graph if there exists a set of (closed) intervals such that if and only if for each and with .1 We call the set of intervals an interval representation of the graph, and sometimes identify a vertex with its corresponding interval . We denote by and the left and right endpoints of an interval , respectively. That is, we always have for any interval .

To specify the bottleneck of the running time of our algorithms, we suppose that an interval graph is given as an input by its interval representation using space. (If necessary, an interval representation of can be found in time [17].) More precisely, is given by a string of length over alphabets . For example, a complete graph with three vertices can be given by an interval representation , and a path of length two is given by an interval representation .

An interval graph is proper if it has an interval representation such that no interval properly contains another. The class of proper interval graphs is also known as the class of unit interval graphs [1]: an interval graph is unit if it has an interval representation such that every interval has unit length. Hereafter, we assume that each proper interval graph is given in the interval representation of intervals of unit length. In the context of the interval representation, an interval graph is proper if and only if if and only if .

An interval graph is trivially perfect if it has an interval representation such that the relationship between any two intervals is either disjoint or inclusion. That is, for any two intervals and with , we have either or .

A caterpillar is a tree (i.e., a connected acyclic graph) that consists of two subsets and of as follows. The vertex set induces a path in , and each vertex in has degree 1, and its unique neighbor is in . We call the path spine, and each vertex in leaf. In this paper, without loss of generality, we assume that , , and . That is, the endpoints and of the spine should have at least one leaf. It is easy to see that the class of caterpillars is a proper subset of the class of interval graphs, and these three subclasses are incomparable with each other.

## 3Proper Interval Graphs

We show the main theorem in this section for proper interval graphs, which first says that the answer of sliding token is always “yes” for connected proper interval graphs. We give a constructive proof of the claim, and it certainly finds a shortest sequence in linear time.

We give a constructive proof for Theorem ?, that is, we give an algorithm which actually finds a shortest reconfiguration sequence between any two independent sets and of a connected proper interval graph .

A connected proper interval graph has a unique interval representation (up to reversal), and we can assume that each interval is of unit length in the representation [8]. Therefore, by renumbering the vertices, we can fix an interval representation of so that (and ) for each , , and each interval corresponds to the vertex .

Let and be any given initial and target independent sets of , respectively. Without loss of generality, we assume that the blue vertices are labeled from left to right (according to the interval representation of ), that is, if ; similarly, we assume that the red vertices are labeled from left to right. Then, we define a target-assignment , as follows: for each blue vertex

To prove Theorem ?, it suffices to show that is proper, and each token takes no detours.

### 3.1String representation

By traversing the interval representation of a connected proper interval graph from left to right, we can obtain a string which is a superstring of both and , that is, each letter in is one of the vertices in and appears in before if . We may assume without loss of generality that since the reconfiguration rule is symmetric in sliding token. If a vertex is contained in both and , as and , then we assume that it appears as in , that is, the blue vertex appears in before the red vertex . Then, for each , , we define the height at by the number of blue vertices appeared in the substring minus the number of red vertices appeared in . For the sake of notational convenience, we define . Then can be recursively computed as follows:

Note that for any string since .

Using the notion of height, we split the string into substrings at every point of height , that is, in each substring , we have and for all , . For example, a string can be split into four substrings , , and . Then, the substrings form a partition of , and each substring contains the same number of blue and red tokens. We call such a partition the partition of at height .

By the definitions, the claim (a) clearly holds. We thus show that the claim (b) holds. (The proof for the claim (c) is symmetric.)

Since and starts with a blue vertex, we have . We now suppose for a contradiction that there exists a blue vertex which appears in after its corresponding red vertex . Then, . We assume that is the minimum index among such blue vertices in . Then, in the substring of , there are exactly red vertices. On the other hand, since , the substring contains at most blue vertices. Therefore, by the definition of height, we have . Since and , by Eq. (Equation 2) there must exist an index such that and . This contradicts the fact that is a substring in the partition of at height .

### 3.2Algorithm

Recall that we have fixed the unique interval representation of a connected proper interval graph so that for each , , and each interval corresponds to the vertex . Since all intervals in have unit length, the following proposition clearly holds.

Let be the string of length obtained from two given independent sets and of a connected proper interval graph , where . Let be the partition of at height . The following lemma shows that the tokens in each substring can always reach their corresponding red vertices. (Note that we sometimes denote simply by the set of all vertices appeared in the substring , .)

We first consider the case where starts with the blue vertex , that is, . Then, by Lemma ?(b) each blue vertex , , appears in before the corresponding red vertex . Therefore, we know that , and hence it is red. Suppose that , then all vertices appeared in are red. Roughly speaking, we slide the tokens from left to right in this order.

We first claim that the token can be slid from to . By Proposition ? there is a path between and which passes through only intervals contained in . Since is an independent set of , the vertex is not adjacent to any other vertices in . Since , by Proposition ? all vertices in are not adjacent to any of tokens that are now placed on , respectively. Therefore, we can slide the token from to . We fix the token on , and will not slide it anymore.

We then slide the next token on to along a path which passes through only intervals contained in . Since is an independent set of , the corresponding red vertex is not adjacent to on which the token is now placed. Recall that , and hence by Proposition ?, is not adjacent to any vertex in . Similarly as above, the tokens are not adjacent to any vertex in . Therefore, we can slide the token from to .

Repeat this process until the token on is slid to . In this way, there is a reconfiguration sequence between and such that tokens are slid along edges only in the subgraph of induced by the vertices contained in .

The symmetric arguments prove the case where starts with the red vertex . Note that, in this case, we slide the tokens from right to left in this order.

We now give an algorithm which slides all tokens on the vertices in to the vertices in . Recall that are the substrings in the partition of at height . Intuitively, the algorithm repeatedly picks up one substring , and slides all tokens in to . By Lemma ? it works locally in each substring , but it should be noted that a token in may be adjacent to another token in or at the boundary of the substrings. To avoid this, we define a partial order over the substrings , as follows.

Consider any two consecutive substrings and , and let . Then, the first letter of is . We first consider the case where both and are the same color. Then, since and are both in the same independent set of , they are not adjacent. Therefore, by Proposition ? and Lemma ?, we can deal with and independently. In this case, we thus do not define the ordering between and . We then consider the case where and have different colors; in this case, we have to define their ordering. Suppose that is blue and is red; then we have and . By Lemma ? the token on is slid to left, and the token will reach from right. Therefore, the algorithm has to deal with before . Note that, after sliding all tokens in , they are on the red vertices , respectively, and hence the tokens in are not adjacent to any of them. By the symmetric argument, if is red and is blue, should be dealt with before .

Notice that such an ordering is defined only for two consecutive substrings and , . Therefore, the partial order over the substrings is acyclic, and hence there exists a total order which is consistent with the partial order defined above. The algorithm certainly slides all tokens from to according to the total order. Therefore, the target-assignment defined in Eq. (Equation 1) is proper, and hence .

Therefore, there always exists a reconfiguration sequence between two independent sets and of a connected proper interval graph . We now discuss the length of reconfiguration sequences between and , together with the running time of our algorithm.

We first modify our algorithm so that it finds a shortest reconfiguration sequence between and . To do that, it suffices to slide each token , , from the blue vertex to its corresponding red vertex along the shortest path between and . We may assume without loss of generality that , that is, the token will be slid from left to right. Then, for the interval , we choose an interval such that and is the maximum among all . If , we can slide from to directly; otherwise we slide to the vertex , and repeat.

We then prove the claim (1). If we simply want to compute the ordering of tokens to be slid in a shortest reconfiguration sequence, it suffices to compute the partial order over the substrings in the partition of the string at height . It is not difficult to implement our algorithm in Section 3.2 to run in time and space. Therefore, the claim (1) holds.

We finally prove the claim (2). Remember that each token , , is slid along the shortest path from to . Furthermore, once the token reaches , it is not slid anymore. Therefore, the length of a shortest reconfiguration sequence between and is given by the sum of all lengths of the shortest paths between and . It is clear that this sum is . We output only the shortest paths between and , together with the ordering of the tokens to be slid. Therefore, the claim (2) holds.

This proposition also completes the proof of Theorem ?.

It is remarkable that there exists an infinite family of instances for which any reconfiguration sequence requires length. To show this, we give an instance such that each shortest path between and is . Simple example is: is a path of length for any positive integer , , and . In this instance, each token must be slid times, and hence it requires time to output all of them. We note that a path is not only a proper interval graph, but also a caterpillar. Thus this simple example also works as a caterpillar.

## 4Trivially perfect graphs

The main result of this section is the following theorem.

In this section, we explicitly give such an algorithm as a proof of Theorem ?. Note that there are no-instances for trivially perfect graphs. However, for trivially perfect graphs, we construct a proper target-assignment between and efficiently if it exists.

### 4.1MPQ-tree for trivially perfect graphs

The -tree of an interval graph is a kind of decomposition tree, developed by Korte and Möhring [17], which represents the set of all feasible interval representations of . For an interval graph , although there are exponentially many interval representations for , its corresponding -tree is unique up to isomorphism. For the notion of -trees, the following theorem is known:

Since it is involved to define -tree for general interval graphs, we here give a simplified definition of -tree only for the class of trivially perfect graphs. (See [17] for the detailed definition of the -tree for a general interval graph.) Let be a trivially perfect graph. Recall that a trivially perfect graph has an interval representation such that the relationship between any two intervals is either disjoint or inclusion. Then, the -tree of is a rooted tree such that each node, called a -node, in is associated with a non-empty set of vertices in such that (a) each vertex appears in exactly one -node in , and (b) if a vertex is in an ancestor node of another node that contains , then in any interval representation of , where and correspond to the intervals and , respectively (see Figure 3 as an example). By the property (b), the ancestor/descendant relationship on corresponds to the inclusion relationship in the interval representation of . Thus, if is in an ancestor node of another node that contains in the -tree.

Let be the (unique) -tree of a connected trivially perfect graph . For two vertices and in , we denote by the least common ancestor in for the nodes containing and . By the property (a) the node can be uniquely defined.

### 4.2Basic properties and key lemma

Let be the (unique) -tree of a connected trivially perfect graph . Recall that the interval representation of a trivially perfect graph has just disjoint or inclusion relationship. This fact implies the following observation.

We first observe that every -node of is non-empty. If the root is empty, the graph is disconnected, which is a contradiction. If some non-root -node is empty, joining all children of to the parent of , we obtain a simpler -tree than , which contradicts the construction of the unique -tree in [17]. Thus every -node is non-empty. Therefore, there is at least one vertex in . Then, the property (b) implies that and , and hence and are both in . Therefore, there is a path of length at most two between and via . When we have or , the path degenerates to the edge .

Let be the set of vertices in appearing in the -nodes on the (unique) path from to the root of the -tree. By the definition of -tree, we clearly have the following observation. (Recall also that each token must be slid along an edge of .)

We are now ready to give the key lemma for trivially perfect graphs.

We first show the sufficiency. For a target-assignment between and , suppose that the nodes and are not in the ancestor/descendant relationship on for every pair of vertices . Then, we can simply slide the tokens one by one in an arbitrary order; by Observation ? each token , , can be slid along a path from to via a vertex in . Note that there is no token adjacent to , because the nodes and are not in the ancestor/descendant relationship on . Thus, there is a reconfiguration sequence between and according to , and hence is proper.

We then show the necessity. Suppose that is proper, and suppose for a contradiction that there exists a pair of vertices such that the nodes and are in the ancestor/descendant relationship on ; without loss of generality, we assume that is an ancestor of . Since is proper, there exists a reconfiguration sequence between and which slides the token from to and also slides the token from to . By Observation ? there is at least one vertex in which is passed through by . Similarly, there is at least one vertex in which is passed through by . Let and be the -nodes that contains and , respectively. Since and are in the ancestor/descendant relationship on , so are and . First suppose is an ancestor of . Then we have , and . Therefore, if we slide via , then would be adjacent to the other token which is on one of the three vertices , and . Thus, the token should “escape” from before sliding . However, we can establish the same argument for any descendant of , and hence must escape to some vertex that is contained in an ancestor of at first. However, the vertex is adjacent to all of , and hence cannot escape before sliding . This contradicts the assumption that slides the token from to and also slides the token from to . The other case, is an ancestor of , is symmetric.

### 4.3Algorithm and its correctness

We now describe our linear-time algorithm for a trivially perfect graph. Let be the -tree of a connected trivially perfect graph . Let and be given initial and target independent sets of , respectively. Then, we determine whether as follows:

We will show later in Lemma ? that it suffices to check only in order to determine whether or not. Indeed, our linear-time algorithm executes (A) and (B) above at the same time, in the bottom-up manner based on .

Description of the algorithm Remember that the vertex-set associated to each -node in induces a clique in . Therefore, for any independent set of , each -node contains at most one vertex in , and hence contains at most one token. We put a “blue token” for each -node containing a blue vertex in , and also put a “red token” for each -node containing a red vertex in . Note that a -node may contain a pair of blue and red tokens. Our algorithm lifts up the tokens from the leaves to the root of , and if a blue token meets a red token at their least common ancestor in , then we replace them by a single “green token.” This corresponds to setting . More precisely, at initialization step, the algorithm first collects all leaves of in a queue, which is called frontier. The algorithm marks the nodes in the frontier, and lifts up each token to its parent -node. Each -node is put into the frontier if its all children are marked, and then, all children of are removed from the frontier after the following procedure at :

Repeating this process, and the algorithm outputs “yes” if and only when the frontier contains only the root -node of which is in one of Cases (1)–(3) above.

Correctness of the algorithm It is not difficult to implement our algorithm to run in time and space. Therefore, we here prove the correctness of the algorithm.

We first show that if the algorithm outputs “yes.” In this case, the algorithm is in Cases (1), (2), or (3) at each -nodes in (including the root ). Then, the target-assignment has been (completely) constructed: for each blue vertex , is the red vertex in such that has the minimum height in among all vertices . Then, we have the following lemma.

By Lemma ? it suffices to show that the target-assignment constructed by the algorithm satisfies that the nodes and are not in the ancestor/descendant relationship on for every pair of vertices .

We first consider the case where a -node is in Case (2). Then, there is exactly one pair of a blue token and a red token , and . Since and did not meet any other tokens before , the subtree of contains only the two tokens and . Therefore, the lemma clearly holds for .

We then consider the case where a -node is in Case (3). Then, two or more least common ancestors of pairs of blue and red tokens meet at this node . Notice that the green tokens were placed on children’s node of in the previous step of the algorithm, and hence they were sibling in . Therefore, their corresponding least common ancestors are not in the ancestor/descendant relationship on .

The following lemma completes the correctness proof of our algorithm.

We assume that the algorithm outputs “no.” Then, by Lemma ?, it suffices to show that there is no target-assignment between and such that and are not in the ancestor/descendant relationship on for every pair of vertices .

Suppose for a contradiction that the algorithm outputs “no,” but there exists a target-assignment between and such that and are not in the ancestor/descendant relationship on for every pair of vertices . Then, by Lemma ?, is proper and hence . Since the algorithm outputs “no,” there is a -node which is in either Case (4) or (5).

We first assume that the -node is in Case (4). Without loss of generality, at least two blue tokens and meet at this node . Then, the -tree contains two red tokens and placed on and , respectively. Notice that, since and did not meet any red token before at the node , both and must be placed on either or nodes in . Then, the least common ancestor must be an ancestor of , and so is the least common ancestor . Therefore, the nodes and are in the ancestor/descendant relationship, a contradiction.

Thus, the algorithm outputs “no” because the -node is in Case (5). In this case, without loss of generality, at least one blue token and at least one green token meet at this node . Then, the red token corresponding to must be placed on either or some node in . Therefore, the least common ancestor is an ancestor of . Note that corresponds to the least common ancestor of some pair of blue and red tokens, say and , and is an ancestor of it. Therefore, the nodes and are in the ancestor/descendant relationship on , a contradiction.

### 4.4Shortest reconfiguration sequence

To complete the proof of Theorem ?, we finally show that our algorithm in Section 4.3 can be modified so that it actually finds a shortest reconfiguration sequence between and .

Once we know that holds by the -time algorithm in Section 4.3, we run it again with modification that “green” tokens are left at the corresponding least common ancestors. As in the proof of Lemma ?, we can now obtain a reconfiguration sequence between and such that each token , , is slid at most twice. It is sufficient to output and , and hence the running time of the modified algorithm is proportional to , the number of independent sets in . Since and each token , , is slid at most twice in , we have , that is, the length of is . Therefore, the modified algorithm also runs in time and space. Notice that each token is slid to its target vertex along a shortest path (of length at most two) between and without detour, and hence has the minimum length.

This completes the proof of Theorem ?.

## 5Caterpillars

The main result of this section is the following theorem.

Let be a caterpillar with spine which induces the path , and leaf set . We assume that , , and . First we show that we can assume that each spine vertex has at most one leaf without loss of generality.

On , let be any vertex in with . Then there exist at least two leaves and attached to (note that they are weak twins). Now we consider the case that two tokens in are on and . Then, we cannot slide these two tokens at all, and any other token cannot pass through since it is blocked by them. If contains these two tokens also, we can split the problem into two subproblems by removing and its leaves from , and solve it separately. Otherwise, the answer is “no” (remind that the problem is reversible; that is, if tokens cannot be slid, there are no other tokens which slide into the situation). Therefore, if at least two tokens are placed on the leaves of a vertex of the original graph, we can reduce the case in linear time. Thus we assume that every spine vertex with its leaves contains at most one token in and , respectively. Then, by the same reason, we can remove all leaves but one of each spine vertex. More precisely, regardless whether or , at most one leaf for each spine vertex is used for the transitions. Therefore, we can remove all other useless leaves but one from each spine vertex. Especially, removing all useless leaves, we have .

Hereafter, we only consider the caterpillars stated in Lemma ?. That is, for any given caterpillar with spine , we assume that and for each . Then, we denote the unique leaf of by if it exists.

We here introduce a key notion of the problem on these caterpillars that is named locked path. Let and be a caterpillar and an independent set of , respectively. A path on is locked by if and only if

This notion is simplified version of a locked tree used in [7]. Using the discussion in [7], we obtain the condition for the immovable independent set on a caterpillar:

The proof can be found in [7], and omitted here. Intuitively, for any caterpillar and its independent set , if contains a locked path , we cannot slide any token through the vertices in . Therefore, splits into two subgraphs, and we obtain two completely separated subproblems. (We note that the endpoints of are leaves with tokens, and their neighbors are spine vertices without tokens. This property admits us to cut the graph at the spine vertices on the locked path.) Therefore, we obtain the following lemma:

In , when contains a locked path , it should be appear in ; otherwise, the answer is no. Therefore, we can remove all vertices in and obtain the new graph with two independent sets and such that with and is a yes-instance if and only if with and is a yes-instance. Repeating this process, we obtain disconnected caterpillar and two independent sets and such that both of and contain no locked paths. On a disconnected graph, we can solve the problem separately for each connected component. Therefore, we can assume that the graph is connected, which completes the proof.

Hereafter, without loss of generality, we assume that the caterpillar with two independent sets and satisfies the conditions in Lemmas ? and ?. That is, each spine vertex has at most one leaf , and have one leaf and , respectively, both of and contain no locked path, and . By the result in [7], this is a yes-instance. Thus, it is sufficient to show an time algorithm that computes a shortest reconfiguration sequence between and .

Each pair can have at most one token. Therefore, without loss of generality, we can assume that the blue vertices in are labeled from left to right (according to the order , , , of