The study of graph planarity testing and of its variants is at the heart of graph algorithms and of their applications in various domains (see, e.g. [p-pte-13]). Among the most studied variants we recall, for example, upward planarity testing, rectilinear planarity testing, clustered planarity testing, and HV-planarity testing (see, e.g. [br-npcpcep-16, cd-cp-socg05, dlp-hvpac-19, fce-pcg-95, gt-upt-95, gt-ccuprp-01]). This paper studies a problem of graph planarity testing subject to embedding constraints.
In its more general terms, graph planarity with embedding constraints addresses the problem of testing whether a graph admits a planar embedding where the cyclic order of the edges incident to (some of) its vertices is totally or partially fixed. For example, Angelini et al. [adfjkpr-tppeg-15] and Jelínek et al. [jr-kttppeg-13] study the case when the planar embedding of a subgraph of is given as part of the input. Angelini et al. [adfjkpr-tppeg-15] present a linear-time solution to the problem of testing whether admits a planar embedding that extends the given embedding of . Jelínek et al. [jr-kttppeg-13] show that if the planarity test fails, an obstruction taken from a collection of minimal non-planar instances can be produced in polynomial time. A different planarity testing problem with embedding constraints is studied by Dornheim [d-pgtc-02], who considers the case that is given with a distinguished set of cycles and it is specified, for each cycle, that certain edges must lie inside or outside the cycle. He proves NP-completeness in general and describes a polynomial-time solution when the graph is biconnected and any two cycles share at most one vertex. Da Lozzo and Rutter [dr-aafcp-18] give an approximation algorithm for a restricted version of the problem.
The research in this paper is inspired by a seminal work of Gutwenger et al. [gkm-ptoei-08] who study the graph planarity testing problem subject to hierarchical embedding constraints. The hierarchical embedding constraints specify for each vertex of which cyclic orders of the edges incident to are admissible in a constrained planar embedding of . The term “hierarchical” reflects the fact that these constraints describe ordering relationships both between sets of edges incident to a same vertex and, recursively, between edges within a same set. For example, Figure 1 shows a vertex, its incident edges, and a set of hierarchical embedding constraints on these edges. The edges are partitioned into four sets, denoted as , , , and . As shown in Figure 0(a), the embedding constraints allow only two distinct clockwise cyclic orders for these sets: and . Within each set, the edges of , , and can be arbitrarily permuted with one another, while the edges of are partitioned into two subsets and such that precedes in the clockwise order around the vertex. Also, the edges of can be arbitrarily permuted while the edges of have only two possible orders that are the reverse of one another.
Hierarchical embedding constraints can be conveniently encoded by using FPQ-trees, a variant of PQ-trees that includes F-nodes in addition to P- and to Q-nodes. An F-node encodes a permutation that cannot be reversed. For example, the hierarchical embedding constraints of Figure 0(a) can be represented by two FPQ-trees called and in Figure 0(b). In the figure, F-nodes are depicted as shaded boxes, Q-nodes as white boxes, and P-nodes as circles. The leaves of and are the elements of , , , , and .
Gutwenger et al. [gkm-ptoei-08] study the planarity testing problem with hierarchical embedding constraints by allowing at most one FPQ-tree per vertex. In this paper we generalize their study and allow more than one FPQ-tree associated with each vertex. Besides being interesting on its own right, this generalization can be used to model and study other graph planarity testing problems. As a proof of concept, we apply our results to the study of NodeTrix planarity testing of clustered graphs.
NodeTrix representations have been introduced to visually explore flat clustered graphs by Henry et al. [hfm-dhvsn-07] in one of the most cited papers of the InfoVis conference [citevis]. See also [bbdlpp-valg-11, ddfp-cnrcg-jgaa-17, dlpt-ntptsc-17, hfm-dhvsn-07]. A flat clustered graph is a graph whose vertex set is partitioned into subsets called clusters. A NodeTrix representation of represents its clusters as adjacency matrices, while the edges connecting different matrices are represented as simple curves (see for example Figure LABEL:fi:intro in Section LABEL:se:nodetrix). The NodeTrix planarity testing problem asks whether admits a NodeTrix representation without edge crossings. The question can be asked both in the “fixed sides” scenario and in the “free sides” scenario. The fixed sides scenario specifies, for each edge connecting two matrices and , the sides (Top, Bottom, Left, Right) of and to which must be incident; in the free sides scenario the testing algorithm can choose the sides to which is incident. NodeTrix planarity testing is known to be NP-complete in both scenarios [ddfp-cnrcg-jgaa-17, dlpt-ntptsc-17]. Our main results are the following.
We show that FPQ-Choosable Planarity Testing is NP-complete even if the number of FPQ-trees associated with each vertex is bounded by a constant. This contrasts with the result of Gutwenger et al. [gkm-ptoei-08] who prove that FPQ-Choosable Planarity Testing can be solved in linear time when each vertex is equipped with at most one FPQ-tree. We also prove that FPQ-Choosable Planarity Testing remains NP-complete even if the FPQ-trees associated with the vertices only contain P-nodes.
Since FPQ-Choosable Planarity Testing is NP-complete for sets of FPQ-trees each having bounded size, it makes sense to investigate under which conditions these instances of the problem become tractable. We prove that FPQ-Choosable Planarity Testing can be solved in polynomial time for graphs of bounded branchwidth if the number of FPQ-trees associated with each vertex is bounded by a constant.
We show that there is a strict interplay between the FPQ-Choosable Planarity Testing problem and the problem of testing whether a flat clustered graph is NodeTrix planar. As a result, we prove that NodeTrix planarity testing with fixed sides is fixed-parameter tractable when parameterized by the size of the clusters of and by the tree-width of the multi-graph obtained by collapsing the clusters of to single vertices. If we consider the vertex degree of as an additional parameter, the fixed-parameter tractability immediately extends to NodeTrix planarity testing with free sides.
From a technical point of view, our algorithmic approach is based on a combined usage of different data structures, namely the SPQR-trees [dt-olpt-96], the FPQ-trees, and the sphere-cut decomposition trees [dpbf-eeapg-10, gt-obdpg-08, st-crr-94] of the input graph. Also, it may be worth recalling that a polynomial-time solution for NodeTrix planarity testing with fixed sides is known only when the tree-width of the graph obtained by collapsing the clusters to single vertices is 2 [dlpt-ntptsc-17].
The rest of the paper is organized as follows. Section 2 reports preliminary definitions. Section 3 introduces the FPQ-Choosable Planarity Testing problem, Section 4 shows the NP-completeness of FPQ-Choosable Planarity Testing, in Section 5 we describe a fixed-parameter tractability approach for FPQ-Choosable Planarity Testing, and in Section LABEL:se:nodetrix we analyze the interplay between FPQ-Choosable Planarity Testing and NodeTrix Planarity testing. Open problems are given in Section 6.
We assume familiarity with graph theory and algorithms, and we only briefly recall some of the basic concepts that will be used extensively in the rest of the paper (see also [arumugam2016handbook, dett-gd-99]).
A PQ-tree is a tree-based data structure that represents a family of permutations on a set of elements [bl-tcopiggpupa-76]. In a PQ-tree, each element is represented by one of the leaf nodes, and each non-leaf node is a P-node or a Q-node. The children of a P-node can be permuted arbitrarily, while the order of the children of a Q-node is fixed up to reversal. Given a graph together with a fixed combinatorial embedding, we can associate with each vertex a PQ-tree whose leaves represent the edges incident to , so that represents a set of cyclic orders of the edges around . An FPQ-tree is a PQ-tree where, for some of the Q-nodes, the reversal of the permutation described by their children is not allowed. To distinguish these Q-nodes from the regular Q-nodes, we call them F-nodes. It may be worth recalling that Gutwenger et al. [gkm-ptoei-08] call this data structure “embedding constraint”, and that their “gc-nodes” correspond to P-nodes, “mc-nodes” to Q-nodes, and “oc-nodes” to F-nodes.
Let be a biconnected planar graph. An SPQR-decomposition of describes the structure of in terms of its triconnected components by means of a tree called the SPQR-decomposition tree, and denoted as (see, e.g. [dett-gd-99, dt-olpt-96]). Tree can be computed in linear time and it has three types of nodes that correspond to different arrangements of the components of . If the components are arranged in a cycle, they correspond to an S-node of ; if they share two vertices and are arranged in parallel, they correspond to a P-node of ; if they are arranged in a triconnected graph, they correspond to an R-node of . The leaves of are Q-nodes, and each of them corresponds to an edge of . To simplify the description and without loss of generality, we shall assume that every S-node of has exactly two children. Tree encodes all possible planar combinatorial embeddings of . Figure 2 shows an example of SPQR-tree decomposition of a graph. For each node of , the skeleton of is an auxiliary graph that represents the arrangement of the triconnected components of corresponding to , and it is denoted by . Each edge of that is not a Q-node of is called a virtual edge, and the end-points of a (possibly virtual) edge are called poles. Every virtual edge corresponds to a subgraph of called the pertinent graph, that is denoted by . Note that the planar combinatorial embeddings that are given by the SPQR-decomposition tree of a biconnected graph give constraints on the cyclic order of edges around each vertex of . These constraints can be encoded by associating a PQ-tree to each vertex of , called the embedding tree of and denoted as (see, e.g. [br-spoace-16]).
3 The FPQ-choosable Planarity Testing Problem
Let be a graph, let , and let be an FPQ-tree whose leaf set is , i.e., the set of the edges incident to . Given a planar embedding of , we denote by the cyclic order of edges incident to . We define as the set of planar embeddings of such that the cyclic order of the edges incident to is represented by the FPQ-tree .
An FPQ-choosable graph is a pair where is a (multi-)graph, and is a mapping that associates each vertex with a set of FPQ-trees whose leaf set is . An assignment is a function that assigns to each vertex an FPQ-tree in . We say that is compatible with if there exists a planar embedding of such that for all . In this case, we also say that is consistent with .
An FPQ-choosable graph is FPQ-choosable planar if there exists an assignment of FPQ-trees that is compatible with . Figure 3 shows an FPQ-choosable planar graph , whose vertices are equipped with the following sets of FPQ-trees: , , , and . Figure 2(a) shows an embedding consistent with an assignment that is compatible with ; in Figure 2(b), there is no planar embedding that is consistent with the shown assignment.
The FPQ-Choosable Planarity Testing problem receives as input an FPQ-choosable graph and it asks whether is FPQ-choosable planar, i.e., it asks whether there exists an assignment that is compatible with . In the rest of the paper we are going to assume that is a biconnected graph. Clearly must be planar or else the problem becomes trivial. Also, any assignment that is compatible with must define a planar embedding of among those described by an SPQR-decomposition tree of .
Therefore, a preliminary step for an algorithm that tests whether is FPQ-choosable planar is to intersect each FPQ-tree with the embedding tree of , so that the cyclic order of the edges incident to satisfies both the constraints given by and the ones given by . (See, e.g., [br-spoace-16] for details about the operation of intersection between two PQ-trees, whose extension to the case of FPQ-trees is straightforward). Therefore, from now on we shall assume that the FPQ-trees of have been intersected with the corresponding embedding trees and, for ease of notation, we shall still denote with the set of FPQ-trees associated with and resulting from the intersection. We also remove the null-tree, which represents the empty set of permutations, from the sets . Clearly, a necessary condition for the FPQ-choosable planarity of is that is not the empty set for every .
4 Complexity of FPQ-choosable Planarity Testing
Gutwenger et al. [gkm-ptoei-08] show that the FPQ-Choosable Planarity Testing problem can be solved in time for an FPQ-choosable graph such that for every vertex of . As shown by the following theorem, in its generality the problem is NP-complete even if is such that is bounded by a constant for every vertex , and even if consists of FPQ-trees having only P-nodes.
 FPQ-Choosable Planarity Testing is NP-complete even if the number of FPQ-trees associated with each vertex is bounded by a constant, and even if these FPQ-trees have only P-nodes.
