    # The Partition Spanning Forest Problem

Given a set of colored points in the plane, we ask if there exists a crossing-free straight-line drawing of a spanning forest, such that every tree in the forest contains exactly the points of one color class. We show that the problem is NP-complete, even if every color class contains at most five points, but it is solvable in O(n^2) time when each color class contains at most three points. If we require that the spanning forest is a linear forest, then the problem becomes NP-complete even if every color class contains at most four points.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Let be a set of  points in the plane and let be a partition of  into  sets of points, called color classes, such that every point belongs to exactly one color class. We study the partition spanning forest problem which is defined as follows: Is there a crossing-free straight-line drawing of a spanning forest  that consists of  trees  such that each tree , , contains exactly the points of the color class ? Figure 1 shows an example with three color classes.

For , the problem is equivalent to finding a geometric spanning tree of  which trivially always exists. Hence, several optimization versions of this problem have been studied in the past; see Eppstein  for a survey. Bereg et al.  showed how to solve the problem in time in the case of . Hiu and Schaefer  proved that it is -complete to decide for two color classes and whether there exists an ordering  such that the geometric paths and are crossing-free. Bereg et al.  asked for not necessarily straight-line Steiner trees for each color class of minimum total length and gave a PTAS for , a -approximation for , and a -approximation for .

In this paper, we analyze the complexity of the partition spanning forest problem for color classes of bounded size. We give an -time algorithm when each color class contains at most three points (Sec. 2) and show that the problem is -complete for up to five points per color class (Sec. 3); the complexity for four points remains open. In Section 4, we show that the partition spanning linear forest problem, where each tree is required to be a path, is -complete, even if every color class contains at most four points. The complexity of the non-linear version remains open if every color class contains at most four points. Figure 1: A solution to a problem instance with three color classes.

## 2 Color classes with at most three points

In the case where each color class of the input instance contains of at most three points, the partition spanning forest problem can be solved in polynomial time. In fact, with this restriction the problem can be formulated as a 2-SAT problem.

Assume that our point set consists of points. In the following we will understand the color classes as subsets of indices. For a point we denote its color class by . We refer to the edges where and are in the same color class as the potential edges of the instance. Observe that an arbitrary choice of the potential edges forms a solution to the problem (with at most three points per color class) if and only if it satisfies the following conditions: (i) For each point , if , then at least one potential edge incident to  must be chosen. (ii) For any pair of potential edges and that intersect in the interior, at most one of them is chosen. (iii) For any color class with one of the potential edges of that color is not chosen.

Observe that condition (iii) can be skipped, as any choice of potential edges satisfying conditions (i) and (ii) can be extended to also satisfy (iii).

We model the possible choices of potential edges that satisfy conditions (i) and (ii) by a 2-SAT formula as follows. For each potential edge there is a variable with the interpretation that if is true, then the edge connecting to is not chosen as part of the solution, and otherwise it is.

Conditions (i) and (ii) can be expressed as 2-SAT formulas using the variables as follows. For condition (i), we create for each point the (sub)formula . Note that this is a 2-SAT formula since by the assumption that each color class has size at most three. For any two potential edges and that cross, we add the clause , thus enforcing condition (ii). It follows that the resulting 2-SAT formula is satisfiable if and only if the original instance of the partition spanning forest problem admits a solution.

If a color class contains only one point, then we can always draw it as a singleton point since we assumed general position for our input points. Thus, we are left with sets of either two or three points. In the case of two points, there is a unique spanning tree. However, for sets with three points we have three choices. For each of those spanning trees, we introduce a boolean variable. In particular, if the color class is , then we denote the boolean variable for the spanning tree formed by the edges and by , using its endpoints as the indices. The interpretation of the variable assignment will be the following: if is true, then the corresponding spanning tree is selected as the spanning tree for its color class; if is false, then any of the three possible spanning trees of its color class can be chosen. To make this work, we have to guarantee that at most one of , and is true. This can be enforced by the 2-SAT (sub)formula

 (¬xij∨¬xik)∧(¬xjk∨¬xik)∧(¬xij∨¬xjk).

We add this formula for every color class with three elements.

In the next step, we process each pair of color classes. While processing, we will observe one of the following: (i) the local configuration already forbids the existence of a partition drawing, (ii) the two sets impose a constraint on the available spanning trees, or (iii) the two sets do not interfere with each other. In case of (i) we can stop the algorithm, in case of (ii) we (iteratively) build a 2-SAT formula to model these constraints.

