C-Planarity of Overlapping Clusterings Including Unions of Two Partitions

We show that clustered planarity with overlapping clusters as introduced by Didimo et al. can be solved in polynomial time if each cluster induces a connected subgraph. It can be solved in linear time if the set of clusters is the union of two partitions of the vertex set such that, for each cluster, both the cluster and its complement, induce connected subgraphs. Clustered planarity with overlapping clusters is NP-complete, even if restricted to instances where the underlying graph is 2-connected, the set of clusters is the union of two partitions and each cluster contains at most two connected components while their complements contain at most three connected components.


Introduction
An (overlapping) clustered graph (G = (V, E), C) consists of an undirected graph G and a set C of clusters, i.e., of subsets of the vertex set V . A vertex may be contained in several clusters. Moreover, clusters may overlap, i.e., there might be C 1 , C 2 ∈ C with C 1 ∩ C 2 = ∅, C 1 ⊆ C 2 , and C 2 ⊆ C 1 . Didimo et al. [14] defined planarity for overlapping clustered graphs geometrically: An overlapping clustered graph (G = (V, E), C) is clustered planar if the vertices can be represented by distinct points, each edge e ∈ E by a curve R(e), and each cluster C ∈ C by a simple closed region R(C) in the plane such that for X, Y ∈ E ∪ C we have that (i) X ⊂ R(X), (V \ X) ∩ R(X) = ∅, (ii) R(X) ⊆ R(Y ) if X ⊆ Y , and (iii) every connected region of R(X) ∩ R(Y ) contains a vertex. E.g., the clustered graph in Fig. 1a is clustered planar while the clustered graph in Fig. 1b is not.
Clustered planarity is NP-complete in general as shown in [17], where the case with E = ∅ is examined. In [14], it was posed as an open question whether clustered planarity is polynomialtime solvable for overlapping clustered graphs if each cluster induces a connected subgraph. We will answer this question in the affirmative.
If the clustering is hierarchical, i.e., if any two clusters in C are either disjoint or one is contained in the other then clustered planarity is the classical problem of c-planarity as considered in [15]. One of the most important open problems in the field of Graph Drawing is the complexity of c-planarity of hierarchically clustered graphs. An overview on the classical c-planarity problem can be found in [11,19,5]. Dahlhaus [12] and later Cortese et al. [11] showed, that c-planarity of hierarchically clustered graphs can be solved in linear time if each cluster induces a connected subgraph. Their approaches make use of the decomposition of the graph into 3-connected components as represented by BC-and SPQR-trees.
Angelini et al. [1] defined drawings with region-region crossings of hierarchically clustered graphs. These are essentially representations by points and regions such that all conditions of clustered planarity are fulfilled except for Condition (iii) when X and Y are both clusters.  E.g., Fig. 1b shows a drawing of a clustered graph with one region-region crossing. Observe that the intersection of the two regions does not contain a vertex as required by the definition of clustered planarity. Angelini et al. [1] showed how to use SPQR-trees to test in polynomial time whether any hierarchically clustered graph with an underlying 2-connected graph has a drawing with region-region crossings.
If E = ∅ then clustered planarity is closely related to the NP-complete problem of hypergraph (vertex) planarity as defined in [17]: Given a set C of subsets of a set V , is there a planar support, i.e., a planar graph G = (V, E) such that each set in C induces a connected subgraph of G. Various subclasses of planar supports that directly imply clustered planarity -such as trees, cacti, and outerplanar supports -were considered [3,4,7,8,9,18]. Hypergraph planarity remains NP-complete even if C is the union of two partitions [2]. The proof in [2] even shows that clustered planarity remains NP-complete if the underlying graph G is 2-connected, C is the union of two partitions, each cluster contains at most two connected components, and the complement of any cluster at most three connected components.
Contribution: In Sect. 3 we focus on the union of two partitions. We further require that for each cluster, both the cluster itself and its complement are connected. Different from hierarchical clusterings, this connectivity property does not automatically imply clustered planarity in the overlapping case. Yet, for the union of two partitions, we can give a characterization that yields a linear-time testing algorithm. Finally, in Sect. 4 and 5, we show how to use BC-trees, SPQR-trees and the consecutive-ones property to obtain an algorithm for testing clustered planarity of possibly overlapping but connected clusters. The run time of the algorithm is polynomial in |V | and |C|.

Preliminaries
For a subset C ⊆ V of the vertices of an undirected graph G = (V, E), we denote by G[C] the subgraph of G induced by C, i.e. the graph with vertex set C and edge set {e ∈ E; e ⊆ C}. A C-path (C-cycle) is a path (simple cycle) in G [C]. A partition of V is a set P of subsets of V such that each vertex in V is contained in exactly one set in P. For two partitions The connected intersection partition of P B and P R is the partition induced by the connected components of G[C], C ∈ P I .
A consecutive-ones ordering of a binary matrix is a permutation of its columns such that in each row all of the 1s are consecutive, i.e. such that each row is of the form 0 * 1 * 0 * . A binary matrix has the consecutive-ones property if and only if it has a consecutive-ones ordering. It can be tested in linear time whether a binary matrix has the consecutive-ones property and a consecutive-ones ordering can be found in linear time if it exists [6].

Planarity of Overlapping Clustered Graphs
Let (G = (V, E), C) be an overlapping clustered graph. Let (C) = C∈C |C| be the total size of all clusters. The clustered graph (G, C) is c-connected if G[C] is connected for all C ∈ C and c-co-connected if both, G[C] and G[V \ C], are connected for all C ∈ C.
If (G, C) is c-connected then a c-planar embedding of G for C is a planar embedding of G such that V \ C is in the outer face of G[C] for all C ∈ C. A graph G + = (V, E + ) is a c-planar support of a clustered graph (G = (V, E), C) if E ⊆ E + , (G + , C) is c-connected and there is a c-planar embedding of G + for C. A clustered graph is c-planar if and only if it has a c-planar support.
It was shown that a c-connected clustered graph [14] or a hierarchically clustered graph [15], respectively, is clustered planar in the sense of [14] if and only if it has a c-planar support.

