Extending Upward Planar Graph Drawings
In this paper we study the computational complexity of the Upward Planarity Extension problem, which takes in input an upward planar drawing of a subgraph of a directed graph and asks whether can be extended to an upward planar drawing of . Our study fits into the line of research on the extensibility of partial representations, which has recently become a mainstream in Graph Drawing.
We show the following results.
First, we prove that the Upward Planarity Extension problem is NP-complete, even if has a prescribed upward embedding, the vertex set of coincides with the one of , and contains no edge.
Second, we show that the Upward Planarity Extension problem can be solved in time if is an -vertex upward planar -graph. This result improves upon a known -time algorithm, which however applies to all -vertex single-source upward planar graphs.
Finally, we show how to solve in polynomial time a surprisingly difficult version of the Upward Planarity Extension problem, in which is a directed path or cycle with a prescribed upward embedding, contains no edges, and no two vertices share the same -coordinate in .
Testing whether a partial solution to a problem can be extended into a complete one is a classical algorithmic question. For instance, Kratochvíl and Sebo  studied the vertex coloring problem when few vertices are already colored, whereas Fiala  considered the problem of extending a partial -coloring of the edges of a graph.
The study of the extensibility of partial representations of graphs has recently become a mainstream in the graph drawing community; see, e.g., [3, 9, 11, 12, 13, 20, 22, 23, 24, 25, 28]. Major contributions in this scenario are the result of Angelini et al. , which states that the existence of a planar drawing of a graph extending a given planar drawing of a subgraph of can be tested in linear time, and the result of Brückner and Rutter , which states that the problem of testing the extensibility of a given partial level planar drawing of a level graph (where each vertex – including the ones whose drawing is not part of the input – has a prescribed -coordinate, called level) is NP-complete.
Upward planarity is the natural counterpart of planarity for directed graphs. In an upward planar drawing of a directed graph no two edges cross and an edge directed from a vertex to a vertex is represented by a curve monotonically increasing in the -direction from to ; the latter property effectively conveys the information about the direction of the edges of the graph. The study of upward planar drawings is a most prolific topic in the theory of graph visualization [2, 4, 5, 6, 7, 8, 10, 14, 15, 17, 19, 29]. Garg and Tamassia showed that deciding the existence of an upward planar drawing is an NP-complete problem . On the other hand, Bertolazzi et al.  showed that testing for the existence of an upward planar drawing belonging to a fixed isotopy class of planar embeddings can be done in polynomial time. Further, Di Battista et al.  proved that any upward planar graph is a subgraph of a planar -graph and as such it admits a straight-line upward planar drawing.
In this paper, we consider the extensibility of upward planar drawings of directed graphs. Namely, we introduce and study the complexity of the Upward Planarity Extension (for short, UPE) problem, which is defined as follows. The input is a triple , where is an upward planar drawing of a subgraph of a directed graph ; we call and the partial graph and the partial drawing, respectively. The UPE problem asks whether can be extended to an upward planar drawing of ; or, equivalently, whether an upward planar drawing of exists which coincides with when restricted to the vertices and edges of . We also study the Upward Planarity Extension with Fixed Upward Embedding (for short, UPE-FUE) problem, which is the UPE problem with the additional requirement that the drawing of we seek has to respect a given upward embedding, i.e., a left-to-right order of the edges entering and exiting each vertex.
Related problems. Level planar drawings are special upward planar drawings. Klemz and Rote studied the Ordered Level Planarity (OLP) problem , where a partial drawing of a level graph is given containing all the vertices and no edges. The problem asks for the existence of a level planar drawing of the graph extending the partial one. They show a tight border of tractability for the problem by proving NP-completeness even if no three vertices have the same -coordinate and by providing a linear-time algorithm if no two vertices have the same -coordinate. Brückner and Rutter studied the Partial Level Planarity (PLP) problem , that is, the extensibility of a partial drawing of a level graph, which might contain (not necessarily all) vertices and edges. Beside proving NP-completeness even for connected graphs, they provided a quadratic-time algorithm for single-source graphs.
The NP-hardness of the Upward Planarity Testing problem  directly implies the NP-hardness of the UPE problem, as the former coincides with the special case of the latter in which the partial graph is the empty graph. Further, we have that any instance of the OLP problem in which no vertices have the same -coordinate can be transformed in linear time into an equivalent instance of the UPE problem in which the partial graph contains all the vertices and no edges, and no vertices have the same -coordinate in the partial drawing; moreover, a linear-time reduction can also be performed in the opposite direction. As a consequence of these reductions and of the cited results about the complexity of the OLP problem, we obtain that the UPE problem is NP-hard even if the partial graph contains all the vertices and no edges, and no three vertices share the same -coordinate in the partial drawing, while it is linear-time solvable if the partial graph contains all the vertices and no edges, and no two vertices have the same -coordinate in the partial drawing.
Several constrained graph embedding problems that are NP-hard when the graph has a variable embedding are efficiently solvable in the fixed embedding setting; some examples are minimizing the number of bends in an orthogonal drawing [19, 30], testing for the existence of an upward planar drawing [5, 19], or testing for the existence of a windrose-planar drawing . Observe that the NP-hardness of the UPE problem does not directly imply the NP-hardness of the UPE-FUE problem. However, by providing a non-trivial extension of the cited NP-hardness proof of Brückner and Rutter  for the PLP problem, we show that the UPE-FUE problem is NP-hard even for connected instances whose partial graph contains all the vertices and no edges. These proofs of NP-hardness are presented in Section 3.
Our contributions. We now present an overview of our algorithmic results.
First, we identify two main factors that contribute to the complexity of the UPE and UPE-FUE problems: (i) The presence of edges in the partial graph and (ii) the existence of vertices with the same -coordinate in the partial drawing. These two properties are strictly tied together. Namely, any instance of the UPE or UPE-FUE problems can be efficiently transformed into an equivalent instance of the same problem in which contains no edges or no two vertices share the same -coordinate in (see Section 2). Hence, the NP-hardness results for the UPE and UPE-FUE problems discussed above carry over to such instances, even when . When the partial graph contains no edges and no two vertices share the same -coordinate in the partial drawing, then the UPE and UPE-FUE problems appear to be more tractable. Indeed, although we can not establish their computational complexity in general, we can solve them for instances such that is a directed path or cycle (see Section 5). In particular, in order to solve the UPE-FUE problem for directed paths, we employ a sophisticated dynamic programming approach.
Second, we look at the UPE and UPE-FUE problems for instances such that is an upward planar -graph (see Section 4), i.e., it has a unique source and a unique sink . The upward planarity of an -graph is known to be decidable in time [15, 17], where is the size of the instance. We observe that a result of Brückner and Rutter  implies the existence of an -time algorithm to solve the UPE problem for upward planar -graphs; their algorithm works more in general for upward planar single-source graphs. We present -time algorithms for the UPE and UPE-FUE problems for upward planar -graphs. Notably, these results assume neither that the edge set of is empty, nor that any two vertices have distinct -coordinates in , nor that .
In the first part of this section we give some preliminaries and definitions.
A drawing of a graph is planar if no two edges intersect. A graph is planar if it admits a planar drawing. A planar drawing partitions the plane into topologically connected regions, called faces. The unique unbounded face is the outer face, whereas the bounded faces are the internal faces. Two planar drawings of a connected planar graph are equivalent if they have the same clockwise order of the edges around each vertex. A planar embedding is an equivalence class of planar drawings of the same graph.
For a directed graph we denote by an edge that is directed from a vertex to a vertex ; such an edge is incoming at or enters , and is outgoing from or exits . A source of is a vertex with no incoming edges; a sink of is a vertex with no outgoing edges. A path in is monotone if the edge between and exits and enters , for every . A successor (predecessor) of a vertex in is a vertex such that there is a monotone path from to (resp. from to ). We denote by (by ) the set of successors (resp. predecessors) of in . An edge of is transitive if contains a monotone path from to with at least one internal vertex. When the direction of an edge in is not known or relevant, we denote it by instead.
A drawing of a directed graph is upward if each edge is represented by a curve monotonically increasing in the -direction from to . A drawing of is upward planar if it is both upward and planar. A graph is upward planar if it admits an upward planar drawing.
Consider an upward planar drawing of a directed graph and consider a vertex . The list contains the adjacent successors of in “left-to-right order”. That is, consider a half-line starting at and directed leftwards; rotate around in clockwise direction and append a vertex to when overlaps with the tangent to the edge at . The list of the adjacent predecessors of is defined similarly. Then two upward planar drawings of a connected directed graph are equivalent if they have the same lists and for each vertex . An upward embedding is an equivalence class of upward planar drawings. If a vertex in an upward planar graph is not a source or a sink, then a planar embedding of determines and . However, if is a source or a sink, then different upward planar drawings might have different lists or , respectively. The combinatorial properties of the upward embeddings have been characterized by Bertolazzi et al. .
Given an upward planar graph with a fixed upward embedding, and given a subgraph of , we assume that is associated with the upward embedding corresponding to the upward planar drawing of obtained from an upward planar drawing of with the given upward embedding by removing the vertices and edges not in .
In order to study the time complexity of the UPE and UPE-FUE problems, we assume that an instance of any of such problems is such that is a polyline drawing, that is, a drawing in which the edges are represented as polygonal lines. Then we define the size of as , where is the number of segments that compose the polygonal lines representing the edges in .
Consider an upward planar -graph with a fixed upward embedding. In any upward planar drawing of every face is delimited by two monotone paths and connecting the same two vertices and . Assuming that , we call the left boundary of and the right boundary of . For a vertex in , the leftmost outgoing path of is the monotone path such that , , and , for each . The rightmost outgoing path , the leftmost incoming path and the rightmost incoming path are defined similarly. The paths and are also called leftmost and rightmost path of , respectively. Note that these paths delimit the outer face of . Consider a monotone path from to . Let be obtained by extending with a -monotone curve directed upwards from to infinity and with a -monotone curve directed downwards from to infinity. Then a vertex is to the left (to the right) of if it lies in the region to the left (resp. to the right) of . In particular, is to the left of a vertex if it lies to the left of the monotone path composed of and . Analogously, is to the right of if it lies to the right of the monotone path composed of and . We denote by (by ) the set of vertices that are to the left (resp. to the right) of a vertex in . Note that all the definitions introduced in this paragraph do not depend on the actual drawing of , but only on its upward embedding.
A cut-vertex in a graph is a vertex whose removal disconnects . A separation pair in is a pair of vertices whose removal disconnects . A graph is biconnected (triconnected) if it has no cut-vertex (resp. no separation pair). A biconnected component of is a maximal biconnected subgraph of .
Let be an -vertex biconnected upward planar -graph containing the edge . A split pair of is either a separation pair or a pair of adjacent vertices. A split component for a split pair is either the edge or a maximal subgraph of which is an upward planar -graph and such that is not a split pair of . A split pair is maximal if there is no distinct split pair in such that is contained in a split component of .
The SPQR-tree of , defined as in , describes a recursive decomposition of with respect to its split pairs and represents succinctly all the upward planar embeddings of . The tree is a rooted tree with four types of nodes: S, P, Q, and R (refer to Fig. 1). Any node of is associated with an upward planar -graph, called skeleton of , which might contain multiple edges and which we denote by . The edges of are called virtual edges. The tree is recursively defined as follows.
Trivial case. If consists of a single edge , then is a Q-node and also coincides with the edge .
Series case. If is not a single edge and is not biconnected, then let (for some ) be the cut-vertices of , where belongs to two biconnected components and , for , with and . Further, set and ; then is an upward planar -graph, for . The root of is an S-node . Finally, is a monotone path plus the edge .
Parallel case. If is not a single edge, if it is biconnected, and if is a split pair of defining split components (for some ), then is an upward planar -graph, for . The root of is a P-node . Finally, consists of parallel edges .
Rigid case. If is not a single edge, if is biconnected, and if is not a split pair of , then let be the maximal split pairs of (for some ). Further, let be the union of all the split components of , for . Then is an upward planar -graph, for . The root of is an R-node . Finally, the graph is obtained from by replacing each subgraph with an edge and by adding the edge . We have that is a triconnected upward planar -graph.
In each of the last three cases, the subtrees of are the SPQR-trees of , rooted at the children of , respectively. Further, the virtual edge in (just one of the edges in the case of a P-node) is associated with the parent of in , while every other virtual edge is associated with a child of and with the graph . The graph corresponds to a virtual edge of and it is called the pertinent graph of and of .
The overall tree of is rooted at the only neighbor of the Q-node ; the skeleton for the root of is defined slightly differently from the other nodes, as it does not contain the virtual edge representing its parent. It is known that has nodes and that the total number of virtual edges in the skeletons of the nodes of is in . All the upward embeddings of can be obtained by suitably permuting the virtual edges of the skeletons of the P-nodes and by flipping the skeletons of the R-nodes. For a specific choice of such permutations and flips, an upward embedding is recursively obtained by substituting the virtual edges in the skeleton of a node with the upward embeddings associated to the children of .
Let be a vertex of . The allocation nodes of are the nodes of whose skeletons contain . Note that has at least one allocation node. The lowest common ancestor of the allocation nodes of vertex is itself an allocation node of and it is called the proper allocation node of . Let be a node of . The representative of in is the vertex or edge of defined as follows: If is an allocation node of , then ; otherwise, is the edge of whose pertinent graph contains .
From a computational complexity perspective, the SPQR-tree of an -vertex upward planar -graph can be constructed in time. Further, within the same time bound, it is possible to set up a data structure that allows us to query for the proper allocation node of a vertex of in time and to query for the lowest common ancestor of two nodes of in time .
In this section we prove that it is not a loss of generality to restrict our attention to instances of the UPE and UPE-FUE problems in which the partial graph contains no edges or no two vertices share the same -coordinate in the partial drawing. We first deal with instances in which the partial graph contains no edges.
Let be an instance of the UPE or UPE-FUE problem and let . There exists an equivalent instance of the UPE or UPE-FUE problem, respectively, such that:
if , then , and
if is an -graph, then is an -graph.
Further, the instance has size and can be constructed in time. The drawing may contain vertices with the same -coordinate even if does not.
Throughout this proof we will assume that is a straight-line drawing of . This is not a loss of generality, as if an edge of is represented in by a polygonal line , where are the bends of the polygonal line, then dummy vertices can inserted on in ; further, the edge becomes a monotone path both in and in . Note that the size of the instance remains asymptotically the same.
We now define the instance and argue about its size. We will later describe how to compute it efficiently.
The graph is obtained from by replacing certain edges of that are also in by monotone paths; how to precisely perform such a replacement will be described later. If has a prescribed upward embedding, then derives its upward embedding from the one of . That is, if an edge is replaced by a monotone path , then substitutes in and substitutes in ; further, for , we have and . Property (iii) of the lemma’s statement is trivially satisfied.
The graph is composed of all the vertices of plus all the vertices internal to the monotone paths that are inserted in to replace edges of that are also in . Property (ii) of the lemma’s statement is then satisfied. Further, contains no edge, hence Property (i) of the lemma’s statement is satisfied.
The drawing coincides with when restricted to the vertices also belonging to . It remains to specify the lengths of the monotone paths that are inserted in to replace edges of that are also in and to describe how to place their internal vertices in . This is done in the following.
Refer to Fig. 2. Among all the possible -coordinates, we call interesting the ones of the vertices of in . We examine the interesting -coordinates in increasing order . For any , denote by the line with equation . We look at the left-to-right order in which the vertices of lying on and the edges of crossing appear in . We place a vertex in at the point in which an edge of crosses in two cases:
If is preceded or followed by a vertex of in ; or
if has an end-vertex whose -coordinate in is or .
If we place a vertex at the crossing point of with , then is also a vertex that is internal to the monotone path that is inserted in to replace . Clearly, the edges of the monotone paths are directed so to connect vertices in increasing order of their -coordinates. This concludes the construction of .
We prove that the size of is linear in the size of . The only vertices which belong to and not to are those internal to the monotone paths that are inserted in to replace edges of that are also in . The number of vertices that are inserted in because of case (i) is at most ; further, the number of vertices that are inserted in because of case (ii) is at most . Since the only edges that belong to and not to are those of the monotone paths above, it follows that the number of such edges is also in . The claim about the size of follows.
We next show how to construct the instance efficiently.
First, we construct a list in which the vertices of are ordered by increasing -coordinate and, secondarily, by increasing -coordinate in . This is done in time.
Handling the vertices that need to be inserted in because of case (ii) is easy. Indeed, it suffices to look at every edge of . Let and be the -coordinates of its end-vertices, for some ; then insert vertices at the crossing points of with the lines and . This can be done in overall time.
Handling the vertices that need to be inserted in because of case (i) is more difficult. The rest of the analysis of the running time deals with this.
For each interesting -coordinate , a trivial algorithm would: (1) compute the crossing points between and the edges of crossing it; (2) order such crossing points together with the vertices of lying on by increasing -coordinate; and (3) insert the new vertices at the crossing points which are preceded or followed by vertices of . However, this might require time in total, as edges might span the -coordinates of vertices of in . We now describe how to bring the time complexity down to .
We examine the interesting -coordinates in increasing order ; denote by the restriction of to the vertices on .
For , our algorithm computes the list defined above; note that coincides with . Further, for , our algorithm also computes a list which contains the edges of crossing the line in , in left-to-right order.
Assume that has been computed, for some . We compute as follows. We initialize to . Then, for each vertex in , we replace in by its outgoing edges in left-to-right order as they appear in . The vertex is accessed in and in in time via a pointer associated to in . Thus, can be constructed in time proportional to the number of edges exiting vertices in , hence in total time.
Now assume that has been computed, for some . We compute as follows. We initialize to . Then, for each vertex in , we determine whether contains edges entering . In case it does, such edges are removed from (indeed, they “end” on ), and is inserted in their place; otherwise, is just inserted in a suitable position in .
The above approach is realized by performing, for each vertex in , a binary search on , which compares to the -coordinates of the intersection points of the edges in with . More precisely, when the binary search considers an edge in , the -coordinate of its intersection point with is computed in time and then compared to ; we stress the fact that not all the intersection points of the edges in with are computed, but only the ones that are compared with in the binary search. The binary search stops in two possible situations. The first is the one in which an edge is found that enters ; that is, is such that . That edge and all the other edges entering are then removed from and is inserted in place of such edges (and a pointer to it is set in ). The second situation in which the binary search stops is the one in which the -coordinates of two consecutive elements of have been compared to , and has been found to be in between such coordinates. Then is inserted between such elements (and a pointer to it is set in ). Finding the proper place where to insert in takes time, and hence time over all the vertices of . Further, removing the edges entering can be done in time because all such edges appear consecutively in , and hence in , by the planarity of ; hence this takes time in total.
Once has been computed, we determine the placement in of the vertices in that are inserted on . In order to do that, we again access each vertex ; then we look at the two elements adjacent to in , and if any of them is an edge we insert a vertex at its intersection point with . For each this takes time, hence time in total.
It remains to prove the equivalence between and .
One direction is easy. Indeed, assume that an upward planar drawing of exists which extends . We modify by placing each vertex at the point where lies in . Let be the edge of that is also in and that is replaced by a monotone path which includes as an internal vertex in . By construction lies on the curve representing in ; hence, the insertion of all the vertices in in results in an upward planar drawing of extending .
The other direction is much more involved. Assume that an upward planar drawing of extending exists. By construction, all the vertices of are also in ; further, these vertices are placed at the same points in and . Let be the drawing of obtained from by interpreting the representation of each monotone path of corresponding to an edge of as a representation of . Then we have that is an upward planar drawing of such that the vertices in are placed as in . However, it might be the case that the edges of that are also in are not drawn in as they are required to be drawn in . We hence need to modify the drawing of such edges in .
Our proof that such a modification is always feasible is a direct consequence of Claim below. We introduce some definitions. Every edge of corresponds to a monotone path in ; we call replacement edge each edge of such monotone paths. Note that the end-vertices of a replacement edge are in , while the replacement edge itself is not in . Recall that, for , the list represents the left-to-right order in which the vertices of lying on and the edges of crossing appear along in . By construction, each vertex of lying on is also a vertex of lying on ; further, each edge of crossing either determines a vertex of lying on or corresponds to a replacement edge of crossing . Hence, there is a bijection between and a set which contains the vertices of lying on and the replacement edges of crossing .
While the left-to-right order of the elements of along in any upward planar drawing of extending is fixed, as all the elements of are drawn in , some elements of do not have any fixed intersection with . Namely, the elements of corresponding to vertices of lying on do have a fixed intersection with ; however, in principle, the elements of corresponding to replacement edges of crossing do not have any restriction on where they should cross with respect to the other elements of . The following claim proves that such a restriction actually exists.
In any upward planar drawing of extending the left-to-right order of the elements of along is .
We prove the claim by induction on . The base case, in which , is trivial, since all the elements of are vertices of , whose left-to-right order along is determined by .
Now suppose that the claim holds for , for some ; we prove the claim for .
We first argue about the elements that are associated with a -monotone curve that extends between and in . More precisely, an element of is of interest here in one of the following two cases:
is a replacement edge of crossing .
is a vertex of lying on that is incident to a replacement edge which is incoming at .
Note that, in both cases, the edge either crosses or has its source on . Then, in both cases, we define as the part of the replacement edge between and . Let be the set of such elements . Hence, contains all the elements of , except for the vertices of lying on in corresponding to sources of .
Consider any element , its associated -monotone curve , and the replacement edge the curve is part of. If crosses in , then is represented by an element in . Otherwise, has its source on ; we denote such a source also by . The elements and correspond to elements and of and , respectively. A -monotone curve between a point of and a point of is associated with ; this curve represents part of an edge of which might cross and/or in (then and/or represent such an edge), or might have an end-vertex on and/or in (then and/or represent the end-vertices of such an edge).
Now consider any two distinct elements . These are associated to elements and of , respectively, via the curves and . Assume w.l.o.g. that is to the left of along in . We establish that precedes in .
If , then is to the left of , as otherwise the -monotone curves and would cross, while is planar. By induction, is to the left of in . Hence precedes in , as otherwise the -monotone curves and would cross, while is assumed to be planar.
If , then and represent parts of replacement edges of whose sources coincide with . Since defines a bijection between and , we have , hence and are edges of both incident to . By construction, a vertex is inserted in at the crossing point between and , and a vertex is inserted in at the crossing point between and (these vertices are inserted in case (ii) of the construction of ). Such vertices are in fact and . Hence, the edges and are in this left-to-right order along , thus precedes in .
It follows that, in any upward planar drawing of extending , the left-to-right order in which the elements of appear along coincides with the order restricted to the elements of .
Now consider any maximal sequence of consecutive elements of that are sources of . Since are vertices of , they appear in the order along . Hence, we only have to ensure that fit between the suitable elements of along . Assume that and both exist (the case in which is an initial and/or final subsequence of is easier to handle). By the maximality of the sequence , we have that and belong to , with immediately preceding along . If is a vertex of , then is a vertex of , hence precedes in left-to-right order along in and hence in . Otherwise, is an edge of crossing ; however, since is a vertex of , a vertex has been inserted in at the crossing point between and (this vertex is inserted in case (i) of the construction of ). In fact is such a vertex. Then precedes in left-to-right order along in and hence in . An analogous argument proves that precedes in left-to-right order along in and hence in . The claim follows.
Claim implies that the desired modification of , which ensures that the edges of are drawn as in , can be performed “locally” to each strip delimited by two consecutive lines and . Then one can start from the intersection between and , which consists of a set of -monotone curves connecting points on with points on , and independently draw the part of inside each region of defined by such -monotone curves.
This concludes the proof of the lemma.
We next deal with instances of the UPE and UPE-FUE problems in which no two vertices have the same -coordinate in the given partial drawing.
Let be an instance of the UPE or UPE-FUE problem and let . There exists an equivalent instance of the UPE or UPE-FUE problem, respectively, such that:
no two vertices of share the same -coordinate in and
if , then .
Further, the instance has size and can be constructed in time. The graph may contain edges even if does not.
First, we apply Section 2.2 in order to transform into an equivalent instance such that contains no edges and such that if . The instance has size and can be constructed in time. Hence, it suffices to prove the statement of the lemma with in place of .
We define the desired instance as follows. Refer to Fig. 3. We initialize . We construct a list of the vertices of ordered by increasing -coordinates and, secondarily, by increasing -coordinates in . This is done in time. Among all the possible -coordinates, we call interesting the ones of the vertices of in . We examine the interesting -coordinates in increasing order . For any , denote by the line with equation ; further, denote by