We denote with the number of vertices of the input graph and we assume that for each vertex of the input, . We generate all possible assignments by performing non-deterministic guess operations and, for each assignment, we decide whether it is compatible with the input graph by applying the linear-time algorithm of Gutwenger et al. [gkm-ptoei-08]. It follows that FPQ-Choosable Planarity Testing is in NP.
In order to show that FPQ-Choosable Planarity Testing is NP-hard, we use a reduction from the problem of deciding whether a triconnected cubic graph admits a -edge-coloring. The -edge-coloring problem for a cubic graph asks whether it is possible to assign a color in the set to each edge of the graph so that no two edges of the same color share a vertex. The problem is known to be NP-complete for triconnected cubic graphs [h-npcec-81]. To this aim, for any given triconnected cubic graph we construct an FPQ-choosable graph that is FPQ-choosable planar if and only if has a -edge-coloring. Since every vertex of is equipped with at most six FPQ-trees, the statement will follow.
The construction that maps any triconnected cubic graph into an FPQ-choosable graph is as follows. Each vertex of is associated with a vertex in , and each edge of is associated in with three parallel paths of arbitrary length , , and , which connect vertices and in (by parallel paths we mean that no two such paths share a vertex except and ). See for example Figure 3(a) and 3(b). Note that every vertex of has either degree or degree . Each vertex of having degree is equipped with one FPQ-tree consisting of an F-node and whose leaves represent the two edges incident to . Each vertex of having degree is equipped with a set of FPQ-trees. Each FPQ-tree in consists of a P-node connected to three Q-nodes , , and , which have three leaves each, denoted as , , . See for example Figure 3(c), that shows an FPQ-tree of the vertex in Figure 3(b).
Observe that every FPQ-tree in can be defined as the union of three trees , , and , such that each consists of node , node , and the three leaves of (). For example, , , and are highlighted in Figure 3(c). Consider a Q-node and the cyclic order of its incident edges in . If the leaves of appear as , , in , we say that has a red configuration; if they appear as , , , we say that has a green configuration; if they appear as , , , we say that has a blue configuration. For example, in Figure 3(c) has a red configuration, has a green configuration, and has a blue configuration.
Let , , and be the three edges incident to a vertex in the triconnected cubic graph and let be its corresponding vertex in . For each -edge-coloring of , there is a bijection between an FPQ-tree in and the colors of the three edges incident to . Namely, for a -edge-coloring of where is red, we impose a red configuration to in ; if is green, we impose a green configuration to ; if is blue, we impose a blue configuration to . We say that matches the color of and that matches the color of the edges incident to . For example, the FPQ-tree of Figure 3(c) matches the color of the edges incident to in Figure 3(a), because matches the color of , matches the color of and matches the color of . Since there are six possible permutations of the three colors around in , we have that in .
We now prove that if admits a -edge-coloring, is FPQ-choosable planar. Let be any vertex of with incident edges , , , and let be the vertex that corresponds to in . We define an assignment for where is the FPQ-tree that matches the color of the edges incident to . For every vertex of of degree , is the only FPQ-tree associated with . We show that there exists a planar embedding of that is consistent with . Each edge of has an end-point of degree and an end-point of degree . Since consists of an F-node with two incident edges representing the edges incident to in , the cyclic order of the edges around is fixed. Every vertex of degree belongs to one of three parallel paths connecting the same pair and of two vertices of degree in . Since matches the color of the edges incident to in and matches the color of the edges incident to in , the leaves of and the leaves of that represent the edges of the three paths can be ordered so to avoid edge crossings. If, for example, edge is red in , we have that has a subtree and has a subtree such that both and match the red color. and have the same set of leaves and they appear in reverse order around and around in a planar embedding of . It follows that if admits a -edge-coloring, is FPQ-choosable planar.
Suppose for a converse that is FPQ-choosable planar. There exists an assignment that is compatible with . Assignment defines the cyclic order of the edges incident to each vertex in a planar embedding of . Recall that for any two vertices and having degree , they are connected by three parallel paths , , and , where is the edge of in a bijection with these three paths. Since is compatible with , the two FPQ-trees and both contain two subtrees and such that: (i) and have the same set of three leaves; (ii) these three leaves represent edges of that belong to , , and ; (iii) and have the same red (green, blue) configuration. We color the edges of , , and with the red (green, blue) color depending on the color configuration of and of . By iterating this procedure over all triplets of paths we have that around every vertex of degree in there are three consecutive triplets of edges such that the edges of each triplet all have the same color and no two triplets have the same color. A -edge-coloring of is therefore obtained by giving every edge of the same color as the one of the corresponding triplet , , and in . It follows that if is FPQ-choosable planar then has a -edge-coloring.
In order to prove that the problem remains NP-complete if the FPQ-trees associated with the vertices have only P-nodes, we construct an FPQ-choosable graph in a slightly different way from the one described above. In particular, each edge of is associated with six parallel paths of arbitrary length in , and each vertex having degree in is equipped with six FPQ-trees as the one in Figure 5. Note that in the previous construction we equipped each vertex of degree in with an FPQ-tree consisting of an F-node, but we can obtain the same behavior for its two leaves by replacing the F-node with a P-node. ∎
Theorem 4 naturally raises the question about which families of FPQ-choosable graphs other than those studied by Gutwenger et al. admit a polynomial-time solution for the FPQ-Choosable Planarity Testing problem. The next section proves that any FPQ-choosable graph such that has bounded branchwidth and is bounded by a constant for each vertex can be tested for FPQ-choosable planarity in polynomial time.
5 FPQ-choosable Planar Graphs with Bounded Branchwidth
This section is organized as follows. We first introduce the notions of boundaries and of extensible orders, and state two technical lemmas. Next, we define the concepts of pertinent FPQ-tree, skeletal FPQ-tree and admissible tuple, which are fundamental in the algorithm description. Finally, we present a polynomial-time testing algorithm for FPQ-choosable graphs having bounded branchwidth and such that the number of FPQ-trees associated with each vertex is bounded by a constant.
Boundaries and Extensible Orders: Let be an FPQ-tree, let denote the set of its leaves, and let be a proper subset of . We denote by a cyclic order of the leaves of an FPQ-tree, and we say that if the FPQ-tree represents . We say that is a consecutive set if the leaves in are consecutive in every cyclic order represented by . Let be an edge of , and let and be the two subtrees obtained by removing from . If either or are a subset of a consecutive set , then we say that is a split edge of . The subtree that contains the leaves in is the split subtree of . A split edge is maximal if there exists no split edge such that the split subtree of contains .
 Let be an FPQ-tree, a consecutive proper subset of , and the set of maximal split edges of . Then either , or and there exists a Q-node of such that has degree at least and the elements of appear consecutive around .