BC-Trees
A vertex v is a cut vertex of a connected graph G if the graph that results from G by deleting v and its incident edges is not connected. A connected graph is 2-connected if it contains more than two vertices but no cut vertices. The blocks of a connected graph are the maximal 2-connected subgraphs and the subgraphs induced by bridges. The vertices of the block-cut tree (BC-tree) of a graph G are the blocks and the cut vertices of G. There is an edge in the block-cut tree between a block H and a cut vertex v if v is contained in H.

SPQR-Trees
Two vertices v and w are a separation pair of a 2-connected graph G if the graph that results from G by deleting v and w and their incident edges is not connected. A graph is 3-connected if it contains more than three vertices but no separation pair. An SPQR-tree [13] is a labeled tree that represents the decomposition of a 2-connected graph into 3-connected components. Each node ν of an SPQR-tree is labeled with a multi-graph skel(ν) -called the skeleton of ν. There are four different types of labels with the skeletons: S-nodes for simple cycles, P-nodes for three or more parallel edges, R-nodes for a simple 3-connected graph, and Q-nodes for two parallel edges.
The Q-nodes are the leaves of an SPQR-tree. No two S-nodes, nor two P-nodes are adjacent in an SPQR-tree. For each node ν of an SPQR-tree there is a one-to-one correspondence of the edges of skel(ν) and the edges incident to ν (except for the Q-nodes where one of the two edges of the skeleton corresponds to the only incident edge of the Q-node). The edge of skel(ν) corresponding to the edge {ν, µ} of the SPQR-tree is denoted by e µ . We consider the edges of the skeletons oriented. For simplicity, we assume that the edges of the skeleton of an S-node are oriented as a directed cycle and the edges of the skeleton of a P-node are all oriented in parallel.
We consider the SPQR-tree T rooted at a Q-node r. Let ν be a node of T . The root edge of skel(ν) is the edge that corresponds to the parent edge of ν. The poles of skel(ν) (or node ν, respectively) are the end vertices of the root edge. Let skel − (ν) be the skeleton of ν without the root edge. Each node ν of the rooted SPQR-tree represents a (multi-)graph G r (ν): The Q-nodes (excluding the root) represent a graph with two vertices connected by an edge and additionally by the root edge. Let ν be a non-leaf node of an SPQR-tree and let ν 1 , . . . , ν k be the children of ν. For i = 1, . . . , k, remove the edge associated with {ν, ν i } from both skel(ν) and G r (ν i ). Insert the remaining parts of G r (ν i ) into skel(ν) identifying the poles of G r (ν i ) with its counter parts in skel(ν). The poles of G r (ν) are the poles of ν. Let G − (ν) be G(ν) without the root edge of skel(ν). The edges of G r (r) correspond to the Q-nodes of the SPQR-tree.
Every 2-connected graph is represented by a unique SPQR-tree (up to the choice of the root) and the SPQR-tree of a 2-connected graph can be constructed in linear time [16]. Figure 2: P B contains the two clusters separated by the blue (dashed) curve, P R contains the two clusters separated by the red (dotted) curve. (G, P B ∪ P R ) is c-co-connected and G is planar but (G, P B ∪ P R ) is not c-planar.