Let now and be a pair of color classes. If , then their convex hull is either intersecting or not. In the former case, there exists no partition drawing; in the latter, these two sets impose no constraints.

If one of the color classes contains three points (say ) and the other contains two points, then we are left with one of the following situations. The convex hulls of both sets could be disjoint, which yields no constraints. If two edges of the convex hull of  are intersected by the convex hull of , then there cannot be a spanning tree of  avoiding the edge spanned by . Thus, in this case we cannot have a partition drawing. Finally, if the segment spanned by  intersects a single edge of the convex hull of , then only one of the three possible spanning tress of  can be part of a partition drawing. In this case, we add an appropriate clause to the 2-SAT formula that enforces the corresponding spanning tree.

We are left with the case that . Clearly, if the convex hulls of these sets are disjoint, then this pair imposes no constraints. If their convex hulls intersect in four or even six points, it is an easy exercise to see that in this case a partition drawing is not possible. If there are two intersection points, we have to consider two cases. If both intersections lie on the same edge, say spanned by points from , then only one spanning tree in  can be chosen (see Figure 2(a)). In this case, we enforce to be true by adding the clause to the formula. In the remaining case, let and . We assume that intersects and that intersects . Now, we have two pairs of possible spanning trees (see Figure 2(b–c)). To model this, we add the clauses

 (¬xij∨¬xab)∧(¬xjk∨¬xbc)

to our 2-SAT formula.

By the above strategy, we have constructed a 2-SAT formula that is satisfiable if and only if the input instance has a partition drawing.

The formula has length at most and can be constructed in time as well. By using an efficient algorithm for 2-SAT , we get the desired algorithm. We summarize our construction in the following theorem.

###### Theorem 1.

The partition spanning forest problem for points can be solved in time if every color class contains at most three points.

## 3 Color classes with at most five points

In this section we prove the following theorem:

###### Theorem 2.

The partition spanning forest problem is -complete, even if every color class contains at most five points.

The problem is obviously contained in . In order to show the -hardness, we perform a polynomial-time reduction from Planar 3-Satisfiability. In this -hard  special case of 3SAT the input is a 3SAT formula  whose variable–clause graph is planar. We can assume that such a formula is given together with a contact representation  of  . Thus, all variables are represented as horizontal line segments arranged on one line. Each clause  is represented as an E-shape turned by such that the three vertical legs of the E-shape touch precisely the variables contained in . For our reduction, we construct a set of colored points that admits a partition drawing if and only if  is satisfiable.

### Overview.

The wire gadget consists of four color classes; see Figure 3. The points of the red color class and the blue color class are arranged such that the convex hulls of  and  intersect in the two points and . As a consequence, there are exactly two possible configurations for the red and blue spannings trees which can be used in a partition drawing, see Figure 2(a) and Figure 2(b). Either choice uniquely determines the spanning tree of both the green color class and the orange color class , as the edges of the red and blue spanning trees obstruct all other possible green and orange edges. Thus, there are exactly two possible partition drawings of the wire gadget. In particular, these two drawings satisfy the following.

###### Observation 1.

Any partition drawing of the wire gadget either contains (i) the edges and , but not the edges and , see Figure 2(a); or (ii) the edges and , but not the edges and , see Figure 2(b).

These two states (i) and (ii) may be propagated by creating chains of wire gadgets in which the convex hulls of consecutive gadgets intersect in two points as illustrated in Figure 2(c). Consider two consecutive wire gadgets in a chain. By Observation 1, either both gadgets are in state (i) or both gadgets are in state (ii) due to the way their convex hulls intersect. As a consequence, the first gadget of the chain is in state (i) if and only if the last one is in state (i) as well. Chains are flexible structures and turns can easily be implemented by curving a chain. Further, the length of a chain may be adjusted by increasing or decreasing the distance between consecutive wire gadgets.

### Splitting and inverting.

The splitting gadget consists of two color classes (violet) and (purple) whose points are placed between two consecutive wires in a chain, see Figure 4. The functionality of these two color classes is similar to the one of the color classes green and orange in the wire gadget: the state of  and  uniquely determines the spanning tree of both the violet and the purple color class. In particular, the purple tree contains either  or  and the violet tree contains either  or . We may now attach one or two additional wires perpendicular to the chain such that their convex hulls intersect the convex hull of the splitting gadget, see and in Figure 4. The edges incident to  and  in the purple and violet spanning trees allow precisely one state for both  and .