Assume that . Let and be two maximal split edges of , and let and be the split subtrees of and , respectively. Let further denote the endpoint of that is not in . The endpoint is defined likewise. Refer to Figure 6 for an illustration.
Suppose for the sake of contradiction that and are distinct. Let denote the first edge on the path from to . By the maximality of and , the edge is not a split edge. It follows that there is an edge incident to that is different from and that is not a split edge. Likewise, we find an edge incident to that is different from the first edge on the path from to and that is not a split edge. But then is an edge of a tree such that one of the two subtrees it separates has leaves in and leaves that are not in . It follows that is not a consecutive set. This is a contradiction to the assumption that and are distinct.
It follows that the edges in are all incident to a single vertex . If has degree , then is not a proper subset of the leaves, and if it has degree , then also its remaining edge is a split edge, which contradicts the maximality of the split edges in . Hence . If were a P-node, this would contradict the assumption that is a consecutive set. ∎
If , the split edge in is called the boundary of L. If , the Q-node defined in the statement of Lemma 5 is the boundary of . Figure 6(a) shows an FPQ-choosable graph and two FPQ-trees and . The three red edges , , and of define a consecutive set in ; the edges and define a consecutive set in . The boundary of in is a Q-node, while the boundary of in is an edge. We denote as the boundary of a set of leaves . If is a Q-node, we associate with a default orientation (i.e., a flip) that arbitrarily defines one of the two possible permutations of its children. We call this default orientation the clockwise orientation of . The other possible permutation of the children of corresponds to the counter-clockwise orientation.
Let , where is a new element. Let , and let be a cyclic order obtained from by replacing the elements of the consecutive set by the single element . We say that a cyclic order of is extensible if there exists a cyclic order with . In this case, we say that is an extension of . Note that if the boundary of is a Q-node , then any two extensions of induce the same clockwise or counter-clockwise orientation of the edges incident to . An extensible order is clockwise if the orientation of is clockwise; is counter-clockwise otherwise. If the boundary of is an edge, we consider any extensible order as both clockwise and counter-clockwise.
Let and be two disjoint consecutive sets of leaves that have the same boundary Q-node in . Let and be two extensible orders of and , respectively. We say that and are incompatible if one of them is clockwise and the other one is counter-clockwise.
 Let be an FPQ-tree, a partition of into consecutive sets, and extensible orders of . There exists an order of represented by such that if and only if no pair is incompatible.
