Extending Upward Planar Graph Drawings
Giordano Da Lozzo, Giuseppe Di Battista, Fabrizio Frati

TL;DR
This paper investigates the computational complexity of extending partial upward planar graph drawings, proving NP-completeness in general but offering efficient algorithms for specific graph classes like upward st-graphs and directed paths or cycles.
Contribution
It establishes NP-completeness for the general problem and provides improved algorithms for upward st-graphs and polynomial solutions for special cases.
Findings
NP-complete in general case
O(n log n) algorithm for upward st-graphs
Polynomial-time solution for directed paths and cycles with unique y-coordinates
Abstract
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…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Extending Upward Planar Graph Drawings
Giordano Da Lozzo
Roma Tre University, Italy
{dalozzo,gdb,frati}@dia.uniroma3.it
Giuseppe Di Battista
Roma Tre University, Italy
{dalozzo,gdb,frati}@dia.uniroma3.it
and Fabrizio Frati
Roma Tre University, Italy
{dalozzo,gdb,frati}@dia.uniroma3.it
Abstract
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 .
1 Introduction
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 [27] studied the vertex coloring problem when few vertices are already colored, whereas Fiala [18] 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. [3], 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 [9], 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 [19]. On the other hand, Bertolazzi et al. [5] 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. [15] 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 [26], 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 [9], 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 [19] 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 [1]. 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 [9] 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 [9] 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 .
2 Preliminaries
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. [5].
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.
2.1 SPQR-Trees
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 [16], 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 [16].
2.2 Simplifications
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.
Lemma 1 ().
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:
- (i)
, 2. (ii)
if , then , and 3. (iii)
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.
Proof.
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:
- (i)
If is preceded or followed by a vertex of in ; or 2. (ii)
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 1 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.
Claim 1**.**
*In any upward planar drawing of extending the left-to-right order of the elements of along is . *
Proof.
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:
- (1)
is a replacement edge of crossing . 2. (2)
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 1 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.
Lemma 2 ().
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:
- (i)
no two vertices of share the same -coordinate in and 2. (ii)
if , then .
Further, the instance has size and can be constructed in time. The graph may contain edges even if does not.
Proof.
First, we apply Lemma 1 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 the restriction of to the vertices on .
We consider horizontal strips such that: (i) for , the line is in the interior of , at equal distance from the horizontal lines and delimiting from above and from below, respectively; and (ii) for , the line lies below . Observe that condition (ii) can be achieved by letting the strips be sufficiently thin.
We now replace each vertex in by an edge. This is done as follows. Let be the height of . Recall that the vertices lying on are ordered in by increasing -coordinate; let be such an ordering. For , we draw a vertical straight-line segment whose midpoint is and whose length is . Note that lies entirely in and crosses .
We replace by two vertices and and by an edge , both in and in . The outgoing edges of in now exit and the incoming edges of in now enter . If has a prescribed upward embedding, then the list of successors of the adjacent predecessors of and the list of predecessors of the adjacent successors of are updated by replacing with and , respectively. Further, coincides with , while , and coincides with , while . The vertex is also removed from . Finally, the edge is represented in by the segment . This concludes the construction of .
Vertices of lying in different strips and do not share their -coordinates in , as such strips are horizontal and disjoint. By construction vertices of lying in the same strip do not share their -coordinates in . Thus, Property (i) is satisfied. If , then , as every vertex in is replaced by two vertices belonging to . Hence Property (ii) is also satisfied.
The size of is linear in the size of as at most two vertices and one edge are introduced in for each vertex of . Constructing the order takes time. Every other step of the algorithm can be performed in time, hence the total running time.
We prove the equivalence between the instances and .
Suppose that an upward planar drawing of exists that extends . For each vertex of that has been replaced in by two vertices and and by an edge , we perform the following modification; see Fig. 4(a). By construction and since extends , the straight-line segment in contains the point at which is placed in . Then a sufficiently small value can be defined so that the region obtained as the Minkowski sum of a ball with radius with the straight-line segment intersects only in a set of line segments incident to and . For each vertex of we delete from the interior of , as in Fig. 4(b), and we draw line segments connecting with the endpoints of the removed line segments on the boundary of , as in Fig. 4(c). This results in the desired drawing of extending .
Conversely, suppose that an upward planar drawing of exists that extends . For each , we modify as follows. First, we vertically perturb the position of each vertex that lies on and that does not belong to . If the perturbation is small enough, then the curves representing the edges incident to that vertex can also be suitably modified so that remains an upward planar drawing of . Refer to Fig. 5(a) and denote by the left-to-right order of the points of along ; note that each of such points might correspond to a vertex of or to a crossing point of an edge of with . Let be a horizontal line above and below . As in Fig. 5(b), we vertically scale down the part of between and so that its vertical extension becomes equal to the distance between and . Further, we translate the scaled part of the drawing so that it lies between and ; after doing so, the points of on acquire corresponding points on . We perform an analogous modification to the part of comprised between and a horizontal line above and below ; denote by the points on corresponding to , respectively. Now does not contain any part of in its interior, except for the points . For every , we draw a vertical straight-line segment connecting with , as in Fig. 5(c); note that passes through . If used to be a crossing point between an edge of and in , then reconnects that edge; indeed, the latter became disconnected after scaling and translating parts of . Otherwise, is the point in which a vertex was placed in and . Then is a part of ; see Fig. 5(d). We remove a small disk around from and extend the edges outgoing down along until they reach . Analogously, we remove a small disk around from and extend the edges incoming up along until they reach . This completes the construction of the desired drawing of extending .
3 Complexity of the UPE and UPE-FUE Problems
In this section we study the complexity of the UPE and UPE-FUE problems. We show the NP-hardness of such problems even for instances in which contains no edges and , and for instances in which no two vertices share the same -coordinate in and . We will then show that the instances in which contains no edges, no two vertices share the same -coordinate in , and can be solved in polynomial time.
We start with the following.
Lemma 3.
The UPE and UPE-FUE problems are in NP.
Proof.
Let be an instance of the UPE problem. Ideally, we would like to guess a solution for , that is, a drawing of , and then to verify in polynomial time whether the guess actually is a solution, that is, whether is an upward planar drawing of extending . However, since there is an infinite number of drawings of , we cannot explicitly guess one of them. Hence, we proceed by associating to each drawing a combinatorial structure, in such a way that: (1) the set of distinct combinatorial structures the drawings of are associated to is finite; and (2) it is possible to test in polynomial time whether an upward planar drawing of extending exists by assuming that such a drawing is associated with a fixed combinatorial structure. This is done in the following.
First, we guess the order by increasing -coordinates of the vertices of in an upward planar drawing of extending . This can be done by assigning a number in to each vertex of . The assignment is, in general, not injective, i.e., the guess might result in several vertices having the same -coordinate. Let be the guessed order of the vertices of . Denote by the subsets of such that: (i) for any , the -coordinates of and are the same in ; and (ii) for any and , the -coordinate of precedes the one of in . Note that there are only finitely many such orders .
Having guessed , we now know whether the horizontal line through the vertices in crosses an edge in . Indeed, this happens if and only if and , with and , or with and . For each , we independently guess a left-to order of the vertices in together with the edges crossing in . Again, there are only finitely many such orders.
We now show how to verify in polynomial time whether an upward planar drawing of exists that extends and that respects and . We perform the checks described below. If any check fails, then we conclude that there is no upward planar drawing of that extends and that respects and , otherwise we proceed to the next check. If all the checks succeed, then an upward planar drawing of exists that extends and that respects and .
For any edge of such that and , we check whether . 2. 2.
We say that an edge of , with and , spans and if and . For any two edges and that span and , we check whether the order of and (or of their end-vertices) in and is the same. 3. 3.
For any two vertices such that and with , we check whether in . 4. 4.
For any two vertices , we check whether in . 5. 5.
For any two vertices such that in and such that precedes in , we check whether in . 6. 6.
For any vertex and for any edge in , we check whether precedes in if and and only if the crossing point between and the horizontal line through is to the left of in . 7. 7.
For any vertex in and any two edges in , we check whether precedes in if and only if the crossing point of with the horizontal line through is to the left of the crossing point of with the horizontal line through in .
If check 1. fails that any drawing of that respects is not upward. If check 2. fails that any upward drawing of that respects , , and is not planar. If checks 3. or 4. fail, then any upward drawing of that respects does not extend . If checks 5., 6., or 7. fail, then any drawing of that respects and does not extend .
On the other hand, if all the checks succeed, then we can construct an upward planar drawing of that extends and that respects and as follows. First, for , we draw a horizontal line with equation on which the vertices in are going to be placed, where . This is done so that passes through a vertex if , which is possible since checks 3. and 4. succeed. For , we place the vertices in that are not in along and we fix the crossing points between and the edges of that are in but not in , so that the left-to-right order of the vertices of (including those in ) and of the edges of (including those in ) along is . This is possible because checks 5., 6., and 7. succeed. Each edge in is now drawn as a sequence of line segments, each connecting points on two consecutive lines and . Since check 2. succeeds, every such a line segment can be drawn in the horizontal strip delimited by and without introducing any crossings, thus the resulting drawing of is planar. Since check 1. succeeds, it follows that is also upward. The drawing has not been modified during the construction of , hence extends . By construction, for each , the vertices in have a smaller -coordinate than the vertices in , hence respects . Finally, by construction, for each , the left-to-right order of the vertices in and of the edges of crossing is , hence respects .
Since all the above checks can be easily performed in polynomial time, we have that UPE is in NP. The membership in NP of the UPE-FUE problem can be proved analogously. In particular, a check has to be introduced in the above algorithm in order to verify whether the orders and define an upward embedding which is the one prescribed in the instance.
We now prove the NP-hardness results. The NP-hardness of the UPE problem directly follows from the one of the Upward Planarity Testing problem [19], which coincides with the special case of the UPE problem in which the partial graph is the empty graph. However, we can establish the NP-hardness of the UPE problem even in a much more constrained scenario. In order to do that, we relate the complexity of the UPE problem to the one of a problem called Ordered Level Planarity [26] (OLP, for short), which is defined as follows.
A level graph is a pair , where is a directed graph and is a function that assigns each vertex to one of levels in such a way that , for each . We denote . A level graph is proper if , for each . A level drawing of is a drawing of that maps each vertex to a point on the horizontal line with equation and each edge to a -monotone curve connecting the points corresponding to and . A level drawing is level planar if it is crossing-free and a level graph is level planar if it admits a level planar drawing.
An ordered level graph is a triple where is a level graph and is a set of total orders of the vertices in . Given an ordered level graph , the OLP problem asks whether there exists an ordered level planar drawing of , that is, a level planar drawing of in which, for every , the -coordinate of is . As observed by Klemz and Rote [26], for an ordered level graph , the - and -coordinates assigned via and , respectively, only serve the purpose of encoding a partial order among vertices of different levels and a total order among vertices of the same level, respectively. In particular, the OLP problem does not change its complexity if and map to the reals. We exploit this fact in the proof of the following lemma.
Lemma 4.
The following statements hold true:
- (i)
Let be an instance of the OLP problem, where is an -vertex graph. It is possible to construct in time an equivalent instance of the UPE problem with such that if contains at most vertices belonging to the same level, then contains at most vertices sharing the same -coordinate. 2. (ii)
Let be an instance of the UPE problem, where is an -vertex graph and . It is possible to construct in time an equivalent instance of the OLP problem such that if contains at most vertices sharing the same -coordinate, then contains at most vertices belonging to the same level.
Proof.
(i) Given an ordered level graph with levels, where is an -vertex graph, we construct an instance of the UPE problem as follows. First, coincides in the two instances. Second, we define , as required. Third, for every and for every , we define the position of in as . This completes the construction of ; this construction can be clearly performed in time. By construction, if contains at most vertices belonging to the same level, then contains at most vertices sharing the same -coordinate.
We claim that the instance of the OLP problem and the instance of the UPE problem are equivalent. Specifically, we have that any ordered level planar drawing of is also an upward planar drawing of that extends and that any upward planar drawing of that extends is also an ordered level planar drawing of . In fact, it holds that (i) each vertex of has the same coordinates both in and in , and that (ii) the edges of are drawn as -monotone curves both in and in .
(ii) Given an instance of the UPE problem, where is an -vertex graph and , we construct an ordered level graph as follows. First, the graph coincides in the two instances. Second, we define a partition of such that, for each , all the vertices in have the same -coordinate in , and such that, for each , the vertices in have a -coordinate smaller than the one of the vertices in in . This partition can be constructed in time after the vertices of have been ordered by their -coordinates in , which takes time. For each vertex of , we now assign if and only . Finally, for each , we compute the order of the vertices in by increasing -coordinates. Such an order can be constructed in time, hence in time over all sets . We claim that the instance of the UPE problem and the instance of the OLP problem are equivalent.
Suppose that an upward planar drawing of exists that extends . For each , we draw a horizontal line through the vertices in in ; let be the left-to-right order in which the vertices in and the edges of crossing appear along in . We construct a level planar drawing of by placing, for each , a sequence of points along the line , such that:
- •
for each , the -coordinate of is smaller than the one of ; and
- •
for each , if corresponds to a vertex of , then the -coordinate of is equal to .
The level planar drawing of is completed by representing each edge of as a sequence of straight-line segments. Specifically, if and , then starts at the point of such that corresponds to , then proceeds with a straight-line segment to the point of such that corresponds to , then proceeds with a straight-line segment to the point of such that corresponds to , and so on until reaching the point of such that corresponds to .
The proof that an upward planar drawing of can be constructed from a level planar drawing of is analogous. In particular, now represents the left-to-right order in which the vertices of and the edges of crossing the line appear along such a line. This order is used so to define a sequence of points along the horizontal line through the vertices of in . Such points are used to represent each edge as a sequence of straight-line segments.
The first NP-hardness result is a direct consequence of reduction (i) from Lemma 4 and of the NP-completeness of Ordered Level Planarity [26].
Theorem 3.1.
*The UPE problem is NP-complete even if
(i) the partial graph contains all the vertices and no edges and
(ii) no three vertices share the same -coordinate in the partial drawing.
Proof.
The membership of UPE in NP follows from Lemma 3. Klemz and Rote proved the NP-hardness of the OLP problem even for ordered level graphs such that consists of a set of disjoint paths and assigns at most vertices to any level [26]. Thus, by applying reduction (i) of Lemma 4 to an instance of the OLP problem with the above properties, we obtain in linear time an equivalent instance of the UPE problem such that and such that no three vertices share the same -coordinate in . This completes the proof.
Lemma 2, together with Theorem 3.1, implies the following.
Corollary 1.
*The UPE problem is NP-complete even if
(i) the partial graph contains all the vertices and
(ii) no two vertices share the same -coordinate in the partial drawing.
We now discuss the complexity of the UPE-FUE problem, in which the input graph comes with a prescribed upward embedding which the required drawing has to respect. We establish the NP-hardness of the UPE-FUE problem via a reduction from the Partial Level Planarity (for short, PLP) problem, recently introduced by Brückner and Rutter [9]. This reduction is quite involved and requires a new analysis of some results in [9].
Given a -tuple where is a level planar graph, is a subgraph of , and is a level planar drawing of , the PLP problem asks whether a level planar drawing of exists that coincides with when restricted to the vertices and edges of . The instance is proper if is a proper level graph.
A proper instance of the PLP problem can also be represented as a triple , where is a set of total orders of such that, for any two vertices , we have that if and only if precedes along the horizontal line with equation . Then, admits a level planar drawing that extends if and only if admits a level planar drawing in which the order of the vertices in along is a linear extension of , for .
Brückner and Rutter [9] proved that the PLP problem is NP-complete even for instances that are proper and connected. Since the reduction they present does not exploit changes of the planar embedding in the produced instances, this allows them to further augment such instances to subdivisions of triconnected graphs, which have a unique planar embedding (up to a flip). Therefore, the PLP problem is NP-complete even for proper instances in which the planar embedding of the level graph is prescribed.
We claim that the hardness result of Brückner and Rutter holds even when the upward embedding of the level graph is prescribed. The basic building blocks of their reduction are two gadgets: The plug and the socket gadgets, which are illustrated in Fig. 6. The plug gadget is simply a directed path consisting of three monotone paths , , and that traverse several levels of the level graph. The vertices of the plugs are not subject to any ordering constraints, that is, there exists no ordering in such that or and . The socket gadget consists of a left-boundary path consisting of two monotone paths and , and of a right-boundary path , consisting of two monotone paths and , all traversing several levels of the level graph. The vertices in are totally ordered by the functions , for each level traversed by such paths; in particular, the left-to-right order of the predecessors of and the left-to-right order of the successors of is prescribed. The crucial property exploited throughout the constructions presented in [9] is that at most one plug can be placed between the left- and the right-boundary paths of a socket, in every level-planar drawing of the input level graph that realizes the prescribed orders of the vertices on each level. Our Claim 2 below then follows by observing that in the edges and appear in this left-to-right order and similarly for the edges and . We thus have the following.
Claim 2**.**
*The PLP problem is NP-complete even for proper instances such that is connected and has a prescribed upward embedding. *
We exploit Claim 2 in order to prove the following.
Theorem 3.2.
*The UPE-FUE problem is NP-complete. This result holds even if
(i) the instance is connected and
(ii) the partial graph contains all the vertices and no edges.
Proof.
The membership of the UPE-FUE problem in NP follows from Lemma 3.
Let be a proper instance of the PLP problem such that is a connected level graph with a prescribed upward embedding. We show how to construct in polynomial time an equivalent instance of the UPE-FUE problem satisfying properties (i) and (ii) of the statement. Refer to Fig. 7.
The graph is defined as follows. For each vertex of , the graph contains vertices and and an edge . Further, for each edge in , the edge set of contains an edge . The graph is connected, since is connected, which implies property (i). We set the upward embedding of as follows. For each vertex of such that and , we set , , , and .
The graph is defined as , which implies property (ii).
Finally, the drawing of is defined as follows. Since contains no edges, in order to construct we only need to assign a position to each vertex of .
For , let be the subset of vertices of level of whose left-to-right order is fixed by , and let be the vertices of . Also, let be the vertices in (whose left-to-right order is not prescribed by ). Let and .
First, for and for , we place the vertex at the point and the vertex at the point . Second, for , we place the vertex at the point and the vertex at the point . Observe that all the vertices of stemming from vertices in lie above the horizontal line and below the horizontal line . This concludes the construction of the instance , which can be carried out in polynomial time in the size of .
We now prove that and are equivalent.
For the first direction, suppose that the instance of the UPE-FUE problem is positive, that is, there exists a drawing of that extends and respects its prescribed upward embedding. We show how to construct a level planar drawing of that respects its prescribed upward embedding and such that the order of the vertices in along the horizontal line is a linear extension of , for .
We construct as follows; refer to Fig. 8. For and for each vertex , let be the crossing point between the edge and in . Observe that such a crossing point exists since and lie below and above , respectively, in (and thus in ), by construction. We place the vertex at in . We modify the drawings of the edges of incident to and as follows. We delete the parts of inside disks with radius centered at and ; if is sufficiently small, only , , and parts of their incident edges are deleted from . We extend the edges that used to be incident to and downwards and upwards, respectively, following the drawing of the edge in sufficiently close to it, until they reach . Finally, we delete the rest of the drawing of the edge . Repeating this process for every vertex of results in a drawing of .
We have that is a level drawing. Namely, each edge of is represented in by a -monotone curve, given that the edge of is represented in by a -monotone curve and given that the parts of the representation of in that do not coincide with the representation of follow the -monotone curves representing the edges and . Further, by construction, for , the vertices of the level lie on the horizontal line with equation . Hence, after a change of the coordinate system which maps any point to the point , we have that is a level drawing. The drawing is also planar, given that is planar and given that, for each edge of , the parts of the representation of in that do not coincide with the representation of in follow the crossing-free curves representing the edges and .
We now show that respects the prescribed upward embedding of . Consider any vertex of and let . By construction, the left-to-right order in of the edges outgoing at is if and only if the left-to-right order in of the edges outgoing at is . Further, the left-to-right order in of the edges outgoing at is indeed , given that and given that respects the prescribed upward embedding of . Analogously, the left-to-right order of the edges incoming at each vertex of in corresponds to the prescribed order of the adjacent predecessors of .
Finally, we show that the ordering of the vertices in along is a linear extension of , for . Recall that each vertex has been placed at the point in . Hence, it suffices to show that appear in this left-to-right order along in , which follows from the fact that the vertices appear in this left-to-right order along the horizontal line , that the vertices appear in this left-to-right order along the horizontal line , and that the edges are drawn as non-crossing -monotone curves in .
For the second direction, suppose now that is a positive instance of the PLP problem, that is, there exists a level planar drawing of that respects its prescribed upward embedding and such that the left-to-right order of the vertices in along the horizontal line is a linear extension of , for . We show how to construct an upward planar drawing of that extends and that respects its prescribed upward embedding.
First, we change the coordinate system in so to map any point to the point . Now the vertices of lie on the horizontal line . For and for each vertex , let be the point along the vertex lies upon in . For , let be the left-to-right order of the vertices in as they appear along in . The proof is based on the following claim.
Claim 3**.**
*There exists a drawing of the edges of such that extends and such that each edge intersects at . *
Proof.
First, we initialize . Then, for each and for each vertex in , we draw the edge as a -monotone curve composed of the straight-line segments and . We prove that is crossing-free. First, for any two vertices and with , the edges and are vertically disjoint. Second, for any two vertices , the straight-line segments and are vertically disjoint, as well as the straight-line segments and . Finally, the straight-line segments and do not cross since and have the same -coordinate, since and have the same -coordinate, and since the -coordinate of is smaller than the one of if and only if the -coordinate of is smaller than the one of ; similarly, the straight-line segments and do not cross.
In order to complete , it remains to draw each edge , with . To this aim, we process the vertices in in the order they appear in . When we process a vertex , we draw the edge as a -monotone curve passing trough , without introducing any crossings in ; this is done so to maintain the invariant that in there exists a region that satisfies the following properties (refer to Fig. 9):
- (i)
is delimited from below and from above by and , respectively, and from the left and from the right by -monotone curves and that extend from to , respectively; 2. (ii)
for every unprocessed vertex , the region contains in its interior , , and ; and 3. (iii)
the region does not contain in its interior any part of an edge , for any processed vertex .
Let be the currently processed vertex. The edge is drawn as a -monotone curve lying inside and composed of eight parts. The first part of starts from and approaches by moving left while slightly and monotonically increasing in the -coordinate. The second part of follows , slightly to the right of it, until reaching a point slightly lower than the line . The third part of approaches a point from which is visible while slightly and monotonically increasing in the -coordinate. The fourth part of is a straight-line segment reaching . The fifth part , the sixth part , the seventh part , and the eighth part are symmetric to , , , and , respectively. Property (i) of ensures that can be drawn as a -monotone curve. Properties (ii) and (iii) ensure that this can be done without introducing crossings in .
The new region is delimited from the right by the same -monotone curve as the old region ; the new -monotone curve delimiting from the left is composed of and of the straight-line vertical segments connecting and with and , respectively. The new region satisfies Properties (i)–(iii); in particular, for every unprocessed vertex , the new region contains in its interior and , provided that and are sufficiently close to the -monotone curve delimiting the old region , and contains in its interior , given that is to the left of , by the definition of . This concludes the proof of the claim.
For , denote by the intersection point of an edge of directed from a vertex of the level to a vertex of the level with the line in . For each , consider the left-to-right order of the intersection points of the edges directed from the vertices of the level to the vertices of the level with the line in . The The sequence has the following properties:
- (1)
For any vertex , the intersection points of the edges exiting with the line are consecutive in . This follows from the fact that is a level planar drawing. 2. (2)
Let be the left-to-right order of the edges exiting as they appear in the upward embedding of ; then appear in this left-to-right order in . This is due to the fact that respects the upward embedding of . 3. (3)
For any two vertices such that , the intersection points of the edges exiting precede the intersection points of the edges exiting in . This is due to the fact that is a level planar drawing and that the left-to-right order of the vertices in in along is a linear extension of .
We obtain a drawing of from by drawing, for each edge of where and , the edge of as a -monotone curve between and passing trough . As in the previous direction, such curves can be drawn so that no two of them intersect, except possibly at common endpoints, by processing the edges directed from the vertices in to the vertices in in the left-to-right order in which they cross (that is, according to the sequence of their crossing points with such a line). We have that is a drawing of that extends . Further, Claim 3 and Properties (1) and (3) guarantee that is upward planar. Finally, Property (2) guarantees that respects the upward embedding of . This concludes the proof of the theorem.
Lemma 2, together with Theorem 3.2, implies the following.
Corollary 2.
*The UPE-FUE problem is NP-complete even if
(i) the partial graph contains all the vertices and
(ii) no two vertices share the same -coordinate in the partial drawing.
We conclude this section by proving that the UPE problem is solvable in almost-linear time for instances in which the partial graph contains all the vertices and no edges, and no two vertices share the same -coordinate in the partial drawing.
Theorem 3.3.
The UPE problem can be decided in time for instances such that has vertices, , and no two vertices share the same -coordinate in .
Proof.
By applying reduction (ii) of Lemma 4 to the instance of the UPE problem, we obtain in time an equivalent instance of Ordered Level Planarity in which each level contains exactly one vertex. As observed by Klemz and Rote [26] such instances of Ordered Level Planarity are solvable in time, as a consequence of the fact that the Level Planarity problem can be solved in time [21].
4 Upward Planar -Graphs
In this section we study the UPE and UPE-FUE problems for upward planar -graphs. The following lemma will be useful for our algorithms.
Lemma 5 ().
Let be an -vertex upward planar -graph with a given upward embedding. There exists a data structure to test in time, for any two vertices and of , whether , , , or . Further, such a data structure can be constructed in time.
Proof.
First, we construct the transitive reduction of , that is, the upward planar -graph obtained from by removing all its transitive edges. This can be done in time by examining each face of ; indeed, an edge of an upward planar -graph is transitive if and only if at least one of the two paths that connect and , that delimit the faces the edge is incident to, and that are different from the edge is monotone.
Next, we show that can be used in place of in order to answer the desired queries.
Claim 4**.**
*For each vertex of (and of ), we have , , , and . *
Proof.
If , then , as is a subgraph of . Conversely, if , then consider the longest monotone path from to in ; such a path also belongs to , hence . This proves that ; the proof that is analogous.
Assume that ; hence, lies to the left of the monotone path composed of and . Since is the leftmost incoming path of in , all the monotone paths that replace transitive edges of in order to define lie to the right of the monotone path composed of and in . Analogous arguments apply to . Thus, lies to the left of the monotone path composed of and , hence .
Conversely, assume that and suppose, for a contradiction, that , as in Fig. 10. It follows that there is a transitive edge of such that: (i) and both belong to or both belong to – assume the former, as the latter case can be treated analogously; (ii) the edge lies to the left of the monotone path composed of and in ; and (iii) lies inside the (undirected) cycle of delimited by the edge and by the monotone path between and in . Consider any longest incoming path of in and any longest outgoing path of in . Since these are longest paths, they also belong to . Further, since they are incident to and , respectively, they share vertices with . In particular, the subpaths of and that are incident to and whose edges are inside determine a monotone path between two vertices of that is to the left of the monotone path composed of and . This contradicts the fact that is the leftmost incoming path of in and hence proves that . It follows that .
The proof that is symmetric.
We now compute a dominance drawing of . A dominance drawing of a directed graph is a straight-line drawing such that there is a monotone path from a vertex to a vertex if and only if and . Di Battista et al. [17] presented an -time algorithm to construct a planar dominance drawing of an -vertex upward planar -graph without transitive edges. The dominance drawings constructed by the cited algorithm satisfy the following properties: (i) if and only if ; and (ii) if and only if .
We use the algorithm by Di Battista et al. [17] in order to construct . Then, in order to query whether , it suffices to check whether and in . The other queries can be similarly answered in time.
We now characterize the positive instances of the UPE-FUE problem.
Lemma 6 ().
An instance of the UPE-FUE problem such that is an upward planar -graph with a given upward embedding and such that contains no edges is a positive instance if and only if:
Condition 1:
For each vertex of , all its successors (predecessors) in that belong to have a -coordinate in that is larger (smaller) than ; and
Condition 2:
For each vertex of , all the vertices of whose -coordinate is the same as and whose -coordinate is larger (smaller) than in are to the right (to the left) of in .
Proof.
Concerning the necessity of Condition 1, assume that two vertices and exist in such that contains a monotone path from to and such that the in . Then cannot be upward in any drawing of extending . Concerning the necessity of Condition 2, assume, for a contradiction, that two vertices and of exist such that: (i) and in ; and (ii) . If , then a monotone path from to cannot be upward in any drawing of extending . Analogously, . Finally, if , then consider any vertex such that there are two edge-disjoint monotone paths and from to and from to , respectively. Such paths can be found by considering any two monotone paths from to and from to , and by truncating these paths at their first common vertex; since and , we have . Since , the left-to-right order of the edges entering in is: The edge of first and the edge of second. However, since and , the left-to-right order of the edges entering in any upward planar drawing of extending is: The edge of first and the edge of second. This contradiction proves the necessity of Condition 2.
To prove the sufficiency we construct an upward planar drawing of that extends .
We first augment by drawing every vertex , so that Conditions 1 and 2 are still satisfied after the augmentation. This is done by assigning to any -coordinate and a -coordinate such that: (i) , for any vertex with ; (ii) , for any ; and (iii) , for any . We show how to construct such an assignment.
We consider the vertices in one at a time. When a vertex is considered, some of its successors in might be already drawn in ; denote by the set of such vertices. Analogously, let be the set of the predecessors of that are already drawn in . Each vertex in has a -coordinate in that is larger than the -coordinate of any vertex in ; namely, since is a successor of and since is a predecessor of , it follows that is a successor of and then Condition 1 ensures that in . We place at any point that is higher than all the vertices in , that is lower than all the vertices in , and whose -coordinate is different from all the other vertices of . Clearly, Conditions 1 and 2 are still satisfied by the new instance. After repeating this augmentation for all the vertices in , we eventually get that and the instance still satisfies Conditions 1 and 2.
Now set . We are going to draw the edges of in ; we start with the edges of the leftmost path of (see Fig. 11(a)). We draw each edge of as follows. If there is no vertex such that , then we draw as a straight-line segment. Otherwise, we draw as a polygonal line composed of three straight-line segments: The first one connects with a point whose -coordinate is slightly larger than and whose -coordinate is smaller than the one of every vertex of in ; the second one is a vertical straight-line segment connecting with a point whose -coordinate is slightly smaller than ; the third one connects with . By construction all the vertices of not in are to the right of in .
Now the algorithm proceeds in steps. After each step we maintain the invariants that: (i) the subgraph of currently drawn consists of an upward planar -graph plus a set of isolated vertices; (ii) the current drawing of in is upward planar; and (iii) the rightmost path of is represented by a -monotone curve such that all the isolated vertices lie to the right of in , when traversing from to .
The invariants are initially satisfied with and with the drawing constructed as above. In each step we consider a face of whose left boundary belongs to and whose right boundary consists of edges not in . In order to draw the right boundary of , we draw each edge independently (see Fig. 11(b)). We draw as a polygonal line composed of three parts. The first part is a straight-line segment connecting with a point whose -coordinate is slightly larger than and whose -coordinate is slightly larger than the -coordinate of the point of the left boundary of with the same -coordinate. The second part is a polygonal line arbitrarily close to the left boundary of , connecting with a point whose -coordinate is slightly smaller than . The third part is a straight-line segment connecting with . Invariant (i) is maintained by the choice of the face . Invariant (ii) is maintained since, for each , we have in , by Condition 1, and since the drawing of is upward and does not cross any previously drawn edge, by construction. Invariant (iii) is maintained since each edge is arbitrarily close to the drawing of the rightmost path of , except in the interior of arbitrarily narrow horizontal strips enclosing and ; further, does not keep any isolated vertex to its left inside such strips by Condition 2.
By invariant (ii), respects the upward embedding of . Further, by construction, the vertices of have the same coordinates in as in , hence extends .
We can now prove the following algorithmic theorem.
Theorem 4.1 ().
The UPE-FUE problem can be solved in time for instances with size such that is an upward planar -graph with a given upward embedding.
Proof.
If contains edges, then Lemma 1 can be applied in time in order to transform into an equivalent instance, which we again denote by , such that , such that contains no edges, and such that is still an upward planar -graph. We show an -time algorithm to test whether Conditions 1 and 2 of Lemma 6 are satisfied by .
In order to test Condition 1, we proceed as follows. We construct an auxiliary graph , which we initialize to . We order in time the vertices in according to their -coordinates in , where . Let be such an ordering. For every two maximal sets and of vertices of such that , such that , and such that , we add to a vertex , directed edges , for , and directed edges , for . The graph can be constructed in time and has vertices and edges.
Claim 5**.**
* satisfies Condition 1 if and only if is acyclic. *
Proof.
For the necessity, suppose that Condition 1 holds true; we show that is acyclic. For a contradiction, suppose that a simple directed cycle exists in ; then can be partitioned into monotone paths where all the edges of belong to if is even and all the edges of do not belong to if is odd. Note that, for , the vertex shared by two consecutive paths and belongs to , where . Condition 1 implies that for , where . The construction of implies for . However, this implies that , a contradiction.
For the sufficiency, suppose that is acyclic; we show that Condition 1 holds true. For a contradiction, suppose that two vertices exist such that and such that in . We have that contains a monotone path directed from to as contains all the edges of , and a monotone path directed from to composed of edges not in , hence it contains a directed cycle, a contradiction.
Since has vertices and edges, it can be tested in time whether it is acyclic. By Claim 5 it follows that we can test Condition 1 in time.
In order to test Condition 2, we proceed as follows. We sort each maximal set of vertices in with the same -coordinate according to their -coordinates. For all the vertices of , this can be done in time. Hence, we assume that , for ; then we test whether , for . By Lemma 5, this can be done in -time per query, after an -time preprocessing. Therefore, the total time to test Condition 2 is also .
Next, we deal with the UPE problem. An instance of the UPE problem such that is an upward planar -graph can be transformed into an equivalent instance of the PLP problem. This is due to the fact that Condition 1 of Lemma 6 does not depend on the upward embedding of and that we can assume:
the edges set of to be empty, by Lemma 1; and 2. 2.
the partial drawing to contain all the vertices of , by drawing each vertex in as in the proof of Lemma 6, without violating neither Condition 1 nor Condition 2 of the lemma.
Hence, the UPE problem for upward planar -graphs can be solved in quadratic time, due to the results of Brückner and Rutter about the PLP problem for single-source graphs [9]. However, in the following theorem we show how to reduce the time bound to almost linear.
Theorem 4.2 ().
The UPE problem can be solved in time for instances with size such that is an upward planar -graph.
Proof.
We are going to test whether an upward embedding of exists that satisfies the conditions in Lemma 6. Actually, Condition 1 does not depend on the upward embedding of , hence it can be tested in time as described in the proof of Theorem 4.1 before any upward embedding of is considered. If the test succeeds, we apply Lemma 1 in time to modify so that contains no edges while remains an upward planar -graph, and proceed as described in the following, otherwise we conclude that the instance is negative.
In order to test whether admits an upward embedding satisfying Condition 2 of Lemma 6 we proceed as follows. First, we add the edge to , if does not contain such an edge. Second, we compute in time the SPQR-tree of . Third, we compute in time the order of the vertices in by increasing -coordinates and, secondarily, by increasing -coordinates in .
We now aim to decide a left-to-right order of the virtual edges of the skeleton of each P-node of and a flip for the triconnected skeleton of each R-node of so that Condition 2 is satisfied. We outline the approach for such decisions. Consider two vertices and sharing their -coordinate. Note that in . Then has to belong to in the upward embedding of we look for. This imposes a constraint on for a node of such that and are in the pertinent graphs of two different virtual edges and of . Namely, if is a P-node, then has to precede in the left-to-right order of the virtual edges of . Further, if is an R-node, then has to be to the left of in the chosen embedding of . To impose these constraints, we employ several algorithmic tools; e.g., we compute in time the proper allocation nodes and of and in , and the lowest common ancestor of and in . This approach is detailed as follows.
We compute the following data structures.
We equip each P-node of with an auxiliary directed graph containing a vertex for each virtual edge of , except for the one corresponding to the parent of in . The edge set of is initially empty. 2. 2.
The skeleton of each R-node of is triconnected, hence it admits two upward embeddings, which can be obtained from each other via a flip. We arbitrarily choose one of these upward embeddings. We equip with a data structure that, given a pair where and are vertices or edges of , determines in time whether , , or none of the previous, in the chosen upward embedding of . Such a data structure can be constructed in time, as in Lemma 5, by inserting a dummy vertex on each virtual edge in order to handle the fact that queries might involve vertices but also virtual edges of . Further, we equip with two boolean variables and that we both initially set to false.
We execute the following algorithm.
We consider each pair of vertices with the same -coordinate that are consecutive in the computed order. Note that in . We perform the following operations, which ensure that in the upward embedding of constructed by the algorithm, if any.
- (a)
We compute in time the proper allocation nodes and of and in , respectively. 2. (b)
We compute in time the lowest common ancestor of and in . Let and be the representatives of and in , respectively. 3. (c)
We perform different operations depending on the type of .
- i.
If , , , or , then we reject the instance. 2. ii.
If is an S-node, then we reject the instance. 3. iii.
If is a P-node, then we add in time a directed edge in from the vertex corresponding to to the vertex corresponding to . 4. iv.
If is an R-node, then we query in time the data structure has been equipped with. If , then we set true. If , then we set true. If and , then we reject the instance. 2. 2.
For each P-node of , we test whether contains a directed cycle. In case of a positive answer, we reject the instance. 3. 3.
For each R-node of , we test in time whether true and true. In case of a positive answer, we reject the instance. 4. 4.
We accept the instance.
We analyze the running time of the algorithm. Step 1 takes time for each pair , hence time in total. Step 2 takes, for each node , time proportional to the number of the edges that are inserted in . Over all the P-nodes of , at most edges are inserted in the auxiliary graphs , namely at most one for each pair . Thus the overall time complexity of Step 2 is . Step 3 takes time for each R-node, hence time in total. Finally, Step 4 takes time. Hence, the total running time is dominated by the sorting of the vertices in and the algorithm runs in time.
Finally, we argue about the correctness of the algorithm.
Consider step 1.(c)i. If or coincides with or , then Condition 2 is not satisfied by any upward embedding of , as and do not have any vertices to their left or to their right in any upward embedding.
Consider step 1.(c)ii. If is an S-node, then four cases are possible. If and , as in Fig. 12(a), then and are two distinct virtual edges of . Further, if and , as in Fig. 12(b) (the case in which and is symmetric), then is a vertex of and is a virtual edge of . Finally, if and , as in Fig. 12(c), then and are distinct vertices of . In all cases, we have that either or , hence Condition 2 is not satisfied in any upward embedding of .
Consider step 1.(c)iii. If is a P-node, then and are two virtual edges of . In fact if, say, were a vertex of , then it would also be a vertex of the skeleton of the parent of in ; hence, its proper allocation node would be a proper ancestor of , thus contradicting the fact that is the lowest common ancestor of the proper allocation nodes of and in . The insertion of the directed edge in from the vertex corresponding to to the vertex corresponding to enforces in the upward embedding of that is constructed by the algorithm, if any.
Consider step 1.(c)iv. If is an R-node, then four cases are possible, as for an S-node. In all of them we check whether the arbitrarily chosen upward embedding of ensures that (then setting true ensures that such an embedding of is the one in the upward embedding of that is constructed by the algorithm, if any), whether flipping the arbitrarily chosen upward embedding of ensures that (then setting true ensures that such an embedding of is flipped in the upward embedding of that is constructed by the algorithm, if any), or whether is not obtained by any choice of the embedding of , since or ; see Fig. 12(d).
Consider step 2. If a directed cycle is detected in , for some P-node , then the left-to-right order of the pertinent graphs of the virtual edges of in any upward embedding of does not satisfy all the constraints stemming from the left-to-right order of the vertices of sharing the same -coordinate in ; see Fig. 12(e).
Consider step 3. If there is an R-node with true and true, then no flip of allows us to construct an upward embedding of satisfying Condition 2. For example, in Fig. 12(f) the pair forces the upward embedding of to be the one shown in the illustration, given that in such an embedding; however the pair forces the upward embedding of not to be the one shown in the illustration, given that .
Finally, consider step 4. In order to prove its correctness, we construct an upward embedding of satisfying Condition 2; this is done as follows. For each R-node of , if true, then we flip the arbitrarily chosen upward embedding of , otherwise we keep it as it is. For each P-node in , we select a total order for the virtual edges of corresponding to children of in that extends the partial order given by . Finally, if was not originally in , then we remove it. This leads to an upward embedding satisfying Condition 2 of Lemma 6.
5 Directed Paths and Cycles
In this section we study the upward planarity extension problem for instances such that is a directed path or cycle. Determining the time complexity of the UPE and UPE-FUE problems for such instances, despite the simplicity of their structure, has proved to be very challenging. However, in the following we exhibit polynomial-time decision algorithms for the cases in which does not contain edges and no two vertices share the same -coordinate in . We start with the UPE-FUE problem for directed paths.
Theorem 5.1 ().
The UPE-FUE problem can be solved in time for instances such that is an -vertex directed path with a given upward embedding, contains no edges, and no two vertices share the same -coordinate in .
Proof.
Let . We show a decision algorithm for the UPE-FUE problem employing dynamic programming. The idea is to decide whether is a positive instance of the UPE-FUE problem based on whether the subpaths of admit upward planar extensions with given upward embedding.
In particular, we fill a table with entries , for all the indices such that and , with and . Consider the subpath of . Let be the restriction of to the vertices that belong to . The entry has value true if there is an upward planar drawing of that extends and such that and are the vertices with the smallest and largest -coordinate in , respectively; the entry has value false otherwise.
We start by computing the entries such that is a monotone path; these include the entries . Assume that the edge of is outgoing , the other case is symmetric. Then true if and only if the following conditions are satisfied: (1) ; (2) ; and (3) for any two indices and such that and such that , we have in .
Assume now that is not a monotone path and that the values of all the entries such that have been computed, for some . After the computation of the entries such that is a monotone path, this is indeed the case with . We compute the values of the entries such that . We distinguish three cases, based on how many of the equalities , , , and are satisfied, that is, based on how many vertices among and are end-vertices of . Refer to Fig. 13.
Suppose first that neither nor is an end-vertex of . Recall that ; in fact, assume that , the case in which can be treated symmetrically. We have the following.
Claim 6**.**
* true if and only if there exist indices and such that the following conditions hold true:*
- (1)
* true;* 2. (2)
* true;* 3. (3)
* true;* 4. (4)
either does not belong to or has the smallest -coordinate among the vertices in ; and 5. (5)
either does not belong to or has the largest -coordinate among the vertices in .
Proof.
We first prove the necessity. Suppose that true, hence an upward planar drawing of exists that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. Restricting to the vertices and edges of yields an upward planar drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively, which proves Condition (2). Let be the vertex of with the largest -coordinate in . Then restricting to the vertices and edges of yields an upward planar drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively, which proves Condition (1). The proof of Condition (3) is analogous. By assumption is the vertex with the smallest -coordinate in , hence Condition (4) follows, given that extends . Condition (5) is proved analogously.
The proof of the sufficiency is more involved. By Conditions (1)–(3) there exist upward planar drawings , , and of , , and extending , , and in which the vertices with the smallest and largest -coordinate are and , and , and and , respectively, for some and . We are going to glue together these drawings in order to construct an upward planar drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. However, before doing so, we need to perform some modifications on , , and , while not altering the positions of the vertices of , , and , respectively.
The first set of modifications aim to establish that:
- (i)
is at the same point in and in , and it has the smallest -coordinate among all the vertices in , , and ; and 2. (ii)
is at the same point in and in , and it has the largest -coordinate among all the vertices in , , and .
Note that is the vertex with the smallest -coordinate in both and , however there might be a vertex in whose -coordinate is smaller than or equal to . A similar problem might occur for .
- •
If , then let be the smallest -coordinate of any vertex in , , or . Let , where and are real numbers such that . Let be smaller than the vertical distance between any two vertices in , , and . We modify as follows. We delete the part of inside a disk with radius centered at . Since is an upward drawing, since is the vertex with the smallest -coordinate in , and by the choice of , only and part of the edge is deleted from . We place at . We extend the part of the edge still in downwards, until it reaches a -coordinate smaller than and larger than , and then we connect it to . We perform an analogous modification of .
- •
If , as in Fig. 14, then is at the same point in and , as such a point belongs to and . Let be a real number larger than and smaller than the -coordinate of any vertex in . Such a real number exists by Condition (4). Vertically scale down the part of in the half-plane , while keeping fixed the points on the line . As long as the scale factor is sufficiently small, the entire drawing lies above the line after the scaling.
The drawings , , and can be modified analogously in order to accomplish property (ii) above.
Gluing together , , and results in an upward drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. However, two problems arise. First, might contain crossings; indeed, while each of , , and is planar, two edges from different graphs among , , and might cross each other. Second, the left-to-right order of the edges outgoing at in might not correspond to and the left-to-right order of the edges incoming at in might not correspond to .
We show that both these problems can be overcome by redrawing the curves representing the edges of , , and , while leaving the position of every vertex unaltered. Refer to Fig. 15. Assume first that and .
Let the vertices of be placed as in . Let and be the horizontal lines through and . Let be the horizontal strip delimited by and . Let be a -monotone curve that connects with a point of , that does not pass through any vertex of other than , and such that the part of to the left of contains in its interior all the vertices of and no vertex of . Analogously, let be a -monotone line that connects with a point of , that does not pass through any vertex of other than , that does not intersect , and such that the part of to the right of contains in its interior all the vertices of and no vertex of . It is easy to see that such lines and exist; in particular, notice that there is no constraint on how these lines might intersect the edges of in .
The lines and partition into three regions: one unbounded region to the left of , one bounded region between and , and one unbounded region to the right of . Notice that , , and contain in their interiors all the points at which the vertices of , , and are placed in , respectively, except for the vertex which is on the common boundary of and , and for the vertex which is on the common boundary of and . We now redraw the edges of , , and in the interiors of , , and , respectively.
We construct an upward planar drawing of inside by modifying via a homeomorphism of the plane which does not alter the positions of the vertices of . More precisely, this can be done as follows. Let be the minimum horizontal distance between a vertex of different from and . Let be the translation of by to the left. Delete the part of to the right of , except for the vertex . Now any -monotone curve that has been deleted from and that used to connect two points and on can be replaced by a -monotone curve that connects and and that lies to the right of , except at and , and to the left of . The end-points of any two such curves do not alternate along , given that is planar, hence all such curves can be drawn without intersections. The curves that used to connect a point with can be similarly redrawn to the right of , except at , and to the left of , except at .
A similar modification allows us to construct an upward planar drawing of inside and an upward planar drawing of inside . Since the interiors of these regions are disjoint, the edges of two different graphs among , , and do not intersect, except for the edges and , which intersect at , and for the edges and , which intersect at . Further, the left-to-right order of the edges outgoing at is , which corresponds to , and the left-to-right order of the edges incoming at is , which corresponds to . The drawing obtained as the union of the constructed drawings of , , and is hence the desired drawing of .
If and , the construction is symmetric. In particular, is defined as before, except that the part of to the right (and not to the left) of contains in its interior all the vertices of and no vertex of , and the part of to the left (and not to the right) of contains in its interior all the vertices of and no vertex of .
If and , then is defined as in the case in which and . However, the definition of is now slightly different. Indeed, is now a -monotone line that connects with (and not just with any point of ), that does not pass through any vertex of other than and , that does not intersect , except at , and such that the part of to the right of contains in its interior all the vertices of and no vertex of or . The rest of the construction is analogous to the previous cases.
Finally, if and , then the construction is symmetric to the case in which and .
This completes the proof of the claim.
Suppose next that one of and is an end-vertex of , while the other one is not. Assume that , the cases in which , , or can be treated analogously. Recall that , hence . We have the following.
Claim 7**.**
* true if and only if there exists an index such that the following conditions hold true:*
- (1)
* true;* 2. (2)
* true; and* 3. (3)
either does not belong to or has the smallest -coordinate among the vertices in .
Proof.
The proof is very similar to (and in fact simpler than) the proof of Claim 6.
Consider an upward planar drawing of in which and are the vertices with the smallest and largest -coordinate, respectively. Restricting to the vertices and edges of (of ) provides an upward planar drawing of (resp. of ) extending (resp. ) in which the vertices with the smallest and largest -coordinate are and (resp. and , for some ). This proves the necessity of Conditions (1) and (2). The property that is the vertex with the smallest -coordinate in implies the necessity of Condition (3).
In order to prove the sufficiency we start from upward planar drawings and of and extending and in which the vertices with the smallest and largest -coordinate are and , and and , respectively, for some . These drawings exist by Conditions (1) and (2). We then modify and/or so that the following properties hold true:
- (i)
is at the same point in and ; and 2. (ii)
has the smallest -coordinate among all the vertices in and .
In order to accomplish property (ii) we act as follows. Let be a real number larger than and smaller than the -coordinate of any vertex in . Such a real number exists by Condition (3). Vertically scale down the part of in the half-plane , while keeping fixed the points on the line . As long as the scale factor is sufficiently small, the entire drawing has a -coordinate larger than after the scaling. The satisfaction of property (i) does not require any modifications to and if ; on the other hand, if , then and parts of its incident edges in and are redrawn so to let be at the same point in and .
Now gluing together and results in an upward drawing of that extends in which and are the vertices with the smallest and largest -coordinate, respectively. However, might contain crossings and the left-to-right order of the edges incoming at in might not correspond to . Hence, we redraw the curves representing the edges of and , while leaving the position of every vertex unaltered. This is done by defining two internally-disjoint regions and that are separated by a -monotone curve through and that contain in their interiors the points at which the vertices of and are placed in , except for which is on the boundary of both such regions; whether is to the left or to the right of depends on whether or , respectively. We redraw the edges of and inside and , respectively. The drawing obtained as the union of the constructed drawings of and is the desired drawing of . This completes the proof of the claim.
Suppose finally that both and are end-vertices of . Assume that and , the other case is symmetric. We have the following.
Claim 8**.**
* true if and only if there exist indices and such that the following conditions hold true:*
- (1)
* true;* 2. (2)
* true;* 3. (3)
* true;* 4. (4)
either does not belong to or has the smallest -coordinate among the vertices in ; 5. (5)
either does not belong to or has the largest -coordinate among the vertices in ; and 6. (6)
either and , or and .
Proof.
We first prove the necessity. Suppose that true, hence an upward planar drawing of exists that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. Since is not a monotone path, there exist internal vertices of which are sinks. Among all these vertices, let be the one with the largest -coordinate in . Further, since and are both sinks in (note that if were not a sink, then an upward drawing of in which is the vertex with the largest -coordinate would not exist), there exist internal vertices of which are sources. Among all these vertices, let be the one with the smallest -coordinate in . Note that and .
Restricting to the vertices and edges of yields an upward planar drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. In particular, no vertex of has a -coordinate larger than , as otherwise the sink such that there is a monotone path from to in (possibly such a path is a single vertex if is a sink itself) would have a -coordinate larger than , contradicting the choice of . This proves Condition (1); the proofs of Conditions (2) and (3) are analogous. By assumption is the vertex with the smallest -coordinate in , hence Condition (4) follows, given that extends . Condition (5) is proved analogously.
In order to prove the necessity of Condition (6) suppose, for a contradiction, that and (the case in which and can be treated analogously). Refer to Fig. 16. Let and be the horizontal lines passing through and in , respectively. Since , it follows that crosses . Order the crossing points between and as they are encountered when walking along from to and let be the last point in this order. Analogously, let be the crossing point between and that is encountered last when walking along from to . Thus the part of connecting with entirely lies in the strip delimited by and (note that does not cross or , since is the source with the smallest -coordinate and is the sink with the largest -coordinate in ). Let be the closed curve composed of the part of between and (this includes ) and of the part of between and . Since , since the part of between and lies in , and by the planarity of , the points , , and appear in this clockwise order along . Further, since and by the upward planarity of , we have that lies inside in ; on the other hand, is outside in . By the Jordan curve’s theorem, the path crosses . Since the path lies in the half-plane , it does not cross , hence it crosses the part of between and , a contradiction to the planarity of .
The proof of the sufficiency is similar to the ones of Claims 6 and 7. Namely, we start from upward planar drawings , , and of , , and extending , , and in which the vertices with the smallest and largest -coordinate are and , and , and and , respectively, for some and . These drawings exist by Conditions (1)–(3).
We then modify , , and so that the following properties hold:
- (i)
is at the same point in and ; 2. (ii)
is at the same point in and ; 3. (iii)
has the smallest -coordinate among all the vertices in , , and ; and 4. (iv)
has the largest -coordinate among all the vertices in , , and .
The satisfaction of property (i) does not require any modifications to and if ; on the other hand, if , then and parts of its incident edges in and are redrawn (in particular is placed higher than it was in and ) so to let be at the same point in and . Property (ii) is satisfied similarly. If , then Property (iii) can be satisfied by redrawing (lower than every other vertex in , , and ) and part of its incident edge in . If , then a real number larger than and smaller than the -coordinate of any vertex in is chosen, which is possible by Condition (4), and the part of in the half-plane is vertically scaled down, while keeping fixed the points on the line . As long as the scale factor is sufficiently small, the entire drawing lies above the line after the scaling. Property (iv) is ensured analogously exploiting Condition (5).
Gluing together , , and results in an upward drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. However, might contain crossings, the left-to-right order of the edges incoming at in might not correspond to , and the left-to-right order of the edges outgoing from in might not correspond to . Hence, we redraw the curves representing the edges of , , and , while leaving the position of every vertex unaltered. This is done by defining three internally-disjoint regions , , and containing in their interiors the points at which the vertices of , , and are placed in , respectively, except for which is on the boundary of both and , and for which is on the boundary of both and . These regions are delimited by the horizontal lines and through and , and by two -monotone curves and passing through and , respectively, and connecting points on and . The curves and are defined so that the regions , , and appear in this left-to-right order inside the horizontal strip delimited by and in the case in which and , or so that they appear in the opposite left-to-right order in the case in which and . One of the two cases happens, because of Condition (6). We now redraw the edges of , , and inside , , and , respectively. The drawing obtained as the union of the constructed drawings of , , and is the desired drawing of . This completes the proof of the claim.
Claims 6, 7 and 8 show how to compute the value of the entry , if is not a monotone path, based on the structure of the instance and on the value of the entries with . Eventually the dynamic programming will compute the values of the entries , for all and with ; then the instance of the UPE-FUE problem is positive if and only if at least one of these entries has value true.
We now show how to implement the described algorithm so that it runs in time. Observe that there are entries whose value has to be computed.
We start by computing, for each entry , the smallest and largest -coordinate of a vertex in , if any such a vertex exists. This can be done in time per entry by induction on . Indeed, if , then at most two coordinates have to be compared in order to determine such two values. If , then the two values either coincide with those computed for , if , or are computed by comparing the two values computed for with , if .
The computation of the true-false values for the entries such that is a monotone path is done in time as follows. First, for any pair of integers such that we check whether is a monotone path. There are such pairs of integers; further, for each pair , the monotonicity of can be tested in time by simply checking whether all the edges of are directed from to , or whether they are all directed from to . For each pair such that is monotone and its edges are directed from to (from to ), we give value true to the entry (resp. ) and false to all the other entries ; there are such entries, hence the quartic running time.
We now turn to the computation of the values of the entries such that is not a monotone path. Consider a pair of integers such that , such that the values of the entries have not been determined yet, and such that the values of the entries have been determined for all the pairs of integers such that . There are such pairs .
We perform the following preliminary check. For each index , we check whether any of the entries has value true, over all the indices . There are indices to be considered and for each of them we check the value of entries, hence this takes time for the pair , and hence time over all the pairs . Analogously, we check for each index whether any of the entries has value true, for each index whether any of the entries has value true, and for each index whether any of the entries has value true. This information can be stored in a separate table, whose entries are of the form , , , and .
By means of Claim 6, we now determine the values of the entries such that neither nor is an end-vertex of . For each entry such that (the entries such that are dealt with analogously) we test in time whether Conditions 1–3 are satisfied by checking whether true, whether true, and whether true. Condition 4 can be tested in time by checking whether and, in case it does, whether is the smallest -coordinate among the vertices in – this information was computed at the beginning of the algorithm. Condition 5 can be tested in time analogously.
Next, by means of Claim 7, we determine the values of the entries such that one of and is an end-vertex of . For each entry (the entries , , and are dealt with analogously) we test in time whether Conditions 1–2 are satisfied by checking whether true and whether true. Condition 3 can be tested in time by checking whether and, in case it does, whether is the smallest -coordinate among the vertices in .
Finally, by means of Claim 8, we determine the values of the entries such that both and are end-vertices of . For each entry (the entries are dealt with analogously) we test in time whether Conditions 1–6 are satisfied as follows. First, we test in time whether Condition 4 is satisfied by checking whether and, in case it does, whether is the smallest -coordinate among the vertices in . Condition 5 can be tested in time analogously. In order to test Conditions 1–3 and Condition 6, we consider all the pairs of indices with and . For each such pair we check in time whether true, whether true, whether true, and whether and , or and . Note that there are entries ; for each of them we consider pairs of indices , and then we check the above conditions in time. Thus the total running time is .
By exploiting arguments analogous to those in the proof of Theorem 5.1 we can extend our quartic-time algorithm to cycles.
Theorem 5.2 ().
The UPE-FUE problem can be solved in time for instances such that is an -vertex cycle with given upward embedding, contains no edges, and no two vertices share the same -coordinate in .
Proof.
Let . Suppose that an upward planar drawing of extending exists. Let be the largest -coordinate of a vertex in . Then it can be assumed without loss of generality that there is a unique vertex in such that . Indeed, if more than one vertex has -coordinate equal to in , then at least one vertex exists such that and . Hence can be moved upwards and its incident edges can be extended upwards as well, so that becomes the unique vertex with the largest -coordinate in . It can be analogously assumed that there is a vertex in whose -coordinate is smaller than the one of every other vertex.
Our strategy is to test, for every possible pair of vertices with and with , whether there is an upward planar drawing of extending in which the vertices with the smallest and largest -coordinate are and , respectively. For any pair , the cycle consists of two directed paths connecting and , call them and , where indices are modulo . Let and be the restrictions of to the vertices that belong to and , respectively. The following claim is the key ingredient for the proof of the theorem.
Claim 9**.**
* has an upward planar drawing extending in which the vertices with the smallest and largest -coordinate are and , respectively, if and only if:*
- (1)
* has an upward planar drawing extending in which the vertices with the smallest and largest -coordinate are and , respectively;* 2. (2)
* has an upward planar drawing extending in which the vertices with the smallest and largest -coordinate are and , respectively; and* 3. (3)
either and , or and .
Proof.
Suppose that has an upward planar drawing extending in which the vertices with the smallest and largest -coordinate are and , respectively. Restricting to the vertices and edges of yields an upward planar drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. This proves the necessity of Condition (1). The necessity of Condition (2) is proved analogously. In order to prove the necessity of Condition (3) suppose, for a contradiction, that and (the case in which and can be treated analogously). Let and be the horizontal lines passing through and in , respectively. The path divides the strip delimited by and into two regions and , to the left and to the right of , respectively. Since and , and by the upward planarity of , it follows that and are in and , respectively. Hence, the path crosses the boundary of such regions. Since and have the smallest and largest -coordinate among the vertices in , and by the upwardness of , it follows that does not cross or , hence it crosses , a contradiction to the planarity of .
The proof of the sufficiency is similar to the ones of Claims 6, 7 and 8. Namely, we start from upward planar drawings and of and extending and , respectively, in which the vertex with the smallest -coordinate is and the vertex with the largest -coordinate is . These drawings exist by Conditions (1) and (2).
We then modify and so that the following properties hold:
- (i)
is at the same point in and ; and 2. (ii)
is at the same point in and .
If , then Property (i) is already satisfied by and ; on the other hand, if , then we redraw and parts of its incident edges so to let be at the same point in and . Property (ii) is satisfied analogously.
Gluing together and results in an upward drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. However, might contain crossings. Hence, we redraw the curves representing the edges of and , while leaving the position of every vertex unaltered. This is done by defining two internally-disjoint regions and containing in their interiors the points at which the vertices of and are placed in , respectively, except for and which are on the boundary of both and . These regions are delimited by the horizontal lines and through and , and by a -monotone curve connecting with . The curve is defined so that is to the left of in the case in which and , or so that is to the right of in the case in which and . One of the two cases happens, because of Condition (3). We now redraw the edges of and inside and , respectively. The drawing obtained as the union of the constructed drawings of and is the desired drawing of . This completes the proof of the claim.
From a computational point of view, we act as follows.
First we compute, for every possible pair of vertices with and with , whether there are upward planar drawings of and extending and , respectively, in which the vertex with the smallest -coordinate is and the vertex with the largest -coordinate is . This can be done by considering the -vertex path and by setting up a dynamic programming table with entries , for all the indices such that and , with , , and . The values of the entries of this table can be computed in total time as in the proof of Theorem 5.1.
Now, for each of the pairs of vertices with and with , we exploit Claim 9 in order to check whether has an upward planar drawing extending in which the vertices with the smallest and largest -coordinate are and , respectively. Concerning Conditions (1) and (2), we check in time whether true and true (if ) or whether true and true (if ). Condition (3) can also be trivially checked in time. This concludes the proof of the theorem.
It turns out that directed paths and cycles are much easier to handle in the case in which they do not come with a given upward embedding, as in the next theorem.
Theorem 5.3 ().
The UPE problem can be solved in time for instances such that is an -vertex directed path or cycle, contains no edges, and no two vertices share the same -coordinate in .
Proof.
Suppose first that is a directed path. We partition into monotone paths , for some integer . Assume that the edge is exiting and entering , the other case being symmetric. Then for every odd we have that is a sink, while for every even we have that is a source. Our algorithm is based on the following characterization.
Claim 10**.**
*There exists an upward planar drawing of extending if and only if, for every , , and with such that , it holds true that in . *
Proof.
The necessity is trivial. Indeed, if there are indices , , and with such that and such that , then the monotone path cannot be upward in any drawing of extending .
For the sufficiency, we construct an upward planar drawing of extending by drawing one monotone path at a time. Roughly speaking, this is done by drawing “to the right” of what has been drawn so far. More precisely, for any , consider the path and let the end-vertex of different from be the last vertex of . Denote by the restriction of to the vertices in . We show how to construct an upward planar drawing of that extends and such that the last vertex of is visible from the right (meaning that a half-line starting at the last vertex and directed rightwards does not intersect other than at its starting point). Assume that is odd, the case in which is even is similar. Then is a source and is visible from the right in (the latter condition is vacuously true if ). We proceed similarly to the proofs of Claims 6, 7 and 8. Namely, we consider a -monotone curve passing through , having the vertices in – as they are placed in – to the left (except for ) and the vertices in to the right (except for ). We redraw parts of the edges of so that entirely lies to the left of , except at ; note that this is possible because is visible from the right. If we further modify by moving downwards along and by extending the edge downwards as well (while keeping it to the left of ), so that is smaller than the -coordinate of every vertex different from in . If , then it is the condition of the claim that guarantees that is smaller than the -coordinate of every vertex in . We next construct an upward planar drawing of , possibly intersecting , extending the restriction of to the vertices in . This is done by drawing as a -monotone curve passing through the vertices in and by then placing the vertices in not in at suitable points on this curve. Finally, we redraw parts of the edges of so that entirely lies to the right of , except at . Now there is no crossing between the edges in and those in ; further, is visible from the right. Hence, when this algorithm constructs an upward planar drawing of extending .
The condition in Claim 10 can be easily checked in time. Indeed, each path can be independently traversed from to while keeping track of the -coordinate of the last encountered vertex in : If the -coordinate of any vertex in is smaller than the -coordinate of the previous vertex in , then the condition is not satisfied; vertices not in are ignored.
We now turn our attention to the case in which is a cycle. We again partition into monotone paths , for some integer . Then the characterization stated in Claim 10 applies to this case as well. Whether satisfies the characterization can be checked in time, as for directed paths. The necessity of the characterization can be proved as in Claim 10. The sufficiency can also be proved similarly to Claim 10, however with one more ingredient. Namely, we have to find a source and a sink (possibly ) which are going to be the vertices with the smallest and largest -coordinate in the upward planar drawing of extending which we are going to construct. Any source of not in can in fact be selected for the task; if all the sources of are in , then the source with the smallest -coordinate can be chosen instead. The sink can be chosen analogously. We now split into two directed paths and between and . We independently construct upward planar drawings and of and extending and , respectively, in which the vertex with the smallest -coordinate is and the vertex with the largest -coordinate is – and are the restrictions of to the vertices in and in , respectively. The drawings and can be constructed as in the proof of Claim 10. We then modify and as in Claim 9 so that:
- (i)
is at the same point in and ; and 2. (ii)
is at the same point in and .
Gluing together and results in an upward drawing of that extends and in which and are the vertices with the smallest and largest -coordinate, respectively. However, might contain crossings. Hence, we redraw the curves representing the edges of and , while leaving the position of every vertex unaltered. This is done again as in the proof of Claim 9.
6 Conclusions and Open Problems
In this paper we introduced and studied the Upward Planarity Extension (UPE) problem, which takes in input an upward planar drawing of a subgraph of a directed graph and asks whether an upward planar drawing of exists which coincides with when restricted to the vertices and edges of .
We proved that the UPE problem is NP-complete, even if has a prescribed upward embedding and contains all the vertices and no edges. Conversely, the problem can be solved efficiently for upward planar -graphs.
Several questions are left open by our research. We cite our favorite two.
First, is it possible to solve the UPE-FUE problem in polynomial time for instances such that contains no edges and no two vertices have the same -coordinate in ? We proved that if any of the two conditions is dropped, then the UPE-FUE problem is NP-hard, however we can only provide a positive answer to the above question if we further assume that is a directed path or cycle.
Second, are the UPE and UPE-FUE problems polynomial-time solvable for directed paths and cycles? Even with the assumption that contains no edges and no two vertices have the same -coordinate in , answering the above question in the affirmative was not a trivial task.
Acknowledgments.
Lemma 6 comes from a research session the third author had with Ignaz Rutter, to which our thanks go.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] P. Angelini, G. Da Lozzo, G. Di Battista, V. Di Donato, P. Kindermann, G. Rote, and I. Rutter. Windrose planarity: Embedding graphs with direction-constrained edges. ACM Trans. Algorithms , 14(4):54:1–54:24, 2018.
- 2[2] P. Angelini, G. Da Lozzo, G. Di Battista, and F. Frati. Strip planarity testing for embedded planar graphs. Algorithmica , 77(4):1022–1059, 2017.
- 3[3] P. Angelini, G. Di Battista, F. Frati, V. Jelínek, J. Kratochvíl, M. Patrignani, and I. Rutter. Testing planarity of partially embedded graphs. ACM Trans. Algorithms , 11(4):32:1–32:42, 2015.
- 4[4] P. Bertolazzi, G. Di Battista, and W. Didimo. Quasi-upward planarity. Algorithmica , 32(3):474–506, 2002.
- 5[5] P. Bertolazzi, G. Di Battista, G. Liotta, and C. Mannino. Upward drawings of triconnected digraphs. Algorithmica , 12(6):476–497, 1994.
- 6[6] P. Bertolazzi, G. Di Battista, C. Mannino, and R. Tamassia. Optimal upward planarity testing of single-source digraphs. SIAM J. Comput. , 27(1):132–169, 1998.
- 7[7] C. Binucci and W. Didimo. Computing quasi-upward planar drawings of mixed graphs. Comput. J. , 59(1):133–150, 2016.
- 8[8] F. Brandenburg. Upward planar drawings on the standing and the rolling cylinders. Comput. Geom. , 47(1):25–41, 2014.