###### Observation 2.

In any drawing of the splitting gadget, the state of the wires  and differs from the state of  and .

In this sense, the splitting gadget does not only split a wire into two wires, it can also be used to flip the state propagated along a chain.

The variable gadget is a horizontal chain to which we attach multiple wires using splitters. The number of wires attached from the top (bottom) matches the number of E-shape legs touching the variable from the top (bottom) in the contact representation  of .

The clause gadget for a clause of three literals  consists of one color class with exactly five vertices . We place , and  inside a wire gadget representing , and , respectively, and we place  and  between those as depicted in Figure 5. We will now show that the gadget is drawable if and only if at least one of  is true. In particular, we can always use an edge to connect  and . We can connect  to  if  is true and we can connect  to  otherwise; similarly, we can connect  to  if  and we can connect  to  otherwise. If , then we can always connect  to . However, if , then we cannot connect  to  or , and we can connect it to  or  only if  or  is true, respectively. Hence, the gadget is not drawable if false. Note that the connection from  to  might intersect the connection from  to . However, we only have to use it if  and ; in this case, we can connect  to  instead of . Thus, the gadget is drawable if and only if at least one of , , and  is true.

### Layout and correctness.

The wires that are attached to the variable gadgets are vertical and, by Observation 2, their state is inverted, so they propagate the negated variable. Hence, if a literal is positive, we have to invert the state of the wire again. Two of the wires are supposed to enter the clause horizontally; for these two, if they correspond to a positive literal, we simply use another splitting gadget to make the wire horizontal. Otherwise, the wire makes a degree turn to become horizontal and to propagate the negated variable. The third wire is supposed to enter the clause gadget vertically, so if its literal is negative, the vertical wire can directly connect to the clause. Otherwise, we use another splitting gadget followed by a degree turn. See Figure 6 for an example of that shows all cases. Since the clause gadgets are drawable if and only if one of their literals is true and since the wires propagate the states of the variable gadgets, the resulting instance is drawable if and only if the planar 3SAT formula  is satisfiable, which proves the correctness of Theorem 2.

## 4 Linear forests for color classes with at most four points

In this section we consider the additional restriction that the spanning forest is a linear forest, that is, each connected component is a path. Note that, if every color class contains at most three points, then every spanning forest is linear, so in this case we can solve the problem in polynomial time. On the other hand, we show that under this additional restriction, the problem is -complete already if every color class contains at most four points.

###### Theorem 3.

The partition spanning linear forest problem is -complete, even if every color class contains at most four points.

### The variable, wire, and inverter gadgets.

The variable gadget consists of one color class, the black color class . Using a second color class, the blue color class , we can enforce that the edge must be drawn in any partition drawing. The classes and are placed in such a way that their convex hulls intersect in two points. In particular, there are two distinct partition drawings for and , corresponding to two truth states and is present in both of them.

The wire gadget consists of four color classes, the red color class and the blue color class , and two black color classes and , see Figure 7. Classes and are placed as in the variable gadget. Class  is a copy of , placed outside the convex hull of and . The point is placed inside the convex hull of but outside the convex hull of . The point is placed inside the convex hull of and and are placed such that the line through them separates the convex hulls of and . Then, either partition drawing on and induces a unique partition drawing of and , where the drawing on is the same as the drawing on .

Placing as a copy of instead of , i.e., with only one point in the convex hull of , we can also turn this gadget into an inverter gadget.

The splitting gadget consists of three variable gadgets , , and , and two additional color classes, the red color class and the blue color class , see Figure 8. The truth assignment on enforces some edges in and to be present, which then uniquely determines the partition drawing on the whole gadget. Note that the truth assignments on  and  are enforced as the negated truth assignment on , so an additional inverter gadget might be needed depending on the required literal.

The OR-gadget consists of three variable gadgets , , and , and two additional color classes, the red color class and the blue color class , see Figure 9. The truth assignments on and enforce some edges in and to be present. It can be seen that the drawing of corresponding to the value true can only be drawn if or  are also drawn corresponding to the value true. In some of these cases, could also be drawn according to the value false, but this does not affect the proof as it is still true that the constructed point set admits a partition drawing if and only if the planar 3SAT formula  is satisfiable.