The only-if direction is clear. For the if-direction, assume that no pair is incompatible. Note that, since is consecutive, so is . We denote by the subtree of that is obtained by replacing the consecutive set by a single leaf . Note that () is a subtree of and the set forms a partition of the edges of . Observe that defines a cyclic order of the edges around each node of . Moreover, if and overlap, then they do so in the boundary of and , which must hence be a Q-node . Since no pair is incompatible, it follows that they induce the same cyclic order of the edges around . Thus, together the determine a unique order in such that . ∎
Pertinent FPQ-trees, Skeletal FPQ-trees, and Admissible Tuples: Let be an FPQ-choosable graph, let be an SPQR-decomposition tree of and let be a pole of a node of , let be an FPQ-tree associated with , let be the set of edges that are incident to and not contained in , and let . Note that there is a bijection between the edges of and the leaves of , hence we shall refer to the set of leaves of as . Also note that is represented by a consecutive set of leaves in , because in every planar embedding of the edges must appear consecutively in the cyclic order of the edges incident to .
The pertinent FPQ-tree of , denoted as , is the FPQ-tree obtained from by replacing the consecutive set with a single leaf . Informally, the pertinent FPQ-tree of describes the hierarchical embedding constraints for the pole within the pertinent graph . For example, in Figure 6(b) a pertinent graph with poles and is highlighted by a shaded region; the pertinent FPQ-tree of and the pertinent FPQ-tree of are obtained by the FPQ-trees and of Figure 6(a).
Let be the children of in . Observe that the edges of each () form a consecutive set of leaves of . The skeletal FPQ-tree of , denoted by , is the tree obtained from by replacing each of the consecutive sets () by a single leaf . See for example, Figure 6(c). Observe that each Q-node of corresponds to a Q-node of , and thus to a Q-node of ; also, distinct Q-nodes of correspond to distinct Q-nodes of , and thus to distinct Q-nodes of . For each Q-node of that is a boundary of or of one of its children , there is a corresponding Q-node in that inherits its default orientation from .
Let be an FPQ-choosable graph, let be an SPQR-decomposition tree of , let be a node of , and let and be the poles of . We denote with the FPQ-choosable graph consisting of the pertinent graph and the set that is defined as follows: for each vertex of that is not a pole, and if is a pole of . A tuple is admissible for if there exists an assignment of and a planar embedding of consistent with such that , , is clockwise (counter-clockwise) in if (), and is clockwise (counter-clockwise) in if (). We say that a tuple is admissible for if it is admissible for . We denote by the set of admissible tuples for .
FPT Algorithm: In order to test if is FPQ-choosable planar, we root the SPQR-decomposition tree at an arbitrary Q-node and we visit from the leaves to the root. At each step of the visit, we equip the currently visited node with the set . If we encounter a node such that , we return that is not FPQ-choosable planar; otherwise the planarity test returns an affirmative answer. If the currently visited node is a leaf of , we set , because its pertinent graph is a single edge. If is an internal node, is computed from the sets of admissible tuples of the children of . The next lemmas describe how to compute depending on whether is an S-, P-, or R-node.
 Let be an S-node with children and . Given and , the set can be computed in time, where .