Two C-Co-Connected Partitions
In this section we show that c-planarity of a c-co-connected clustered graph can be tested in linear time if the set of clusters is the union of two partitions. Observe that in contrast to the hierarchical case [10], there are c-co-connected clustered graphs with an underlying planar graph that are not c-planar. E.g., the graph G = (V, E) in Fig. 2 is 3-connected and, thus, has a unique embedding up to the choice of the outer face. No matter which face we choose as the outer face, there is always at least one cluster C among the four clusters in P B ∪ P R such that G[C] contains a simple cycle enclosing a vertex in V \ C.
The key for the algorithm is the following characterization.
Theorem 1. Let G = (V, E) be a graph and let P R and P B be two partitions of V such that the clustered graph (G, P R ∪ P B ) is c-co-connected. Let P I be the connected intersection partition of P R and P B . Then (G, P R ∪ P B ) is c-planar if and only if (G, P I ) is c-planar.
Proof. We first show that if (G, P B ∪ P R ) is c-connected and c-planar then (G, P I ) is c-planar : Consider a c-planar embedding of G for P R ∪ P B . Let C ∈ P I , R ∈ P R , and B ∈ P We now show that if (G, P B ∪ P R ) is c-co-connected and (G, P I ) is c-planar then (G, P B ∪ P R ) is c-planar : Let C ∈ P B ∪ P R (squared blue vertices in the drawing). c-co-connected implies that V \ C is contained in one face f of G[C] (shaded area in the drawing). We call C bad if V \ C is contained in an inner face of G[C]. Among all planar embeddings of G that are c-planar for P I choose one that minimizes the number of bad clusters. Assume there is a bad C ∈ P B ∪ P R . We assume without loss of generality that C ∈ P B . We show that this would yield a contradiction to the choice of the embedding.
If C is the union of some clusters in P R , choose a face f 0 of G inside f incident to a vertex of C as the outer face, decreasing the number of bad clusters.
Otherwise, let C ∈ P R intersect C and V \ C. Since G[C ] is connected, E(C ∩ C, C \ C) is not empty. There must even be an edge e ∈ E(C ∩C, C \C) that is in the outer face of G[C ]: Otherwise   Since c-planarity for c-connected hierarchically clustered graphs can be tested in linear time [11], it remains to show that P I can be constructed in linear time. Since connected components can be computed in linear time it suffices to show that the intersection partition P I of two partitions P B = {B 1 , . . . , B B } and P R = {R 1 , . . . , R R } of V can be computed in linear time. We introduce the following data structure: For X ∈ {B, R}, we use a vertex array with X[v] = i for v ∈ X i . We also initialize an array S[1, . . . , λ R ] of stacks, where S[i] will contain the vertices of R i , i = 1, . . . , λ R in the order in which they appear in B 1 , . . . , B λ B . We fill the stacks as follows: For i = 1, . . . , λ B and v ∈ B i , we push v to S[R [v]]. Now, the sets in P I can be obtained by going through the stacks and opening a new set whenever B[v] changes. This concludes the proof of the following theorem: Theorem 2. It can be tested in linear time whether a c-co-connected clustered graph is c-planar if the set of clusters is the union of two partitions of the vertex set.
Observe that if (G, P B ∪ P R ) is only c-connected then (G, P B ∪ P R ) does not have to be c-planar even if (G, P B ), (G, P R ), and (G, P I ) are.
E.g., let G be the graph in Fig. 3a, let P R and P B , respectively, be the partition of the vertex set enclosed by the red dotted and blue dashed curves, respectively. Let P I be the connected intersection partition of P R and P B . The embedding in Fig. 3a is c-planar for P B and P I -see also Fig. 3b+3c. Fig. 3d shows an embedding that is c-planar for P R . However, (G, P B ∪ P R ) is not c-planar: Assume that there would be an embedding that is c-planar for (G, P B ∪ P R ). We use the vertex labeling indicated in Fig 3. Due to cluster {1, 2, 3, 4} the interior of the cycle c R = 1, 2, 3, 4 must be empty. Thus, vertex 5 must be drawn outside c R . Due to the cluster C = {1, 3, 4, 5, 7}, vertex 2 and 6 must not be enclosed by the triangle c B = 1, 4, 5 . It follows that the edges connecting 5 to c R must be drawn such that c B does not enclose c R and that 6 is outside c B . Due to the edge {3, 7}, vertex 7 is not enclosed by c B either. Thus, except for the edge e = {1, 7}, the embedding is as indicated in Fig. 3d. But no matter how we would add e in a planar embedding, we would either create a cycle in G[C] enclosing vertex 2 or vertex 6.  Let T be the SPQR-tree of G rooted at a Q-node r representing the edge e of G. The embeddings of T represent the embeddings of G with e on the outer face. They in turn induce embeddings of the skeletons of all nodes of T with their root edges on the outer face.
Apart from the choice of the root, i.e., the choice of the outer face, the degrees of freedom we have are the order of the parallel components of the graph at the P-nodes, and in which way the R-nodes are flipped.
In the following let C ∈ C be a cluster such that G[C] is connected and let C ext ⊆ C be a subset of vertices that we want to be incident to the outer face of G[C] (we'll need C ext in Sect. 5). We label each node ν in T and its corresponding edge in the skeleton of its predecessor node to capture, which parts of skel(ν) are contained in C. 1 Let s and t be the poles of G r (ν). The node ν is an inside node for C, if G r (ν) is completely contained in C and at most the poles s and t of G r (ν) are in C ext . It is inappropriate if G − r (ν) has no embedding with the poles on the outer face that is c-planar for {C} and is such that C ext is on the outer face of . Node ν is an outside node, if it is not inappropriate and G − r (ν) contains no C-path between its poles. ν is border if ν is neither inside nor outside and G − r (ν) has an embedding with the poles on the outer face that is c-planar for {C} and such that exactly one of the outer s-t-paths contains one or more vertices not in C \ (C ext \ {s, t}). In all other cases ν is double-border. See Fig. 4 for an example with C ext = ∅.
Traversing the SPQR-tree, we can compute for all nodes whether they are inside, outside, border, double-border, or inappropriate for a given cluster C. Let node ν be neither inside nor outside. If ν has an inappropriate child then ν is also inappropriate. In the following, we assume that ν has no inappropriate children. If ν is a P-node it is border if it has no double-border node and at most one border node among its children. It is double-border if it either has no double-border node and exactly two border nodes or exactly one double-border node and neither inside nor border nodes among its children. Otherwise it is inappropriate. If ν is an S-node, it is double-border if it has at least one double-border node as child and border otherwise. If ν is an R-node consider skel − (ν) embedded with the poles s and t on the outer face. ν is inappropriate if there is a simple cycle in skel − (ν) that does not contain outside edges but (a) contains double-border edges or (b) encloses vertices in C ext or non-inside edges. Otherwise, it is double-border if both s-t-paths on the outer face contain vertices in C ext \ {s, t} or non-inside edges. In the remaining cases ν is border. Finally, if ν = r is the root, let e be the edge of G represented by r. If e does not have both end vertices in C then r has the same label as its unique child µ. Otherwise r is border if µ is outer or border and inappropriate otherwise.
An external path of a node ν is a path in G between the poles of G r (ν) that does not contain any other vertices of G r (ν). We label the root edge of skel(ν) inside for C if ν has an external C-path and outside otherwise. We say that an external path p of node ν is to the right (left) of ν with respect to the ordered pair (s, t) of its poles if the cycle that is induced by p in the graph that results from G by contracting G r (ν) is oriented (counter-) clockwise assuming that p was oriented from t to s. Two external paths of ν are on the same side of ν if they are both to the right or both to the left of ν with respect to an arbitrary ordering of the poles of ν. Otherwise, they are on different sides. Lemma 1. Let G = (V, E) be a 2-connected graph, let C ⊂ V be a cluster inducing a connected subgraph of G, let C ext ⊆ C, let T the SPQR-tree of G, and let r be a Q-node of T representing the edge e of G. A planar embedding of G with e on the outer face is c-planar for {C} with C ext incident to the outer face of G[C], if and only if the following conditions are fulfilled for any non-inside node ν of its SPQR-tree T .
1. All external C-paths of ν are embedded on the same side of G r (ν) -which we reflect by the embedding of the root edge of skel(ν).
2. skel(ν) contains no simple cycle of non-outside edges that encloses a non-inside edge or a vertex in C ext .
Proof. Clearly, both conditions must be fulfilled for a c-planar embedding with C ext on the outer face of the cluster. So assume now that both Conditions are fulfilled. Let v ∈ V \(C\C ext ), let e = e be an edge incident to v, and let ν be the Q-node representing e . Assume that G contains a C-cycle c enclosing v. By Condition 1, there is no node ν on the ν -r-path such that c can be decomposed into two external C-paths of ν. So, let ν be the first node on the ν -r-path such that c is contained in G − r (ν) or can be composed by a path in G − r (ν) and an external C-path of ν. Observe that c induces a cycle c in skel(ν) that contains only non-outside edges. Let µ be the child of ν on the ν -ν-path. By the choice of ν it follows that c does not contain the edge e µ of skel(ν). Hence c encloses the edge e µ . However, e µ was either not inside or v ∈ C ext is an end vertex of e µ not in c -contradicting Condition 2.
In the following, we construct a set of binary matrices from an initial embedding of T that have the consecutive-ones property, if and only if there is a c-planar embedding for C with the fixed root edge on the outer face. The total size of the matrices will be in O(|V | (C)).

Modeling by Consecutive-Ones Property
For each possible root r of T that is not inappropriate for any C ∈ C, we start with a fixed embedding of T -including fixed flips of the R-nodes -and perform the following steps:

Splitting T
We split T at each R-node, removing the edges from the R-node to its children from T . Let T r be the subtree containing r. For each former non-leaf child ρ of an R-node ν we attach a new Q-node ρ to ρ . We root the subtree containing ρ at ρ and denote it by T ρ . We label ρ inside for a cluster C, if ρ had an external C-path and outside otherwise. In the parent tree, we replace the R-node ν by a special P-node ν with the same label and three Q-nodes ν 1 , ν 2 , ν 3 in this order as children. If the R-node ν was labeled border for a cluster C, we label ν 2 and exactly one among ν 1 and ν 3 as inside and the other as outside. More precisely, we label ν 1 as outside if and only if the left outer path of skel − (ν) between its poles contains non-inside edges or vertices from C ext . If the R-node ν was labeled double-border, we label ν 1 and ν 3 as border and ν 2 as inside. If the R-node was labeled inside or outside, we label all three children as inside or outside, respectively. We thus end up with a forest containing only S, P, and Q-nodes. (a) (G, C)

Initializing the Matrices
For each root ρ of one of the subtrees, we create a new binary matrix M ρ . A node in T ρ is a lowest-P-child, if it is the child of a P-node and has no other P-nodes in its subtree. The embedding of T ρ induces an ordering of the lowest-P-children from left to right. We initialize M ρ with a column for each lowest-P-child in accordance with the ordering. For a node ν of T ρ , we use c(ν) to refer to the set of its corresponding columns in M ρ , i.e. the columns of the lowest-P-children in ν's subtree. For M r we create one additional external column c(r). For ρ = r, we create two additional external columns, enclosing the rest of the matrix. For each cluster C, one of the two external columns will represent the side of possible external C-paths of the child of ρ and will be denoted by c C (ρ).
We then create a row for each non-leaf node ν, adding 1s in the columns in c(ν) and 0s in all other columns. This ensures that in every permutation of the columns of M ρ for which the 1s are consecutive in all rows, the columns of the lowest-P-children of each node remain adjacent, allowing a reconstruction of an embedding of T ρ from the ordering of the columns in M ρ . See Fig. 5. If ρ = r we add two rows having all 1s except for one 0 in the first or last external column, respectively.
In order to fill the matrix M ρ , we traverse the tree T ρ with a post-order DFS. For each cluster C ∈ C and each examined node we add up to three rows to M ρ . We define for each node ν and each cluster C a set r(ν, C) of relevant rows. For each lowest P-child ν, we set r(ν, C) = ∅. The block B(ν, C) is the submatrix of M ρ with entries in rows r(ν, C) and columns c(ν). When we create rows in M ρ , the default entries are 0 and we explicitly mention when we set the entries to 1.

Handling P-nodes
For a P-node ν with children ν 1 , . . . , ν k we initialize r(ν, C) as r(ν 1 , C) ∪ . . . ∪ r(ν k , C). Due to c-planarity, the children of ν must be permuted such that all inside children are consecutive pre-and succeeded by at most one border child and arbitrary many outside children. 2 Hence, if ν is neither outside nor double-border, we add up to 3 constraint-rows r 0 (ν, C), r 1 (ν, C), and r 2 (ν, C) to r(ν, C). If ν has inside children, we add r 0 (ν, C) with 1s in all columns in c(ν i ) where ν i is an inside child of ν. This ensures that all inside children are placed in consecutive order. If ν has a child µ that is a border node, we add r 1 (ν, C) with 1s in all columns in c(µ) and again with 1s in all columns in c(ν i ) where ν i is an inside child of ν. We do the same for a potential second border node in a third row r 2 (ν, C). This ensures, that the border children are placed next to the inside children, with at most one border child on each side. Finally, let µ be a child of ν let i ∈ r(µ, C) and let j ∈ c(ν) \ c(µ). Then we set the entry in row i and column j to 1, if one or more of the rows in r(ν, C) \ r(µ, C) contain a 1 in the same column. See Fig. 6a.

Handling S-nodes
If an S-node ν with children ν 1 , . . . , ν k is outside then r(ν, C) = ∅, otherwise r(ν, C) = r(ν 1 , C)∪ . . . ∪ r(ν k , C). Assume now that ν is not outside and has an external C-path. Observe that in this case ν cannot be double-border. Otherwise r would be inappropriate for C. If ν has two or more P-nodes as children, we have to make sure that the 1s in each P-node and the 1s in the external path can be made consecutive via additional 1s.
More precisely, let ν 1 , ν 2 . . . , ν k be the children of ν that are P-nodes. The upper half for a cluster C are all entries in rows r(ν i , C), i = 1, . . . , k and columns c(ν i ), i = j + 1, . . . , k while the lower half are all entries in columns c(ν i ), i = 1, . . . , k and rows r(ν i , C), i = j + 1, . . . , k. We fill both, the upper and the lower half with 1s if ν is inside and we fill either the upper or the lower half with 1s if ν is border. See Fig. 6b.
Recall that if ν is not inside then the external C-paths must all be on the same side of G r (ν) in a c-planar drawing of G. However, external C 1 -and C 2 -paths could be on different sides for distinct clusters C 1 and C 2 . Hence, we cannot just always fill the upper half with 1s. To this end, we will define same and different constraints that only depend on the structure of the clustered graph. A same (different) constraint indicates that if there is a c-planar embedding then the external paths must be on the same (different) side. We call a cluster C critical for ν if ν is border with respect to C and has an external C-path.
Let C 1 and C 2 be two clusters that are critical for ν. If ν has an external C 1 -path that is also an external C 2 -path then there is a same constraint between C 1 and C 2 . Otherwise, there is a different constraint between C 1 and C 2 : Assume that there would be an external C 1 -path p 1 and an external C 2 -path p 2 of ν that are on the same side of G r (ν) in a c-planar embedding of G. Since ν is border, there is a C i -path p ν i , i = 1, 2 in G − r (ν). Consider the cycles c i , i = 1, 2 composed by p ν i and p i . By c-planarity, each portion of p 1 that is inside c 2 must be in G[C 2 ] and vice versa. Since p 1 and p 2 are on the same side of G r (ν), there is an external path of ν that contains only edges of p 1 inside c 2 , edges of p 2 inside c 1 and common edges of p 1 and p 2 , i.e., only edges in G[C 1 ∩ C 2 ].
Fix now an arbitrary cluster C that is critical for ν and assign C the upper half. Assign to any other cluster C that is critical for ν the upper half if there is a same constraint between C and C and the lower half otherwise.

External Columns
If ρ = r let ν be the unique child of r and let e be the edge represented by the Q-node r. Then the external column is 1 for each row in r(ν, C) if the cluster C contains both end vertices of e.
If ρ = r then the unique child ρ of ρ was the child of an R-node ν. Consider a fixed embedding of skel − (ν) with its poles s and t on the external face. Let C be a cluster for which ρ is a border node and has an external C-path. We have to make sure that the parts of G − r (ρ ) that are not in C \ C ext are embedded such that they are not enclosed by a C-cycle in G that is composed by an external C-path of ρ and a C-path in G r (ρ ) between its poles s and t .
Consider first that skel − (ν) contains a cycle c containing e ρ and consisting only of nonoutside edges. If c is (counter-)clockwise oriented when traversing e ρ from s to t , then we set c C (ρ) to be the (left) right external column.
Otherwise all external C-paths of ρ must contain an external C-path of ν. Thus, ν is not double-border. Moreover, the set of vertices of skel − (ν) that can be reached from s using only non-outside edges and not e ρ induces an s-t-cut of skel − (ν) that contains e ρ and no other non-outside edges. It follows that e ρ is on the left (right) outer s-t-path and all external C-paths ν are to the left (right) of ν with respect to (s, t) in any c-planar embedding. Hence, if e is on the left (right) outer s-t-path then we set c C (ρ) to be the left (right) external column. In both cases we set the entry in column c C (ρ) to 1 for each row in r(ρ , C).
Clearly the number of columns is linear in the number of Q-nodes and R-nodes and thus linear in |V | for planar graphs. For a cluster C and a P-node ν, we enter up to three rows but at most if both poles are in C. Observe that at least one of the poles of a P-node ν is not a pole of another P-node ν on the path from ν to the root. Hence, the number of rows is bounded by 3 (C).
Applying the next theorem with C ext = ∅ yields a characterization of c-connected overlapping clustered graphs with underlying 2-connected graphs.
Theorem 3. A c-connected overlapping clustered graph (G, C) with an underlying planar 2connected graph G and sets C ext ⊂ C, C ∈ C has a c-planar embedding in which C ext is incident to the outer face of G[C] for any C ∈ C if and only if the root of the SPQR-tree of G can be chosen such that it is not inappropriate for C ∈ C and all matrices M ρ fulfill the consecutive-ones property.
Proof. Let (G, C) be an overlapping clustered graph. Let the SPQR-tree T of G be rooted at the Q-node r, and let e be the edge represented by r.
Assume first that the columns of all matrices M ρ are permuted such that in each row the 1s are consecutive. We may assume without loss of generality that the external columns were not permuted. Starting from ρ = r, we traverse T and do the following at a non-leaf node ν. If ν is a P-node, we permute the children ν 1 , . . . , ν k of ν according to the ordering of c(ν 1 ), . . . , c(ν k ) in the permuted matrix M ρ .
If ν is an R-node, we fixed an embedding of G r (ν) and replaced ν with a P-node and three incident Q-nodes ν 1 , ν 2 , ν 3 in this order. If ν was labeled inside or outside for all clusters Figure 7: The three forbidden cases in the proof of Theorem 3, first direction.
then we maintain the fixed flip of G r (ν). Otherwise the labeling was such that c(ν 2 ) will remain between c(ν 1 ) and c(ν 3 ). We maintain the fixed embedding of G r (ν) if c(ν 1 ) remains before c(ν 3 ) after the permutation and flip G r (ν) otherwise. If we flip G r (ν), we also reverse all matrices for all non-leaf nodes in the subtree rooted at ν that are children of an R-node. Finally, we embed e to the right of G − r (r) if the external column of M r is on the right hand side of M r and to the left otherwise.
We show that this yields a c-planar embedding for C: Let C ∈ C and let ν 1 be a non-inside node of T . We show by induction on the length of the ν 1 -r-path that all external C-paths of ν 1 are on the same side and that no non-inside edge and no vertex in C ext is enclosed by a simple cycle of non-outside edges in skel(ν 1 ) -provided that the root edge of skel(ν) is embedded on the same side as the external C-paths of ν 1 .
First observe that if ν 1 is an R-node then skel − (ν 1 ) does not contain a simple cycle of non-outside edges that encloses a non-inside edge, otherwise ν 1 would be inappropriate. Let e 0 be a non-inside edge of skel(ν 1 ) or let v 0 ∈ C ext be a vertex of skel(ν 1 ) other than the poles and let e 0 be an edge of skel(ν 1 ) incident to v 0 . Let ν 0 be the child of ν 1 corresponding to e 0 . Let p 1 and p 2 be two paths in G[C] with one of the following properties (see Fig. 7 for an illustration): (a) ν 1 is a P-node and there are two children µ 1 = ν 0 = µ 2 of ν 1 such that p j , j = 1, 2 is a path in G − r (µ j ) between its poles, or (b) p 1 is a path in G − r (ν 1 ) between its poles that intersects G r (ν 0 ) at most in its poles and p 2 is an external C-path of ν 1 , or (c) p 1 and p 2 are both external C-paths of ν 1 . We have to prove that the cycle composed by p 1 and p 2 does not enclose G r (ν 0 ).
Let ν 1 , . . . , ν = r be the ν 1 -r-path. Let j ∈ {1, 2}. If p j in G − (ν 1 ) let i j = 1. Otherwise let 2 ≤ i j ≤ be minimum such that ν ij is an R-node or G − r (ν ij ) contains p j . We may assume that i 1 ≤ i 2 . If ν ij is an R-node, we actually redefine ν ij to be the root ρ of the tree containing ν ij −1 : we replace p j by the respective path in G r (ν ij −1 ) through the root edge e ρ of skel(ν ij −1 ). If ν 1 was an R-node we redefine ν 1 to be the special P-node with which we replaced the R-node and we redefine ν 0 to be one of the artificial non-inside Q-nodes we appended to ν 1 .
Observe that ν ij is either ρ or a P-node and p j is composed by two C-paths p 1 j and p 2 j connecting the poles of G r (ν 1 ) with the poles of G r (ν ij ) and a middle C-path p j . p 1 j and p 2 j are empty if i j = 1. p j consists of the edge e ρ if ν ij = ρ. If ν ij is a P-node then it has a non-outside child µ j = ν ij −1 such that p j is a path in G − r (µ j ) between its poles. We distinguish some cases. (1) If ν i1 = ρ or if ν i1 = ν i2 = ρ and µ 1 = µ 2 then p 1 and p 2 are trivially on the same side of G r (ν 1 ). (2) Assume that ν i1 = ν i2 = ρ and µ 1 = µ 2 . Since the 1s are consecutive in the rows inserted for ν ij the two non-outside children µ 1 and µ 2 must be on the same side of the non-inside child ν ij −1 . (3) Otherwise, observe that the C-paths p 1 2 and p 2 2 connecting the poles of G r (ν) with the poles of G r (ν i2 ) must contain the poles of G r (ν k ), k = 1, . . . , i 2 . This implies especially that for each k = i 1 , . . . , i 2 the graphs G − r (ν k ) contain a C-path connecting their poles: such a C-path can be composed by p 1 and portions of p 1 2 and p 2 2 . Hence, ν k , k = i 1 , . . . , i 2 is not outside. Further a subpath of p 2 is an external C-path of ν i1 . Hence, ν i1 cannot be double-border, since otherwise the root would be inappropriate  for C.
Since ν i1−1 is non-inside and ν µ1 is border or inside there is a row κ inserted for ν i1 that contains only 0s in c(ν i1−1 ) and only 1s in c(µ 1 ). Further, when we handled ν i2 , we added 1s in the row κ and the external column (if ν i2 = r) or the columns c(µ 2 ) (otherwise). Hence, since the 1s must be consecutive in κ, it follows that c(ν i1−1 ) cannot be between c(µ 1 ) and the external column c C (ρ) or c(µ 2 ), respectively. Hence, p 1 and p 2 must be on the same side of G r (ν 0 ). Now, if ν i2 = ρ we are done. Otherwise let ν be the parent R-node of ν i2−1 in T . By induction, we already know that all external C-paths of ν are on the same side and that e νi 2 −1 is not enclosed by a simple cycle of non-outside edges in skel(ν). Hence, the external C-paths of ν i2−1 are all on the same side and by construction this is represented by the external column c C (ρ).
Assume now that a c-planar embedding with e on the outer face is given in which C ext is on the outer face of G[C] for every cluster C. This yields a permutation of the children of the P -nodes of T and flips of the R-nodes. Permute the columns of the matrices accordingly. Let ρ be the root of a split off tree T ρ and let ρ be the only child of ρ in T ρ . The external columns of M ρ are exchanged if on the ρ -r-path there are an odd number of R-nodes that are flipped.
Recall that we have inserted up to three rows for each P-node and each cluster and no other rows into the matrices. Let ν be a P-node in a subtree T ρ and let C be a cluster such that we have created a row κ for ν and C in M ρ . Then ν has no double-border child. Due to c-planarity and the condition on all C ext , the children of ν must be permuted such that all inside children are consecutive pre-and succeeded by at most one border child and arbitrary many outside children. It follows that the 1s in columns c(ν) must be consecutive.
Let ν = ν 1 , . . . , ν = ρ be the path from ν to the root of T ρ , and let 1 < k ≤ be maximum such that ν 1 , . . . , ν k are not outside. If ν 1 was not a special P -node substituting an R-node then ν i is a P-node if i is odd and an S-node if i is even. (Otherwise it might be vice versa, but the situation is similar) ν k is a P-node if ν k = ρ. Also observe that c(ν i−1 ) ⊆ c(ν i ), i = 2, . . . , and that for each i = 1, . . . , the columns in c(ν i ) are consecutive in the permuted matrix. If k < , we've set r(ν k+1 , C) = ∅. Hence, the entries in row κ are 0 in all columns in : Possible ordering of the 0s and 1s in a row inserted for a P-node ν 1 according to a c-planar embedding.
We consider first a P-node ν i , i = 3, . . . , k odd. Since ν i−1 is not outside it follows that no child of ν i other than ν i−1 can be double-border. Hence, for each non-outside child µ = ν i−1 of ν i there are 1s in row κ and all columns in c(µ). Observe that due to c-planarity the nonoutside children of ν i are consecutive. Moreover, if there are both, non-outside children of ν i to the right and the left of ν i−1 then ν i−1 is inside and, thus, all columns in c(ν 1 ) as well as c(ν j ) \ c(ν j−1 ) have entry 1 in row κ for all 3 ≤ j < i odd.
If ν k = ρ, let m = k = and assume that the external Cpaths of ν −1 are all to the right (left) of ν −1 , i.e., the column c C (ρ) is the right (left) external column. If ν k = ρ, let m ≤ k be maximum such that ν m is a P-node and has a non-outside child other than ν m−1 (If no such P-node exists then all entries in row κ other than in the columns c(ν) are zero and thus all 1s are consecutive.) Assume that ν m has a non-outside child µ to the right (left) of ν m−1 . Assume now that there is a 1 ≤ j < m odd such that the P-node ν j has a child µ to the right (left) of ν j−1 . I.e., the columns c(µ ) are between the columns c(ν) and c(µ). If µ were not inside then G r (µ ) would contain a vertex in V \ (C \ C ext ) that would be enclosed by a C-cycle composed by the following four paths: S-node P-node P-node or ρ P-node P-node non-outside nodes µ µ ν j ν m in G − r (ν j−1 ) between its poles, (2+3) two C-paths connecting the poles of G r (ν m−1 ) with the poles of G r (ν j ), and (4) either an external C-path of ν −1 , if ν m = ρ or a C-path in G r (µ) between its poles, if ν m is a P-node. Hence, the entries in c(µ ) are all 1.
Consider now an S-node ν i , i = 2, . . . , k even that has an external C-path. By the choice of k, ν i is not outside. Since the root is not inappropriate, ν i is not double-border. Thus, we've set the entries in row κ and columns c(ν i ) \ c(ν i−1 ) to 1 if ν i is inside. Otherwise, we set the entries in c(ν i ) \ c(ν i−1 ) that are to one side of c(ν i−1 ) to 1. Observe that an S-node ν i has an external path if and only if = k or i < m.
Hence, row κ looks as follows. Assume without loss of generality that c(ν m ) \ c(ν m−1 ) contains a 1 to the right of c(ν m−1 ). Then the entries in c(ν) are ordered such that all 0s (if any) are to the left and all 1s are to the right. Moreover, if ν is inside let 1 ≤ b ≤ k be maximal such that ν b is inside. Then all entries in columns c(ν b ) are 1. Otherwise let b = 1. For i = b + 1, . . . , m − 2 odd all entries in c(ν i ) \ c(ν i−1 ) that are on the right side of c(ν i−1 ) are 1. For i = b + 1, . . . , m − 1 even, all entries in c(ν i ) \ c(ν i−1 ) on one side of c(ν i−1 ) are 1 -however, for some i that could be the right-hand side and for others the left-hand side. Finally, the entries in c(ν m ) \ c(ν m−1 ) to the right of c(ν m−1 ) are ordered such that the 1s are to the left and the 0s (if any) are to the right. See Fig. 9.
Hence, the 1s in row κ are consecutive up to maybe the wrong choice of the side for the 1s inserted for border S-nodes. Observe, however, on one hand that we could remove now the 1s from the wrong side and insert them on the right side and would thus obtain the 1s consecutive. We could obtain that for one cluster also by permuting the columns for the children of the (b) the corresponding embedding Figure 10: The hierarchy in the BC-tree given by the choice of the root S-node accordingly. On the other hand the assignment to sides was forced by the same and different constraints -up to the choice for one cluster. Hence, if we do the permuting that works for one cluster it'll create the feasible assignment we'd obtain if we'd assign the sides now that we knew were the external paths are embedded.

C-Connected Clusterings on Arbitrary Graphs
Let (G, C) be a c-connected overlapping clustered graph with underlying planar graph G. We show how to extend the method from the last section to work for an arbitrary planar graph G. If G is not connected, we can test each connected component separately, since the c-connectivity limits each cluster to a single component.
It remains the case, where G is connected but not 2-connected and can thus be represented by a BC-tree. We consider the BC-tree of G rooted at a block H r (meaning that H r should contain an edge incident to the outer face of G in a planar drawing). Let H be a block of G. If H = H r then the parent cut vertex of H is the cut vertex of H on the path from H to H r . H is a child block of its parent cut vertex. All other cut vertices of H are called child cut vertices of H. All cut vertices of H r are child cut vertices of H r .
Consider the SPQR-tree T of H. If H = H r , any root of T is suitable. Otherwise the parent cut vertex of H must be on the outer face of H. Thus, a root of the SPQR-tree T is suitable if it corresponds to an edge incident to the parent cut vertex of H. See Fig. 10.
Let H 1 , . . . , H k be the child blocks of v and let V i , i = 1, . . . , k be the set of vertices in the connected components of G − v containing H i . We call a cluster C relevant for a child block H i , if v ∈ C and V i ⊆ C. Let C ext be the set of child cut vertices v of H such that C is relevant for a child block of v.
Use the algorithm for 2-connected graphs, restricting the roots for the SPQR-trees to be suitable, to test whether there is some c-planar embedding for each block H with the parent cut vertex on the outer face of H and C ext on the outer face of H[C]. For each child cut vertex v of a block H and for each child block H i of v, test whether there is a free face, i.e., a face f of H incident to v such that the boundary of f contains a vertex not in C for any cluster C that is relevant for H i . If so, the c-planar embeddings of the blocks can be combined into a c-planar embedding of the whole graph. In the following, we show that otherwise there is no c-planar drawing for the whole graph with the given choices of the root of the BC-tree and the roots of the SPQR-trees.
Given a c-planar embedding, a face f is free with respect to a subset C ⊆ C of clusters if f is not enclosed by a C-cycle for any C ∈ C . Otherwise, f is covered by C . In the following we use C instead of {C} if the context is clear.

Remark 1. A face is covered by C if and only if its boundary is a C-cycle.
A vertex v is free with respect to a subset C ⊆ C of clusters if one of its incident faces is free with respect to C and covered by C otherwise. We call a cut vertex v free for a child block H i , if v is free with respect to the set of clusters that are relevant for H i .
Given a vertex v in a block H, we call two incident edges e 1 and e 2 of v equivalent with respect to a set C of clusters, if they are in the same block of H[ C∈C C], i.e. if there is a simple cycle in H that is a C-cycle for any C ∈ C and contains both, e 1 and e 2 . A Cequivalence class around v is a maximal set of edges incident to v that are pairwise equivalent with respect to C . Let v be a vertex that is free with respect to any C ∈ C . Given a c-planar embedding of a block, a C -interval around a vertex v is a maximal sequence of consecutive edges around v that are (a) equivalent with respect to C and such that (b) the face between any two consecutive edges is covered by C for all C ∈ C . Note that there is a one-to-one correspondence between the C -equivalence classes and the C -intervals around v: the condition that v is free with respect to any cluster in C guarantees that the C -intervals have a well defined start and end point. Also note that there might be several distinct C -intervals around v -even if C contains only one cluster. Lemma 3. Let H be a block, v a vertex in H, and C ⊆ C. If there is a c-planar embedding of H, in which v is free with respect to C , then v is free with respect to C in any c-planar embedding of H in which v is free with respect to C for all C ∈ C .
Proof. Assume that there is a c-planar embedding of H in which v is free with respect to C for all C ∈ C but v is not free with respect to C . Consider the cyclic order e 1 , . . . e of the edges around v. Since v is not covered by any C ∈ C , the C-intervals around v are well defined. Among all C-intervals for all C ∈ C , let I be a minimal set of intervals such that all faces around v are covered by at least one interval in I. Let I i = e si , . . . , e ti , i = 1, . . . , κ be the intervals in I in cyclic order around v. See Fig. 11b. We assume that s 1 = 1, s i < t i for i = 1, . . . , κ − 1, and t κ > s κ . For simplicity, we set s κ+1 := s 1 . Let C i ∈ C be such that I i is a C i -interval. Since all faces around v are covered, it holds that s i+1 ≤ t i . e si+1 , . . . , e ti is a {C i , C i+1 }-interval (Let s i+1 ≤ j < t i . The face f between e j and e j+1 is covered by both, C i and C i+1 . Hence the boundary of f is a both a C i -and a C i+1 -cycle). Thus {e si+1 , . . . , e ti } is consecutive in any c-planar embedding. Hence, in any c-planar embedding, the ordering of edges around v is as follows and thus, a sequence of overlapping C-intervals for some C ∈ C . Hence, for any face f incident to v there is at least one C ∈ C such that f is covered by C. Therefore v cannot be free with respect to C in any c-planar embedding. We now apply Lemma 3 to any child cut vertex v of any block H and to the set C of relevant clusters of any child block of v to obtain our main result. Observe that the particular choice of C ext in the following theorem guarantees that the child cut vertices are free with respect to any relevant cluster.
Theorem 4. A c-connected overlapping clustered graph (G, C) is c-planar, if and only if G is planar and for each connected component of G, there is a root block of its BC-tree for which there exist suitable root nodes of the SPQR-tree of each block that are not inappropriate for any C ∈ C with C ext = {v; v child cut vertex and C relevant for a child block of v} such that 1. all binary matrices fulfill the consecutive-ones property and 2. given an arbitrary consecutive-ones ordering of the binary matrices each cut vertex is free for each of its child blocks in the corresponding embedding.
Proof. Assume the two conditions hold. We embed the blocks as in the proof of Theorem 3 and combine the embeddings of the blocks as follows. Let H be a block, let v be a child cut vertex of H and let H i be a child block of v. We place H i into a face of H incident to v that is free with respect to the set of H i 's relevant clusters. This yields a c-planar embedding of G: Otherwise there must be a cluster C and a vertex w ∈ V \ C such that w is enclosed by a C-cycle c. Let c be in block H. The first condition requires, that the embedding of H is c-planar (see Theorem 3). Hence, w cannot be a vertex of H. Let v be the parent cut vertex of H and let V be the union of the sets of vertices in the connected components of G − v not containing H. By the choice of the root of the BC-tree, V must be drawn in the outer face of H. Hence w / ∈ V . Finally, let v be a child cut vertex of H, let H i be a child block of v, let V i be the set of vertices in the connected components of G − v containing H i , and assume that w ∈ V i . Then v must be enclosed by c and thus, by c-planarity of H, v ∈ C. Since w / ∈ C it follows that C is relevant for H i . Since we embedded H i into a face of H that was free with respect to H i 's relevant clusters, it follows that w cannot be enclosed by the C-cycle c.
For the other direction assume now that there is a c-planar embedding E. Without loss of generality, we assume that G is connected. Let the root H r of the BC-tree be a block with an edge that is incident to the outer face of G. Root each SPQR-tree at an edge incident to the outer face of the respective block and incident to the parent cut vertex.
In a c-planar drawing, a child cut vertex v of a block H is placed on the outer face of H[C] for any relevant cluster C of any of v's child blocks. Thus, Theorem 3 implies that the roots are not inappropriate and Condition 1 is fulfilled.
Obviously any block must be inserted into a face that is free with respect to its relevant clusters in any c-planar embedding of G. Consider now a block H and an embedding E of H corresponding to an arbitrary consecutive-ones ordering of the binary matrices. Let v be a child cut vertex of H and let H i be a child block of v. Let C be the set of relevant clusters for H i .
The labeling guarantees that v is on the outer face of H[C] for any C ∈ C . Thus, E is a c-planar embedding of H in which v is free with respect to each C ∈ C . We further know that E induces a c-planar embedding of H in which v is free with respect to C . Hence, Lemma 3 implies that v is free with respect to C in E .
The characterization in the previous theorem immediately yields the following corollary.
Corollary 1. It can be tested in polynomial time whether a c-connected overlapping clustered graph is c-planar.