Let and be the poles of , and let be the pole in common between and . We show that if and only if there exist a tree and an , such that and .
If , then there exist an assignment of and a planar embedding of consistent with such that , , is clockwise (counter-clockwise) in if (), and is clockwise (counter-clockwise) in if (). Let and be the embeddings of and induced by , respectively, and let . Observe that and are disjoint consecutive sets of sharing the same boundary in . Also, observe that is an extension of both and . By Lemma 7, and are not incompatible, and hence and are both clockwise or both counter-clockwise. We set if they are both clockwise, and otherwise. For every vertex of different from , we set ; for we set . Since is consistent with and , is clockwise (counter-clockwise) in if (if ). By observing that is clockwise (counter-clockwise) if (if ), we have that . The same argument can be used to show that . It follows that if , there exist a tree and an such that and .
For the converse, assume that there exist a tree and an , such that and . By definition, there exist assignments and of and respectively, and two planar embeddings and that are consistent with and respectively, such that , , is clockwise (counter-clockwise) in if (), is clockwise (counter-clockwise) in if (), , , is clockwise (counter-clockwise) in if (), and is clockwise (counter-clockwise) in if (). We define an assignment and a planar embedding of consistent with such that , , is clockwise (counter-clockwise) in if (), and is clockwise (counter-clockwise) in if (). Embedding of is obtained by merging and as follows. For every vertex of different from , we set , for every vertex of different from , we set . For , since has the same value in and in , hence and are not incompatible. By Lemma 7, there exists an order of the leaves of that is an extension of both and : Let be this order. Assignment for is defined as follows. For every vertex of different from , we set ; for every vertex of different from , we set ; for we set . Since is consistent with , , and , is clockwise (counter-clockwise) in if (if ), and is clockwise (counter-clockwise) in if . Furthermore, since and , and . It follows that if there exist a tree and an such that and , then .
Set is computed from and by looking for pairs of tuples , sharing the same and the same value of . By ordering and , is computed in time. ∎
 Let be a P-node with children . Given , the set can be computed in time, where .
Namely, consists of an F-node connected to P-nodes representing the vertices of ; see, e.g., Figure 7(b). These P-nodes around appear in the clockwise order that is defined by , namely