2-Layer Right Angle Crossing Drawings

Algorithmica
DOI 10.1007/s00453-012-9706-7
2-Layer Right Angle Crossing Drawings
Emilio Di Giacomo · Walter Didimo · Peter Eades ·
Giuseppe Liotta
Received: 26 July 2011 / Accepted: 24 October 2012
© Springer Science+Business Media New York 2012
Abstract A 2-layer drawing represents a bipartite graph where each vertex is a point
on one of two parallel lines, no two vertices on the same line are adjacent, and the
edges are straight-line segments. In this paper we study 2-layer drawings where any
two crossing edges meet at right angle. We characterize the graphs that admit this
type of drawing, provide linear-time testing and embedding algorithms, and present
a polynomial-time crossing minimization technique. Also, for a given graph G and a
constant k, we prove that it is N P-complete to decide whether G contains a subgraph
of at least k edges having a 2-layer drawing with right angle crossings.
Keywords Graph drawing · Right angle crossings · 2-layer drawings · Efficient
algorithms · Testing algorithms · NP-hardness
1 Introduction
The study of drawings of graphs where any two crossing edges form crossing angles
that are not too small is among the emerging topics in Graph Drawing. This interest
Work supported in part by MIUR of Italy under project AlgoDEEP prot. 2008TFBWL4. An abstract
of this work was presented at the International Workshop on Algorithms and Combinatorics (IWOCA
2011) [7].
E. Di Giacomo · W. Didimo () · G. Liotta
Università di Perugia, Perugia, Italy
e-mail: [email protected]
E. Di Giacomo
e-mail: [email protected]
G. Liotta
e-mail: [email protected]
P. Eades
University of Sydney, Sydney, Australia
e-mail: [email protected]
Algorithmica
is motivated by recent experiments of Huang et al. [23, 24], who show that crossing
angles guarantee good readability properties only if they are “large enough” (approximatively larger than π3 ). These experiments therefore imply that non-planar drawings
of graphs should not only be optimized in terms of classical parameters such as the
number of edge crossings and the number of bends along the edges, but also in terms
of the minimum angle formed by any two crossing edges.
In this paper we study straight-line Right Angle Crossing drawings (or RAC drawings for short). In a RAC drawing any two crossing edges meet at angle π2 . RAC
drawings have been first introduced in [10, 12], where it is proved that straight-line
RAC drawings with n vertices have at most 4n − 10 edges, which is a tight bound.
Straight-line RAC drawings are also studied by Dujmović et al. [15], who give an
alternative proof of the 4n − 10 bound. The relationship between straight-line RAC
drawings with 4n − 10 edges and 1-planar graphs is studied in [18]. Angelini et al. [3]
investigate straight-line upward RAC drawings of digraphs. Van Kreveld [30] studies how much better a straight-line RAC drawing of a planar graph can be than any
straight-line planar drawing of the same graph. Complete bipartite straight-line RAC
drawable graphs are studied in [11]. More references on RAC drawings can be found
in [13].
Despite the growing literature about straight-line RAC drawings, no algorithms
for computing such drawings have been described so far. Existing papers either establish combinatorial properties of RAC drawings (they typically address Turán-type
questions) or study RAC drawings with bends along the edges (see, e.g., [1, 3, 5,
9, 10, 12]). Also, deciding whether a graph admits a straight-line RAC drawing is
N P-hard in the general case [4] and it is not even known if this problem is in N P.
In this paper we present the first efficient algorithms for straight-line RAC drawings. We focus on bipartite graphs and consider both the problem of deciding whether
a bipartite graph admits a straight-line RAC drawing and the problem of computing
one in the positive case. We also study how to efficiently compute straight-line RAC
drawings of bipartite graphs with the minimum number of edge crossings. We adopt
the widely accepted 2-layer drawing paradigm, in which the vertices of each partition set lie on a distinct horizontal layer. This paradigm is motivated by the fact
that it clearly conveys the bipartite structure of the graph. Also, it represents a building block for the popular Sugiyama-style framework, adopted for visualizing general
graphs on several layers [27, 31]. A limited list of papers on 2-layer drawings of
bipartite graphs includes [17, 21, 25, 29]; for more references see also [26].
An overview of our results is given below (n denotes the number of vertices of
the input graph). A 2-layer RAC drawing is a 2-layer straight-line drawing with right
angle crossings.
• We characterize 2-layer RAC drawable graphs (Theorem 6). This is the counterpart
for RAC drawings of the well-known characterization of 2-layer planar drawings
(see, e.g., [19, 22, 28]). Our characterization implies that 2-layer RAC drawable
graphs have at most 1.5n − 2 edges, which is a tight bound (Corollary 1); also it
allows us to describe an O(n)-time algorithm that tests whether a graph admits a
2-layer RAC drawing and, if so, it computes one.
Algorithmica
• We show an O(n2 log n)-time algorithm to compute a 2-layer RAC drawing with
the minimum number of edge crossings (Theorem 7). The algorithm models the
optimization problem as the one of computing a flow of minimum cost on a suitable network. We recall that computing a 2-layer drawing of a graph with the
minimum number of crossings is N P-hard and that heuristics [17], approximation algorithms [21], FPT algorithms [14, 16], and exact methods [25, 29] for this
problem have been described.
• Finally, we study the complexity of computing the maximum 2-layer RAC drawable subgraph. We prove that for a given bipartite graph G and for a given k, it is
N P-complete to decide whether G has a 2-layer RAC drawable subgraph with at
least k edges (Theorem 8). This extends to RAC drawings the N P-completeness
result for the maximum 2-layer planar subgraph problem [20].
The rest of the paper is organized as follows. Section 2 gives preliminary definitions and proves that the geometric problem of computing a 2-layer RAC drawing
reduces to the combinatorial problem of computing a 2-layer RAC embedding. In
Sect. 3 an overview of the characterization of 2-layer RAC drawable graphs is given.
Sections 4 and 5 present the characterization of biconnected 2-layer RAC drawable
graphs and 2-layer RAC drawable trees, respectively. The general characterization of
2-layer RAC drawable graph is given in Sect. 6. The problem of computing a 2-layer
RAC drawing with the minimum number of edge crossings is studied in Sect. 7. The
N P-hardness result about the maximum 2-layer RAC drawable subgraph problem is
presented in Sect. 8. Open problems are listed in Sect. 9.
2 Preliminary results: Geometry and Combinatorics
Let G = (V1 , V2 , E) be a bipartite graph. A 2-layer drawing of G has a fan crossing
if there exist two adjacent edges that are both crossed by a third edge; we say that
the three edges involved in the fan crossing form a fan crossing. For a given 2-layer
drawing of G, denote by i the horizontal line on which the vertices of Vi are drawn
(i = 1, 2). We always assume that 1 is above 2 . Two 2-layer drawings of G are
equivalent if they have the same left-to-right order πi of the vertices of Vi (i = 1, 2)
along i . A 2-layer embedding is an equivalence class of 2-layer drawings and it is
described by a pair of linear orderings (i.e., permutations) γ = (π1 , π2 ) of the vertices
in V1 and V2 , respectively. If Γ is a drawing within class γ , we also say that γ is the
embedding of Γ .
Let Γ1 and Γ2 be 2-layer drawings of G with the same embedding γ . Two edges
e and e cross in Γ1 if and only if they cross in Γ2 . We say that embedding γ has a
crossing at edges e and e . Also, three edges e, e and e form a fan crossing in Γ1 if
and only if they form a fan crossing in Γ2 . Correspondingly, we say that embedding
γ has a fan crossing at edges e, e , and e . Let γ = (π1 , π2 ) be a 2-layer embedding
of a bipartite graph G. The first vertex of π1 and the first vertex of π2 are called the
leftmost vertices of γ ; the last vertex of π1 and the last vertex of π2 are called the
rightmost vertices of γ .
The following result proves that the problem of computing a 2-layer RAC drawing
of a bipartite graph G = (V1 , V2 , E) can be studied in purely combinatorial terms as
Algorithmica
the one of choosing a suitable pair (π1 , π2 ) of permutations of the vertices in V1 and
V2 , disregarding details about the exact coordinates of the vertices.
Theorem 1 Let G be a connected graph with n vertices. G is 2-layer RAC drawable if and only if it has a 2-layer embedding without fan crossings. Also, if γ is a
2-layer embedding of G without fan crossings, there exists an O(n)-time algorithm
that, taking γ as input, computes a 2-layer RAC drawing of G whose embedding is γ .
Proof The necessity is a consequence of the fact that a fan crossing always implies
at least one crossing angle smaller than π2 . In order to prove the sufficiency, we shall
describe a drawing algorithm that computes a 2-layer drawing Γ with the following
properties: (1) The embedding of Γ is γ ; (2) any edge involved in a crossing has
either slope 1 or slope −1. These two properties imply that Γ is a 2-layer RAC
drawing: Let e1 and e2 be two edges that cross each other in γ and assume that these
two edges have the same slope in Γ ; either the two edges overlap or they are parallel
and never intersect; in both cases the linear order of the vertices on the layers defined
by γ would not be respected.
Our algorithm strongly relies on the following two properties:
Property 1 If G is connected and has a 2-layer embedding γ = (π1 , π2 ) without fan
crossings, then γ has no three mutually crossing edges.
Property 2 If a 2-layer embedding γ = (π1 , π2 ) has no fan crossings, then for every
vertex v at most two of its incident edges can be crossed by other edges.
Property 1 is proved by contradiction. Indeed, assume that (u1 , u2 ), (u1 , u2 ), and
(u1 , u2 ) are three mutually crossing edges in γ , such that π1 (u1 ) < π1 (u1 ) < π1 (u1 )
and π2 (u2 ) < π2 (u2 ) < π2 (u2 ). Since G is connected, then at least one of u1 and u2
has degree two, say for example u1 . This implies that there exists a vertex v2 adjacent
to u1 (possibly coincident with either u2 or u2 ) such that (u1 , v2 ), (u1 , u2 ), and one
of (u1 , u2 ) and (u1 , u2 ) form a fan crossing.
Property 2 follows by observing that γ defines the left-to-right order of the edges
incident to v and only the leftmost and the rightmost edges incident to v can receive
a crossing (otherwise there would be a fan crossing in γ ).
The drawing algorithm consists of the following steps (see Fig. 1). For each step
we also discuss its time complexity. Since each step can be executed in O(n) time,
then the whole algorithm runs in linear time. Notice that, since G is straight-line RAC
drawable, then G has O(n) edges [10, 12]. We will assume that G has at least two
edges, otherwise G is trivially 2-layer RAC drawable.
Fig. 1 Example of the drawing algorithm. The bold edges represent the crossing edges (edges in C). The
gray vertices are not incident to crossing edges
Algorithmica
Step 1 Compute the set C of all edges of G that cross in γ , and denote by G the
subgraph of G consisting of all edges in C and its end-vertices. In order to compute G in O(n) time, we first observe that since G is connected, every edge is
incident to a vertex of degree at least two, that is, the set of vertices of degree
at least two covers the whole set of edges of G. For each vertex v of degree at
least two, denote by (v, a) and (v, b) the leftmost and the rightmost edge of v
in γ , respectively. Clearly, the leftmost and the rightmost edge for all vertices
can be detected and stored in linear time. By Property 2, no edge incident to
v other than (v, a) and (v, b) can cross other edges. Also, if an edge crosses
(v, a) or (v, b), one of its end-vertices must be in between a and b on their layer
(note that an edge cannot cross both (v, a) and (v, b), otherwise there would
be a fan crossing). If there is no vertex in between a and b (which can be established in constant time), then we can conclude that all edges incident to v
are crossing free. Otherwise, let a be the vertex immediately to the right of a
on its layer, and let b be the vertex immediately to the left of b on its layer.
Observe that a and b may coincide. We claim that if (v, a) and (v, b) do not
cross some edges incident to a or b , then they cannot cross any other edge. Indeed, suppose that neither (v, a) nor (v, b) cross an edge incident to a or b :
(i) If a = b is the only vertex in between a and b on its layer, then the claim is
trivial; (ii) If a = b , since a and b cannot be isolated vertices, G would contain
the edges (v, a ) and (v, b ), and any edge incident to a vertex in between a and
b that crosses either (v, a) or (v, b) would also cross either (v, a ) and (v, b ),
thus causing a fan crossing, a contradiction; this proves the claim. It follows that,
to establish whether (v, a) and (v, b) cross some other edges, it is sufficient to
check if each of them crosses one among the leftmost and the rightmost edges of
a and of b . This can be done in constant time for each vertex v.
Step 2 Compute the set P of connected components of G . Since by Property 2 at
most two edges per vertex cross, each connected component is a path. This step
can clearly be executed in O(n) time.
Step 3 Iteratively draw each path of P , while maintaining the vertex ordering defined
by γ on each layer. Each path is drawn in such a way that each pair of consecutive
edges have slopes 1 and −1. To perform Step 3 in O(n) time, define a suitable
left-to-right ordering for the paths of P , and draw a path at a time according to
this order. More in details, the first path is any path containing a leftmost vertex of
γ (there are at most two of these paths). Assume that at the generic step we have
added a path Π to the drawing and that e is the leftmost edge of Π . In the next
step we consider the embedding γ consisting only of those paths of P that have
not been drawn yet, and consider those paths of P that are incident to the leftmost
vertices of γ . Since there are at most two leftmost vertices in γ , then we have
either one or two of such paths. If there is only one, then it is the next path to be
drawn. If there are two of such paths, say Π and Π , then their leftmost edges
necessarily cross; denote by e and e the leftmost edges of Π and Π . It is
not possible that both e and e cross e, otherwise there would be three mutually
crossing edges in γ (which is not possible by Property 1). If neither e nor e
crosses e, then we arbitrarily chose Π or Π as the next path to be drawn. If one
of the two edges crosses e, then we chose its path as the next path to be drawn.
Algorithmica
Step 4 Add to the drawing the vertices and the edges of G not yet drawn, if any. Each
vertex is drawn in such a way that the vertex ordering defined by γ is maintained.
This can be easily done because we are working with real coordinates. For example, suppose that u, v, and z are three consecutive vertices of γ on the same layer;
also, suppose that u and z are already in the drawing while v is not; it is sufficient
to draw v at any point in between u and z. Hence, this step can be computed in
O(n) time.
A 2-layer embedding without fan crossings is called 2-layer RAC embedding.
Based on Theorem 1, the problem of characterizing 2-layer RAC drawable graphs
is equivalent to characterizing which graphs have a 2-layer RAC embedding. Note
that, a graph is 2-layer RAC drawable if and only if its connected components are
2-layer RAC drawable. Hence, from now on we assume to work on connected graphs.
The following notations will be used in the remainder of the paper. Given two
vertices a and b of a path, we denote by d(a, b) the distance between a and b on the
path, that is, the number of edges from a to b along the path. Given a vertex v, the
degree of v is the number of edges incident to v and is denoted as deg(v).
3 Characterization of 2-layer RAC Drawable Graphs: Overview
In this section we give an overview of the characterization of 2-layer RAC drawable
graphs. In the more general case, a 2-layer RAC drawable graph consists of a set
of non-trivial biconnected components1 and a set of tree components that are partially ordered along the two layers (two components are ordered if their drawings
can be separated by a line cutting the two layers). Such an order is not a total order
because there can be some “overlap” between different tree components (two components overlap if an edge of a component crosses an edge in the other component).
For example, Fig. 2(b) shows a 2-layer RAC drawing of the graph G depicted in
Fig. 2(a). G consists of two non-trivial biconnected components and five tree components (highlighted in Fig. 2(c)) that are partially ordered left-to-right along the two
layers in the drawing; as shown in Fig. 2(d) the left-to-right order is not a total ordering because in some cases the tree components overlap as it happens for components
T1 and T2 and for components T4 and T5 in the drawing of Fig. 2(b).
In what follows we first characterize biconnected 2-layer RAC drawable graphs
(Sect. 4), and then 2-layer RAC drawable trees (Sect. 5). These two characterizations
will then be combined to characterize 2-layer RAC drawable graphs. The combination, however, is not straightforward because the drawings of the different components of G must satisfy additional properties in order to be combined together.
In particular, it must be possible to order the components along the two layers in
such a way that: (i) Each component shares vertices only with the components that
immediately precede and follow it and with the components that overlap with it;
(ii) the vertices shared by two consecutive components C1 and C2 (in this left-toright order) must be the rightmost for C1 and the leftmost for C2 . For example, the
1 A trivial biconnected component consists of a single edge.
Algorithmica
Fig. 2 (a) A graph G. (b) A 2-layer RAC drawing Γ of G. (c) The biconnected components and the tree
components of G. (d) The biconnected components and the tree components of G in Γ . (e) A graph G .
(f) G does not admit a 2-layer RAC drawing
graph G of Fig. 2(e) has a biconnected component (isomorphic to B1 in Fig. 2(c))
and a tree component (consisting of edge (3, 9)). Both components are 2-layer RAC
drawable, but the biconnected component does not admit a 2-layer RAC drawing with
the vertex 3 as the leftmost or the rightmost vertex; as a consequence whatever the
position of vertex 9 will be, it is not possible to obtain a 2-layer RAC drawing of
G (see Fig. 2(f)). For this reason, Sect.s 4 and 5 contain: (i) the characterizations of
biconnected 2-layer RAC drawable graphs and 2-layer RAC drawable trees; (ii) the
characterization of biconnected graphs that are 2-layer RAC drawable in such a way
that two specified edges are the leftmost and the rightmost ones; and (iii) the characterization of trees that are 2-layer RAC drawable in such a way that two specified
leaves are the leftmost and the rightmost ones.
4 Characterization of Biconnected Graphs
Let G be a biconnected bipartite graph with at least four edges, and let e and e be
two independent edges of G. If there exists a 2-layer RAC embedding γ of G such
that the end-vertices of e are the leftmost vertices of γ and the end-vertices of e are
the rightmost vertices of γ , we say that γ is a 2-layer RAC embedding of G with
respect to e and e . Clearly, edges e and e cannot cross any edge in γ . A 2-layer
RAC drawing with embedding γ is called a 2-layer RAC drawing with respect to e
and e . If G admits such a drawing, we also say that G is 2-layer RAC drawable with
respect to e and e . Figure 3(b) shows an example of a 2-layer RAC drawing with
respect to edges (1, 10) and (5, 6).
A biconnected bipartite graph is a ladder if it consists of two paths of the same
length u1 , u2 , . . . , u n2 and v1 , v2 , . . . , v n2 plus the edges (ui , vi ) (i = 1, 2, . . . , n2 ).
Algorithmica
Fig. 3 (a) A bipartite simple cycle C. (b) A 2-layer RAC drawing of C with respect to edges (1, 10) and
(5, 6); the drawing has an interlaced embedding. (c) A ladder with extremal edges e and e . (d) A 2-layer
RAC drawing of the ladder with respect to e and e
Figure 3(c) shows an example of a ladder. Note that, a ladder is a maximal bipartite
outerplanar graph where all vertices have degree at most three and exactly four vertices u1 , v1 , u n2 , v n2 have degree two. The edges e = (u1 , v1 ) and e = (u n2 , v n2 ) are
called the extremal edges of the ladder.
We will now prove that a biconnected graph G is 2-layer RAC drawable with
respect to two independent edges e and e if and only if it is a spanning subgraph of
a ladder having e and e as extremal edges (Theorem 2). Figure 3(d) shows a 2-layer
RAC drawing of the ladder in Fig. 3(c). Theorem 2 also proves the existence of an
efficient algorithm that tests whether G admits a 2-layer RAC drawing with respect
to e and e and, if so, it computes such a drawing. Theorem 3 is the counterpart of
Theorem 2 without any fixed extremal edges. We give some preliminary definitions
and lemmas.
Let C be a bipartite simple cycle and let γ be a 2-layer embedding of C. Denote by
a1 , a2 , . . . , a n2 the left-to-right sequence of vertices on one layer and by b1 , b2 , . . . , b n2
the left-to-right sequence of vertices on the other layer in γ . We say that γ is an
interlaced embedding if the edges of C are (a1 , b1 ), (a n2 , b n2 ), (ai , bi+1 ), (ai+1 , bi )
for each i ∈ {1, . . . , n2 − 1} (see Figs. 3(a) and 3(b) for an example). In other words, if
γ is an interlaced embedding of C, then γ is a 2-layer RAC embedding with respect
to two edges e and e and each edge distinct from e and e is crossed exactly once. Let
γ be an interlaced embedding with three consecutive vertices a1 , b1 , c1 on one layer
and three consecutive vertices a2 , b2 , c2 on the other layer, such that the edge (b1 , a2 )
crosses the edge (b2 , a1 ) and the edge (b1 , c2 ) crosses the edge (b2 , c1 ). We say that
b1 and b2 are opposite vertices of γ . For example, in the embedding of Fig. 3(b), the
pairs {9, 2}, {3, 8}, and {7, 4} are pairs of opposite vertices.
Algorithmica
Lemma 1 Let C be a bipartite simple cycle. C is a 2-layer RAC drawable graph and
any 2-layer RAC embedding of C is an interlaced embedding.
Proof Clearly, C always admits an interlaced embedding, and therefore it is 2-layer
RAC drawable by Theorem 1. On the other hand, suppose γ is a 2-layer RAC embedding of C. We prove that γ is an interlaced embedding. Let a1 , a2 , . . . , a n2 be the
left-to-right sequence of vertices on one layer and let b1 , b2 , . . . , b n2 be the left-toright sequence of vertices on the other layer in γ . If edge (a1 , b1 ) is not in C, then,
since a1 has degree two, C has two edges (a1 , bh ), (a1 , bk ) with h, k > 1. This would
imply that any edge (aj , b1 ) (j > 1) crosses both the edges (a1 , bh ), (a1 , bk ), causing a fan crossing, a contradiction. It follows that C contains edge (a1 , b1 ). With a
symmetric argument, C contains edge (a n2 , b n2 ). We now prove by induction on i that
C contains edges (ai , bi+1 ) and (ai+1 , bi ), for i ∈ {1, . . . , n2 − 1}. For i = 1 we have
to prove that C contains edges (a1 , b2 ) and (a2 , b1 ). If edge (a1 , b2 ) is not in C, then,
since a1 has degree two, C has an edge (a1 , bh ) for h > 2, other than (a1 , b1 ); but
this would imply that the two edges incident to b2 form a fan crossing with (a1 , bh ),
a contradiction. For the same reason, C has the edge (a2 , b1 ). Assume now that C
contains the edges (ai−1 , bi ), (ai , bi−1 ) for i > 2. If edge (ai , bi+1 ) is not in C, then
C would have an edge (ai , bi+h ) for h > 1. Also, bi+1 cannot be adjacent to a vertex
to the left of a1 , because each of these vertices has already degree two by inductive hypothesis. Hence, the two edges incident to ai+1 would be incident to vertices
that are to the right of ai , but in this case they would form a fan crossing with edge
(ai , bi+h ). It follows that edge (ai , bi+1 ) is in C. With a symmetric argument it can
be proved that edge (ai+1 , bi ) is in C.
Lemma 2 Let γ be an interlaced embedding of a simple cycle C and let u and v be
two non-adjacent vertices of C. The embedding γ with the addition of edge (u, v) is
a 2-layer RAC embedding if and only if u and v are opposite vertices of γ .
Proof As also observed in the proof of Lemma 1, any interlaced embedding of a
cycle is a 2-layer RAC embedding by Theorem 1. If u and v are opposite vertices
of γ , the addition of edge (u, v) does not create crossings, and therefore the new
embedding is still a 2-layer RAC embedding. On the other hand, if u and v are not
opposite vertices of γ , the addition of edge (u, v) causes a fan crossing, and therefore
the new embedding is not a 2-layer RAC embedding.
Lemma 3 Let G be a biconnected bipartite graph. G is a 2-layer RAC drawable
graph only if it is outerplanar.
Proof If G consists only of one edge the lemma trivially holds. Suppose that G has
at least four vertices. We assume that the vertices of G are colored black and white,
according to the bipartition. Since G is biconnected and has at least four vertices, it
contains a simple cycle. Let C be the longest simple cycle of G. If G is outerplanar,
C contains all vertices of G and placing all the vertices of G on a circumference (in
the cyclic order they occur in C) we get a planar drawing of G. If G is not outerplanar,
two cases are possible.
Algorithmica
Fig. 4 Illustration for the proof of Lemma 3
Case 1: C contains all vertices of G, but placing these vertices on a circumference
there are two crossing edges (refer to Fig. 4(a)). Denote by (u, z) and (v, w) two
crossing edges of G, where the vertices u, v, z, w are encountered in this order walking on the circumference clockwise. According to Lemma 1 every 2-layer RAC embedding γ of C is an interlaced embedding. Consider any 2-layer RAC embedding
of C and assume, without loss of generality, that π1 (u) < π1 (v); this implies that
π2 (w) < π2 (z), because the interlaced embedding reflects the circular order of the
vertices in C. It follows immediately that it is not possible to add to γ both (u, z)
and (v, w) without creating a fan crossing. By Theorem 1, this implies that G is not
2-layer RAC drawable, a contradiction.
Case 2: C does not contain all vertices of G (refer to Fig. 4(b)). According to
Lemma 1 every 2-layer RAC embedding γ of C is an interlaced embedding. Let
v be a vertex of G that is not contained in C. Without loss of generality, assume that
v is white. Let w and z be two black vertices of C (note that C contains at least two
black vertices and two white vertices). Since G is biconnected, there exist two edge
disjoint paths Πvw , Πvz , such that Πvw goes from v to w, Πvz goes from v to z. Walk
along Πvw from v to w and along Πvz from v to z. Denote by (w , w ) the first edge
along Πvw such that w does not belong to C and w belongs to C. Note that, w may
coincide with v and that w may coincide with w. Similarly, denote by (z , z ) the
first edge along Πvz such that z does not belong to C and z belongs to C (again, z
may coincide with v and z main coincide with z). If w is not a leftmost/rightmost
vertex of γ then edge (w , w ) would cause a fan crossing with some edges of γ (see,
e.g., Case 2.1 of Fig. 4(b)). Analogously, if z is not a leftmost/rightmost vertex of
γ then edge (z , z ) would cause a fan crossing. Also, if w is a leftmost vertex of
γ and z is a rightmost vertex of γ , then for every placement of v there would be at
least one edge in the subpath of Πvw from v to w or at least one edge in the subpath
of Πvz from v to z that causes a fan crossing with some edges of γ (see, e.g., Case
2.2 of Fig. 4(b)). Finally, suppose that w and z are both leftmost (or both rightmost)
vertices of γ . In this case it would be possible to enhance γ with an embedding γ1 of
the subpath of Πvw going from v to w and with an embedding γ2 of the subpath of
Πvz going from v to z , in such a way that γ = γ ∪ γ1 ∪ γ2 without the edge (w , z )
Algorithmica
is an interlaced embedding of a new cycle C , which contains more vertices than C
(see, e.g., Case 2.3 of Fig. 4(b)); this contradicts the hypothesis that C is the longest
simple cycle in the graph. It follows that C cannot exist.
Lemma 4 Every ladder is 2-layer RAC drawable with respect to its extremal edges.
Proof Let G be a ladder. Since by definition of ladder G is a maximal bipartite outerplanar graph and all its vertices have degree at most three, then G has a planar
embedding where all vertices are on the external boundary, all internal faces of G are
quadrilateral, and there are no two internal edges incident to the same vertex. Hence,
a 2-layer RAC drawing of G can be constructed so that the external boundary has an
interlaced embedding γ and each internal edge connects two opposite vertices of γ .
Embedding γ is such that the end-vertices of the extremal edges of G are the leftmost
and the rightmost vertices, respectively.
Theorem 2 Let G be a biconnected graph and let e and e be two independent edges
of G. G is 2-layer RAC drawable with respect to e and e if and only if it is a spanning
subgraph of a ladder with extremal edges e and e . Also, if G has n vertices, there
exists an O(n)-time algorithm that tests whether G admits a 2-layer RAC drawing
with respect to e and e and, if so, it computes such a drawing.
Proof If G is a spanning subgraph of a ladder with extremal edges e and e , then G
is 2-layer RAC drawable by Lemma 4. Suppose vice-versa that G has a 2-layer RAC
drawing Γ with respect to e and e . By Lemma 3 G is outerplanar. Since G is an
outerplanar graph, it admits a planar embedding where all vertices are on the external
boundary C. By Lemma 1 Γ is such that cycle C has an interlaced embedding γ ; by
Lemma 2 every internal edge of Γ connects two opposite vertices of γ . By connecting all pairs of non-adjacent opposite vertices u, v of γ (if any), we obtain a ladder
that contains G as a spanning subgraph and with extremal edges e and e .
Concerning the time complexity, the algorithm first checks in O(n) time if G is a
bipartite graph and if the vertex degree of G is at most three. Then, it tests in O(n)
time whether G admits an outerplanar embedding, by applying the following standard
technique: (i) Temporarily adds to G a dummy vertex u and a dummy edge (u, v) for
every vertex v of G. (ii) run on the new graph an O(n)-time planarity testing and embedding algorithm (see, e.g., [6]); if the testing algorithm finds a planar embedding,
then removing the dummy vertex and edges we get an outerplanar embedding of G,
otherwise G is not outerplanar, and the whole test is negative.
Suppose that G is a bipartite outerplanar graph with vertex degree at most three,
and that the outerplanar embedding of G has been found; since G is biconnected,
it has only one outerplanar embedding. Denote by C the external boundary of this
embedding. To complete the test, the algorithm has to verify if the two following
conditions hold: (a) C consists of two paths of the same length u1 , u2 , . . . , u n2 ,
v1 , v2 , . . . , v n2 such that e = (u1 , v1 ) and e = (u n2 , v n2 ). (b) Any edge of G that
does not belong to C connects a pair of vertices {ui , vi } (2 ≤ i ≤ n2 − 1).
If (a) and (b) are not both true, the test is negative. Otherwise, the test is positive
and a 2-layer RAC embedding γ of G with respect to e and e is immediately obtained
Algorithmica
from the outerplanar embedding of G, using the circular ordering of the vertices
along C (see, e.g., Fig. 3(a) and Fig. 3(b)). A 2-layer RAC drawing with embedding
γ can be computed in linear time with the constructive technique of Theorem 1. Theorem 3 Let G be a biconnected graph. G is 2-layer RAC drawable if and only if
it is a spanning subgraph of a ladder. Also, if G has n vertices, there exists an O(n)time algorithm that tests whether G is 2-layer RAC drawable and, if so, it computes
a 2-layer RAC drawing of G.
Proof Let G be a biconnected graph. If G is a spanning subgraph of a ladder then G
is 2-layer RAC drawable by Lemma 4. Suppose vice-versa that G is a 2-layer RAC
drawable graph. By Lemma 3 G is outerplanar. If G is already a ladder we are done.
Assume that G is not a ladder and let Γ be any 2-layer RAC drawing of G. Since G
is an outerplanar graph, it admits a planar embedding where all the vertices are on the
external boundary C. By Lemmas 1 and 2, Γ is such that cycle C has an interlaced
embedding γ and every internal edge of G connects two opposite vertices of γ . By
connecting all pairs of non-adjacent opposite vertices u, v of γ we obtain a ladder
that contains G as a spanning subgraph.
According to the characterization above, a testing algorithm has to check if G
is bipartite and if G can be augmented to a ladder (i.e., to a maximal outerplanar
graph with vertex degree at most three), by adding some extra edges. Testing if G
is bipartite, outerplanar, and with vertex degree at most three is done as described in
the proof of Theorem 2. Suppose that G is a bipartite outerplanar graph with vertex
degree at most three, and that the outerplanar embedding of G has been found; since
G is biconnected, it has only one outerplanar embedding. To complete the test, the
algorithm has to decide whether it is possible to add extra edges so that all the internal
faces of G are split into faces of degree four while maintaining the graph bipartite and
with vertex degree at most three. This can be done as follows. While there exists an
internal face f of degree greater than four, consider an internal edge e = (u, v) on
the boundary of f . Let (u, w) and (v, z) be the edges of the boundary of f that are
adjacent to e. Observe that w and z have different colors. If both w and z have degree
two then split f into two faces, by adding the new edge (v, z); otherwise, G cannot
be augmented to a ladder, the algorithm stops and the test is negative. The test is
positive when every internal face has degree four and the algorithm never stopped
during the edge augmentation. It is not difficult to see that the edge augmentation can
be performed in O(n) time. Also, if the test is positive, a 2-layer RAC embedding
γ of G is immediately obtained from the outerplanar embedding of G, using the
circular ordering of the vertices along the external boundary. A 2-layer RAC drawing
with embedding γ can be computed in linear time with the constructive technique of
Theorem 1.
5 Characterization of Trees
In this section we characterize 2-layer RAC drawable trees. As explained in Sect. 3,
along with the characterization of 2-layer RAC drawable trees (Theorem 5), we give
Algorithmica
the characterization of 2-layer RAC drawable trees where two given vertices u and
v are required to be a leftmost vertex and a rightmost vertex, respectively (Theorem 4). The latter characterization will be used in Sect. 6 to characterize 2-layer
RAC drawable graphs. In Theorem 4 we focus on the case when u and v are two
leaves for two reasons: (i) This is the only case needed for the characterization of
2-layer RAC drawable graphs that contain both non-trivial biconnected components
and tree components. (ii) As Lemma 6 proves, any 2-layer RAC drawable tree admits
a 2-layer RAC drawing where a leftmost vertex and a rightmost vertex are leaves.
The characterization given in Theorem 5 is an immediate consequence of Lemma 6
and Theorem 4.
Roughly speaking, a 2-layer RAC drawing of a tree consists of a “zig-zag” path
between the two layers with some suitable sub-structures attached to its vertices. In
order to define the different types of sub-structures we define a sort of simplified
version of the tree which we call the weighted contraction of the tree. Section 5.1
gives some preliminary definitions, and presents and proves Lemma 6. Weighted contractions are defined in Sect. 5.2. The sufficiency of the characterization is given in
Sect. 5.3, while the necessity is proved in Sect. 5.4. Section 5.5 presents and proves
Theorems 4 and 5.
5.1 Basic Properties of 2-layer RAC Drawable Trees
We start with definitions and lemmas that can be stated for more general connected
graphs. Let γ = (π1 , π2 ) be a 2-layer embedding of a bipartite graph G and let G be
a subgraph of G consisting of a vertex u ∈ Vi attached to three vertices v1 , v2 , v3 ∈ Vj
(i, j ∈ {1, 2} and i = j ) where πj (v1 ) < πj (v2 ) < πj (v3 ). We say that G is a degree3 blocker in γ and that u is the apex of the degree-3 blocker. An edge (w, z) of G
with w ∈ Vi and z ∈ Vj is called a traversing edge of G in γ if either πi (w) < πi (u),
πj (v2 ) < πj (z) or πi (u) < πi (w), πj (z) < πj (v2 ). Refer to Fig. 5(a).
Let γ = (π1 , π2 ) be a 2-layer embedding of a bipartite graph G and let G be a
subgraph of G consisting of a path v1 , v2 , v3 , v4 , such that v1 , v3 ∈ V1 , v2 , v4 ∈ V2
and either π1 (v1 ) < π1 (v3 ) and π2 (v4 ) < π2 (v2 ) or π1 (v3 ) < π1 (v1 ) and π2 (v2 ) <
π2 (v4 ). We say that G is a butterfly blocker in γ . An edge (w, z) of G with w ∈ V1
and z ∈ V2 is called a traversing edge of G in γ if either π1 (w) < π1 (v3 ), π2 (v2 ) ≤
π2 (z) or π1 (v3 ) < π1 (w), π2 (z) ≤ π2 (v2 ). Refer to Fig. 5(b). If G is either a degree3 blocker or a butterfly blocker, every traversing edge of G causes a fan crossing.
Hence, by Theorem 1 the following property holds.
Fig. 5 (a) The bold edges form a degree-3 blocker. The remaining edges are traversing edges. (b) The
bold edges form a butterfly blocker. The remaining edges are traversing edges
Algorithmica
Property 3 Let γ = (π1 , π2 ) be a 2-layer RAC embedding of a bipartite graph G
and let G ⊆ G be either a degree-3 blocker or a butterfly blocker in γ . There is no
traversing edge of G in γ .
Let γ = (π1 , π2 ) be a 2-layer embedding of a bipartite graph G. A path Π of G
is monotone in γ if, for one of the two possible orientations of Π , every two vertices
u, v in Π ∩ Vi are such that πi (u) < πi (v) (i ∈ {1, 2}) if and only if u appears before
v in Π .
Lemma 5 Let γ = (π1 , π2 ) be a 2-layer RAC embedding of a connected bipartite
graph G. Let u and v be a leftmost vertex and a rightmost vertex in γ , respectively.
Every path of G from u to v is monotone in γ .
Proof Let Π be a path from u to v in G (Π exists because G is connected) and walk
on Π from u to v. If Π is not monotone in γ , there exist three consecutive vertices
u , z, v along Π , such that u , v ∈ Vi (i ∈ {1, 2}) and πi (v ) < πi (u ). Assume that
u , z, and v are the first three vertices along Π that are in this situation. This implies
that there is a subpath G =v1 , v2 = u , v3 = z, v4 = v such that πh (v1 ) < πh (v3 )
and πi (v4 ) < πi (v2 ), where h, i ∈ {1, 2} and h = i. Hence, G is a butterfly blocker
in γ . Since v1 is encountered before v2 and v3 walking along Π from u to v, v2 = v
and v3 = v. Also, since v is a rightmost vertex of γ , either v ∈ Vh and πh (v3 ) < πh (v)
or v ∈ Vi and πi (v2 ) < πi (v). In both cases, the subpath of Π from v4 to v contains
a traversing edge of G , and therefore causes a fan crossing. This contradicts the
assumption that γ is a 2-layer RAC embedding of G.
Let T be a tree and let u and v be two leaves of T . If there exists a 2-layer RAC
embedding γ where u and v are a leftmost vertex and a rightmost vertex of γ , respectively, we say that γ is a 2-layer RAC embedding with respect to u and v. A 2-layer
RAC drawing with embedding γ is called a 2-layer RAC drawing with respect to u
and v. If T admits such a drawing, we also say that T is 2-layer RAC drawable with
respect to u and v.
The next lemma guarantees that in order to test the 2-layer RAC drawability of a
tree we can concentrate only on those 2-layer RAC embeddings that have two leaves
as leftmost and rightmost vertices.
Lemma 6 Let T be a 2-layer RAC drawable tree. There exist two leaves u and v
such that T is 2-layer RAC drawable with respect to u and v.
Proof Since T is a 2-layer RAC drawable tree, it admits a 2-layer RAC embedding
γ = (π1 , π2 ). If a leftmost vertex in γ is a leaf and a rightmost vertex of γ is a leaf,
γ is the desired 2-layer RAC embedding. Otherwise both the leftmost vertices are not
leaves and/or both the rightmost vertices are not leaves. We prove that it is possible
to modify the 2-layer RAC embedding γ to obtain a new 2-layer RAC embedding γ
that satisfies the statement.
Let u1 ∈ V1 and u2 ∈ V2 be the leftmost vertices in γ and assume that they are not
leaves. It follows that they must be adjacent because otherwise u1 would be adjacent
Algorithmica
to at least two vertices to the right of u2 and u2 would be adjacent to at least two
vertices to the right of u1 . But this would imply a fan crossing. By the same reasoning,
both u1 and u2 have degree 2. Let v be a rightmost vertex of γ . By Lemma 5, the
path Π1 from u1 to v is monotone, and the path Π2 from u2 to v is monotone.
One among Π1 and Π2 contains edge (u1 , u2 ) and properly contains the other path
(otherwise T would contain a cycle, which is impossible). Assume, without loss of
generality, that Π2 contains (u1 , u2 ) (hence, Π1 ⊂ Π2 ), and let ei be the edge incident
to ui and distinct from (u1 , u2 ) (i ∈ {1, 2}). Clearly, edge e1 belongs to Π2 . Let C
be the connected component obtained by removing e2 that does not contain u1 and
let T = C ∪ {e2 }. Observe that T shares with Π2 only vertex u2 , otherwise there
would be a cycle in T , which is impossible. This implies that, since T is embedded
to the right of u1 and u2 (because they are the leftmost vertices), it cannot contain a
degree-3 vertex, because otherwise it would contain a degree-3 blocker G and one
edge of Π2 would be a traversing edge of G . Thus T is a path. (Note also that T is
a monotone path in γ ; if not, it would contain a butterfly blocker G and one edge
of Π2 would be a traversing edge of G .)
Let a1 , a2 , . . . , ah be the vertices of T that belong to V1 in the left-to-right order they appear in π1 and let b1 , b2 , . . . , bk be the vertices of T \ {u2 } that belong
to V2 in the left-to-right order they appear in π2 . We construct from γ a 2-layer
RAC embedding γ = (π1 , π2 ) by mirroring the monotone path T with respect to
edge (u1 , u2 ). More precisely, π1 in such that a1 , a2 , . . . , ah are to the left of u1 and
π1 (ah ) < π1 (ah−1 ) < · · · < π1 (a1 ) < π1 (u1 ), while all the other vertices of V1 remain to the right of u1 in the same relative order they have in π1 . Analogously, π2 is
such that b1 , b2 , . . . , bk are to the left of u2 and π2 (bk ) < π2 (bk−1 ) < · · · < π2 (b1 ) <
π2 (u2 ), while all the other vertices of V2 remain to the right of u2 in the same relative
order they have in π2 . It is easy to verify that this mirroring does not create any new
crossing and therefore γ is a 2-layer RAC embedding. Also, one of the two leftmost
vertices of γ (i.e., either ah or bk ) is the end-vertex of the path T and therefore it
is a leaf. At this point, if one of the rightmost vertices of γ is a leaf, then γ is the
desired 2-layer RAC embedding, otherwise we can symmetrically modify it so that a
rightmost vertex of the resulting 2-layer RAC embedding is a leaf.
5.2 Weighted Contractions
We now give some definitions that will be used to characterize 2-layer RAC drawable
trees. A chain of T is a maximal path of T such that all its internal vertices have
degree two in T . A weighted contraction of T is a weighted tree obtained from T by
replacing each chain of length k > 1 with a single edge of weight k. We denote by
wc(T ) the weighted contraction of T and by ω(a, b) the weight of an edge (a, b) of
wc(T ). An edge of T that also belongs to wc(T ) has weight 1. Note that, the vertices
of wc(T ) are a subset of the vertices of T and every vertex of wc(T ) has the same
degree in T and in wc(T ).
A path between two leaves u, v of T is called a spine of T and is denoted by
suv (T ). The path between u and v in wc(T ) is denoted by scuv (T ) and is called a
spine of wc(T ). For a given spine, we call its vertices spine vertices; the remaining
vertices are called non-spine vertices. Figure 6(a) shows a tree T and its weighted
Algorithmica
Fig. 6 (a) A tree T and its weighted contraction wc(T ); the gray vertices are internal vertices of chains
and disappear in wc(T ); the path between u and v in T (edges in bold) is a spine. (b) A 2-layer RAC
embedding of T with respect to u and v
contraction wc(T ). The path between leaves u and v (edges in bold) is a spine; Figure 6(b) shows a 2-layer RAC embedding with respect to the end-vertices u and v of
the spine.
Our characterization of a 2-layer RAC drawable tree is expressed in terms of properties of its weighted contraction. In order to do that, we look at what type of subtrees
are “attached” to the vertices of the spine. For a given spine scuv (T ) of wc(T ), we
define three kinds of subtrees in wc(T ), called k-fence, y-tree, and star-tree, respectively. Also, for a subtree T of any of the types above, we give the definition of
feasibility of T , which expresses the possibility of representing the “non-contracted”
version of T in a 2-layer RAC embedding with respect to the end-vertices, u and v,
of the spine. We will prove that a tree T is 2-layer RAC drawable with respect to u
and v if and only if every subtree “attached” to scuv (T ) is either a feasible maximal
k-fence, or a feasible y-tree, or a feasible star-tree. The three kinds of subtrees are
defined as follows:
• k-fence (refer to Figs. 7(a), 7(b), and 7(c)). Let z0 , z1 , z2 , . . . , zk , zk+1 (k ≥ 2)
be a sequence of spine vertices such that: (i) deg(zi ) = 3 (i ∈ {1, . . . , k});
(ii) ω(zi , zi+1 ) = 1 (i ∈ {1, . . . , k − 1}); deg(wi ) = 1, where wi is the non-spine
vertex adjacent to zi (i ∈ {1, . . . , k}). The weighted subtree T induced by the
vertices of {zi | i = 1, . . . , k} ∪ {wi | i = 1, . . . , k} is called a k-fence of wc(T ).
The subsequence z1 , z2 , . . . , zk is the chain root of T , each wi is a leaf of T .
A k-fence is maximal if z0 , z1 , z2 , . . . , zk , zk+1 is a maximal sequence satisfying
(i) and (ii).
– A 2-fence is feasible if either ω(z1 , w1 ) ≤ ω(z0 , z1 ) + 1 and ω(z2 , w2 ) ≤
ω(z2 , z3 ) + 1 or ω(z2 , w2 ) ≤ ω(z0 , z1 ) and ω(z1 , w1 ) ≤ ω(z2 , z3 ).
– A 3-fence is feasible if one of the following conditions holds:
∗ the subtree induced by z1 , z2 , w1 , w2 is a feasible 2-fence and ω(z3 , w3 ) ≤
ω(z3 , z4 ) + 1;
∗ the subtree induced by z2 , z3 , w2 , w3 is a feasible 2-fence and ω(z1 , w1 ) ≤
ω(z0 , z1 ) + 1;
– A k-fence (k > 3) is feasible if the following conditions holds:
∗ the subtree induced by z1 , z2 , w1 , and w2 is a feasible 2-fence;
∗ the subtree induced by zk−1 , zk , wk−1 , and wk is a feasible 2-fence;
∗ If k ≥ 5, then ω(zi , wi ) ≤ 2 (i ∈ {3, . . . , k − 2}).
Algorithmica
Fig. 7 (a) A feasible 2-fence. (b) A feasible 3-fence. (c) A feasible 5-fence. (d) A feasible y-tree.
(e) A feasible star-tree
• y-tree (refer to Fig. 7(d)). Let z be a degree-3 spine vertex of wc(T ) that does not
belong to any maximal k-fence and such that: (i) deg(w) = 3, where w is the nonspine vertex adjacent to z: and (ii) the vertices a, b = z adjacent to w have degree
one. The weighted subtree T induced by z, w, a, b is called a y-tree of wc(T ).
Vertex z is the root, w is the internal vertex, and a, b are the leaves of T . Denote
by z1 , z2 the spine vertices adjacent to z. Tree T is feasible if: (i) ω(z, w) = 1;
(ii) either ω(w, a) ≤ ω(z1 , z) and ω(w, b) ≤ ω(z, z2 ) or ω(w, b) ≤ ω(z1 , z) and
ω(w, a) ≤ ω(z, z2 ).
• star-tree (refer to Fig. 7(e)). Let z be a spine vertex of wc(T ) that does not belong
to either a maximal k-fence or a y-tree and such that: (i) deg(z) ≥ 3; (ii) every nonspine vertex wi adjacent to z has degree one (i = 1, . . . , deg(z) − 2). The weighted
subtree T induced by z and all vertices wi is called a star-tree of wc(T ). Vertex z is
the root of T . Denote by z1 , z2 the spine vertices adjacent to z. Tree T is feasible
if: (i) There exist at most two vertices wj , wh such that 1 < ω(z, wj ) ≤ ω(z1 , z)+1
and 1 < ω(z, wh ) ≤ ω(z, z2 )+1; (ii) for every vertex wi ∈
/ {wj , wh }, ω(z, wi ) = 1.
A spine suv (T ) is called a feasible spine if every vertex z ∈ scuv (T ) distinct from
u and v is such that one of the three conditions holds: (i) z belongs to the chain
root of a feasible maximal k-fence; (ii) z is the root of exactly one feasible y-tree;
(iii) z is the root of exactly one feasible star-tree.
In what follows we prove that a tree T is 2-layer RAC drawable with respect to
u and v if and only if suv (T ) is a feasible spine (Theorem 4). We prove separately
the sufficiency condition (Lemma 7) and the necessity condition (Lemma 9). The
proof of the sufficiency condition describes a linear time algorithm that starting from
a feasible spine suv (T ) constructs a 2-layer RAC embedding of T with respect to u
and v.
5.3 Sufficiency
Lemma 7 Let T be a tree and let u, v be two leaves of T . Tree T is 2-layer RAC
drawable with respect to u and v if suv (T ) is a feasible spine.
Algorithmica
Fig. 8 Illustration for the proof of Lemma 7: (a) A 2-layer RAC embedding of the spine; (b) A 2-layer
RAC embedding of the non-contracted version of the y-tree of Fig. 7(d); (c) A 2-layer RAC embedding
of the non-contracted version of the star-tree of Fig. 7(e); (d)–(e) Two different 2-layer RAC embeddings
of the 2-fence of Fig. 7(a); (f) A 2-layer RAC embedding of the 3-fence of Fig. 7(b); (g) A 2-layer RAC
embedding of the 5-fence of Fig. 7(c)
Proof We describe an algorithm to construct a 2-layer RAC embedding γ of T with
respect to u and v. This is sufficient by Theorem 1. The algorithm works as follows.
First it embeds suv (T ) as a monotone path. Then for each vertex z ∈ suv (T ) ∩ scuv (T )
the algorithm distinguishes between the following cases:
Case 1: z is the root of a feasible y-tree T . Let w be the internal vertex of T and
let a, b be its leaves. Also, let z1 , z2 be the two vertices of scuv (T ) adjacent to
z. Without loss of generality assume that ω(w, a) ≤ ω(z, z1 ) and that ω(w, b) ≤
ω(z, z2 ) (if not, we can exchange the labels of a and b). The algorithm embeds the
non-contracted version of T as shown in Fig. 8(b): The path Π1 from w to a in
T and the path Π2 from w to b in T are embedded to the left of z and to the right
of z, respectively, so that their vertices alternate with the vertices of the spine.
Since ω(w, a) ≤ ω(z, z1 ) and that ω(w, b) ≤ ω(z, z2 ), no edge of Πi traverses
a blocker (i = 1, 2). Hence, the embedding of the non-contracted version of T does not create fan crossings. Also, note that if z1 coincides with u, it remains a
leftmost vertex of γ . Analogously, if z2 coincides with v, it remains a rightmost
vertex of γ .
Case 2: z is the root of a feasible star-tree T . Let w1 , . . . , wk be the vertices of T adjacent to z and let z1 , z2 be the two vertices of scuv (T ) adjacent to z. Without
loss of generality, assume that ω(z, w1 ) ≤ ω(z, z1 ) + 1, ω(z, wk ) ≤ ω(z, z2 ) + 1,
and ω(z, wi ) = 1 (i = 2, . . . , k − 1) (if not, we can reorder the vertices). The algorithm embeds the non-contracted version of T as shown in Fig. 8(c): The path Π1
from z to w1 in T and the path Π2 from z to wk in T are embedded to the left and
to the right of z, respectively, so that their vertices alternate with the vertices of the
spine. Since ω(z, w1 ) ≤ ω(z, z1 ) + 1 and that ω(z, wk ) ≤ ω(z, z2 ) + 1, no edge of
Πi traverses a blocker (i = 1, 2). The remaining edges (z, wi ) (i = 2, . . . , k − 1)
are embedded between the leftmost and the rightmost edges incident to z, so
that they do not cross any other edge of γ . Hence, the embedding of the noncontracted version of T does not create fan crossings. Also, note that if z1 coincides with u, it remains a leftmost vertex of γ . Analogously, if z2 coincides with
v, it remains a rightmost vertex of γ .
Algorithmica
Case 3: z belongs to the chain root of a feasible maximal k-fence T . Let z1 , . . . , zk
be the chain root of T (z ∈ {z1 , . . . , zk }). Let z0 and zk+1 be the vertices of
scuv (T ) adjacent to z1 and zk , respectively. Also, let wi be the leaf of T adjacent
to zi and let Πi be the path from zi to wi in T (i = 1, . . . , k). We distinguish the
following sub-cases:
Case 3.a: T is a maximal 2-fence. If ω(z1 , w1 ) ≤ ω(z0 , z1 )+1 and ω(z2 , w2 ) ≤
ω(z2 , z3 ) + 1, then the non-contracted version of T is embedded as shown in
Fig. 8(d): The path Π1 from z1 to w1 and the path from z2 to w2 are embedded
to the left of z1 and to the right of z2 , respectively, so that their vertices alternate
with the vertices of the spine. Otherwise, by the definition of 2-fence, it must
be ω(z1 , w1 ) ≤ ω(z2 , z3 ) and ω(z2 , w2 ) ≤ ω(z0 , z1 ). In this case Π1 and Π2
are embedded to the right of z2 and to the left of z1 , respectively, so that their
vertices alternate with those of the spine, as shown in Fig. 8(e). With the same
reasoning applied for Cases 1 and 2, it can be seen that this embedding does not
create fan crossings.
Case 3.b: T is a maximal 3-fence. By definition of feasible 3-fence, either the
subtree induced by z1 , z2 , w1 , w2 is a feasible 2-fence, or the subtree induced by
z2 , z3 , w2 , w3 is a feasible 2-fence. Assume the first case holds, the proof for the
other one is symmetric. By the feasibility of the 3-fence it must be ω(z3 , w3 ) ≤
ω(z3 , z4 ) + 1. The feasible 2-fence consisting of z1 , z2 , w1 , w2 is embedded in
one of the two ways described in Case 3.a. It is easy to see that in both cases Π3
can be embedded to the right of z3 so that its vertices alternate with the vertices
of the spine (see also Fig. 8(f)). Also in this case no fan crossing is created.
Case 3.c: T is a maximal k-fence, with k > 3. By definition of feasible k-fence,
Πi has length at most two for each i = 3, . . . , k − 2; also each of the two sets of
vertices {z1 , z2 , w1 , w2 } and {zk−1 , zk , wk−1 , wk } induces a 2-fence in wc(T ).
Thus, the algorithm embeds Π1 , Π2 and Πk−1 , Πk with the same strategy applied for a 2-fence. Also, for each i = 3, . . . , k − 2, Πi is embedded so that it
crosses at most once the spine and it does not create fan crossings (see Fig. 8(g)
for an example).
According to the description above, each subtree “attached” to the vertices of the
spine can be added to the embedding of the spine without creating fan crossings.
We conclude the proof by observing that although different subtrees, embedded as
described above, can cross each other no fan crossing is created. First, consider two
consecutive vertices zi and zi+1 of scuv (T ). There are at most two paths overlapping
with the subpath of suv (T ) between zi and zi+1 : a path Π1 starting from zi embedded
to the right of zi and a path Π2 starting from zi+1 embedded to the left of zi+1 .
In this case these two paths can be relatively embedded as explained in Cases 1–3,
such that: (i) the leftmost vertices of Π1 ∪ Π2 \ {zi } on both layers belong to Π1 ;
(ii) the rightmost vertices of Π1 ∪ Π2 \ {zi+1 } on both layers belong to Π2 ; (iii) on
each layer the vertices of Π1 alternate with those of Π2 for their overlapping parts
(see, e.g., Fig. 9(a)). This avoids fan crossings. As a further case, there could be two
overlapping paths Π1 and Π2 such that Π1 starts from a vertex zi of suv (T ) and
Π2 starts from a vertex zi+2 of suv (T ) (see, e.g., Fig. 9(b)); this may happen when
Π2 is a path of a feasible 2-fence embedded as shown in Fig. 8(e). Again, a strategy
analogous to that described above is applied to avoid fan crossings.
Algorithmica
Fig. 9 Embedding of two overlapping paths. The bold edges are edges of the spine, the solid (non-bold)
edges are edges of path Π1 , and the dashed edges are edges of Π2 . (a) Both Π1 and Π2 are embedded
analogously to the embedding shown in Figs. 8(b), 8(c), and 8(d). (b) Path Π2 is a path of a feasible
2-fence embedded as shown in Fig. 8(e)
Fig. 10 (a) Illustration for Property 4. (b) Illustration for Property 5. (c) Illustration for Property 6. (d) Illustration for Property 7
5.4 Necessity
In order to prove the necessity condition, we give some simple properties of 2-layer
RAC embeddings, some further definitions, and a technical lemma (Lemma 8). Let
T be a 2-layer RAC drawable tree with respect to two leaves u and v, and let γ =
(π1 , π2 ) be a 2-layer RAC embedding with respect to u and v. Let suv (T ) = u =
z0 , z1 , z2 , . . . , zh , v = zh+1 . The following properties immediately hold.
Property 4 Let w be a vertex that does not belong to the spine suv (T ). Then
deg(w) ≤ 3 and if deg(w) = 3, w is adjacent to a vertex of suv (T ).
Proof Let w be a non-spine vertex having at least three non-spine neighbours u1 ,
u2 , and u3 . We prove that w necessarily creates a fan crossing (see also Fig. 10(a)).
Suppose first that w is not a leftmost or a rightmost vertex in γ , i.e., that w is between
zi and zi+2 in γ for some 0 ≤ i ≤ h − 2. At least two among u1 , u2 , and u3 are either
before zi or after zi+2 in γ . It follows that either (zi , zi+1 ) or (zi+1 , zi+2 ) crosses at
least two among (w, u1 ), (w, u2 ), and (w, u3 ) thus creating a fan crossing. Suppose
Algorithmica
now that w is a leftmost vertex (the case when it is a rightmost vertex is symmetric).
Since z0 is a leftmost vertex by definition, w belongs to the layer that does not contain
u and is to the left of z1 . Also, u1 , u2 , and u3 belong to the same layer as z0 and must
be to the right of z0 (because z0 is a leftmost vertex by definition). It follows that
(z0 , z1 ) crosses (w, u1 ), (w, u2 ), and (w, u3 ) thus creating a fan crossing. From the
argument above and from the fact that a non-spine vertex w can be adjacent to only
one spine vertex (otherwise there would be a cycle), it follows that a non-spine vertex
w can have at most three neighbours one of which must be a spine vertex.
Property 5 Let zi be such that deg(zi ) > 2 (i ∈ {1, . . . , h}) and let w be a non-spine
vertex adjacent to zi . If deg(w) = 3 then deg(zi ) = 3 and w follows zi−1 and precedes
zi+1 in γ .
Proof Let u1 and u2 be the two neighbours of w distinct from zi . Both u1 and u2
do not belong to the spine (otherwise there would be a cycle). If w precedes zi−3 in
γ (assuming that i ≥ 3), then (zi , w) crosses both (zi−2 , zi−3 ) and z(zi−2 , zi−1 ) thus
creating a fan crossing. Analogously, there would be a fan crossing if w follows zi+3
(assuming i ≤ h − 2). If w precedes zi−1 (but follows zi−3 if it exists), then u1 and u2
cannot both precede zi−2 (notice that if w precedes zi−1 , then zi−2 necessarily exists
because u = z0 is a leftmost vertex by definition) either because they would form
a fan crossing with edge (zi−2 , zi−3 ) or, in the case when zi−2 = z0 , because they
would precede the leftmost vertex z0 . Thus, one of them, say u1 , follows zi−2 , but
in this case (w, u1 ), (w, zi ), and (zi−2 , zi−1 ) would form a fan crossing. It follows
that w cannot precede zi−1 . Analogously, w cannot follow zi+1 . So w follows zi−1
and precedes zi+1 in γ .
In order to prove that zi has degree three, we start by observing that one among u1
and u2 must precede zi and the other one must follow zi because otherwise (w, u1 )
and (w, u2 ) would form a fan crossing either with (zi , zi−1 ) or with (zi , zi+1 ) (see
also Fig. 10(b)). Assume that u1 precedes zi and u2 follows zi , and suppose that zi has
degree larger than three. Let u be any neighbour of zi distinct from zi−1 , zi+1 and w.
If u precedes w, then (zi , u), (zi , zi−1 ), and (w, u1 ) would form a fan crossing; if u
follows w, then (zi , u), (zi , zi+1 ), and (w, u2 ) would form a fan crossing. It follows
that zi must have degree three.
Property 6 Let zi be such that deg(zi ) > 2 (i ∈ {1, . . . , h}). If every non-spine vertex
adjacent to zi has degree at most two, then: (i) at most two non-spine vertices w1 and
w2 adjacent to zi have degree two; (ii) w1 and w2 cannot be both to the left of zi−1
or to the right of zi+1 in γ .
Proof The spine vertex zi must have at most two non-spine adjacent vertices w1 and
w2 of degree two, otherwise there would be a fan crossing (Fig. 10(c)). Also, if these
two vertices are both to the left of zi−1 , then (zi , w1 ) and (zi , w2 ) will cause a fan
crossing with an edge incident to zi−1 distinct from (zi−1 , zi ). Analogously, w1 and
w2 cannot be both to the right of zi+1 without causing a fan crossing.
Algorithmica
Fig. 11 Schematic illustration
of a dangling component
incident to a vertex w
Property 7 Let Π1 = u1 , u2 , . . . , uk and Π1 = v1 , v2 , . . . , vh be two monotone
paths in γ such that u1 ∈ V1 and v1 ∈ V2 . If (u1 , u2 ) crosses (v1 , v2 ) in γ , then
(ui−1 , ui ) crosses (vi−1 , vi ) in γ for 2 ≤ i ≤ min{k, h}.
Proof Suppose that the statement is not true and let i be the minimum index such
that (ui−1 , ui ) does not cross (vi−1 , vi ) in γ (3 ≤ i ≤ min{k, h}). Since (ui−1 , ui )
and (vi−1 , vi ) do not cross, then either ui−1 precedes vi and ui precedes vi−1 , or
ui−1 follows vi and ui follows vi−1 . Since (ui−2 , ui−1 ) and (vi−2 , vi−1 ) cross each
other, in the first case (ui−2 , ui−1 ), (ui−1 , ui ), and (vi−2 , vi−1 ) form a fan crossing; in
the second case (vi−2 , vi−1 ), (vi−1 , vi ), and (ui−2 , ui−1 ) form a fan crossing. Thus,
if (u1 , u2 ) crosses (v1 , v2 ), the only possible 2-layer RAC embedding for the two
monotone paths Π1 and Π2 is like the one showed in Fig. 10(d) (the vertices of Π1
are in white and the vertices of Π2 are in gray).
For a vertex zi ∈ suv (T ), we denote by λ(zi ) the closest vertex to zi along the
spine such that λ(zi ) is to the left of zi and deg(λ(zi )) ≥ 3. If there is no vertex
of degree larger than two to the left of zi , then let λ(zi ) = u. Symmetrically, ρ(zi )
denotes the closest vertex to zi along the spine such that ρ(zi ) is to the right of zi and
deg(ρ(zi )) ≥ 3. If there is no vertex of degree larger than two to the right of zi , then
let ρ(zi ) = v.
Let w be a non-spine vertex of T that is adjacent to zi (i ∈ {1, 2, . . . , h}) and let
e = (w, w ) be an edge incident to w with w = zi . Let C be the connected component
obtained by removing e that does not contain zi . The subtree T = C ∪ {e} is called
the dangling component of e. We also say that T is a dangling component incident
to w. Fig. 11 shows an example of a dangling component.
Lemma 8 Let γ = (π1 , π2 ) be a 2-layer RAC embedding of a tree T with respect to
u and v. Let suv (T ) = u = z0 , z1 , z2 , . . . , zh , zh+1 = v, and let w be a non-spine
vertex of T adjacent to zi (i ∈ {1, 2, . . . , h}). Let e = (w, w ) be an edge of T such
that w = zi . The dangling component of e is a monotone path Π in γ . Moreover:
•
•
•
•
if (w, w ) crosses (zi , zi+1 ), then the length of Π is at most d(zi , ρ(zi ));
if (w, w ) crosses (zi−1 , zi ), then the length of Π is at most d(λ(zi ), zi );
if (zi , w) crosses (zi+1 , zi+2 ), then the length of Π is at most d(zi , ρ(zi+1 )) − 2;
if (zi , w) crosses (zi−2 , zi−1 ), then the length of Π is at most d(λ(zi−1 ), zi ) − 2;
Proof First of all, note that the four cases in the statement cover all possible embeddings for the edges e and (zi , w). Since the dangling component Π of e has no vertex
in suv (T ) (otherwise there would be a cycle in T ), then all its vertices have degree
at most 2 by Property 4. Since Π is connected by definition then Π is a path. Also,
Algorithmica
Π is monotone in γ . Indeed, if Π is not monotone then Π would contain a butterfly
blocker. Since suv (T ) connects a leftmost vertex to a rightmost vertex, whatever is
the position of the blocker in γ , an edge of suv (T ) would be a traversing edge for the
butterfly blocker. By Property 3, this contradicts the assumption that γ is a 2-layer
RAC embedding.
We prove now the statement about the length of Π . Without loss of generality
assume that zi ∈ V1 . Let Π = v0 , v1 , . . . , vk , with v0 = w and v1 = w . Consider
first the case when (w, w ) crosses (zi , zi+1 ). By Property 7 edge (vj −1 , vj ) crosses
(zi+j −1 , zi+j ) for 2 ≤ j ≤ k (notice that, since v is a rightmost vertex, i + k ≤ h + 1).
Thus, the length k of Π is equal to d(zi , zi+k ). We need to prove that zi+k is before
ρ(zi ) along Π or zi+k and ρ(zi ) coincide. This follows immediately from the fact
that each zi+j with 1 ≤ j ≤ k − 1 must have degree two because otherwise it would
be part of a degree-3 blocker for Π , i.e., Π would contain a traversing edge for
this degree-3 blocker, which contradicts Property 3. The case when (w, w ) crosses
(zi−1 , zi ) can be proved symmetrically.
Consider now the case when (zi , w) crosses (zi+1 , zi+2 ). By Property 7, edge
(vj −1 , vj ) crosses (zi+j +2 , zi+j +3 ) for 1 ≤ j ≤ k (notice that, since v is a rightmost
vertex, i + k + 3 ≤ h + 1). Thus, the length k of Π is equal to d(zi , zi+k+3 ). We
need to prove that zi+k+3 is before ρ(zi+1 ) or zi+k+3 and ρ(zi+1 ) coincide. Each
zi+j +2 with 1 ≤ j ≤ k must have degree two because otherwise it would be part of
a degree-3 blocker for Π , which still contradicts Property 3. It follows that there
can be only one vertex, namely zi+1 , with degree higher than two after zi and before
zi+k+3 along Π . Hence ρ(zi+1 ) must be after zi+k+2 along Π . The case when (zi , w)
crosses (zi−2 , zi−1 ) can be proved symmetrically.
We are now ready to prove the necessity condition.
Lemma 9 Let T be a tree and let u, v be two leaves of T . Tree T is 2-layer RAC
drawable with respect to u and v only if suv (T ) is a feasible spine.
Proof Let γ be a 2-layer RAC embedding of T with respect to u and v and let
suv (T ) = u = z0 , z1 , z2 , . . . , zh , zh+1 = v. Let zi be a vertex with deg(zi ) > 2
(i ∈ {1, 2, . . . , h}), that is a vertex of scuv (T ). Without loss of generality assume that
zi ∈ V1 . We consider different cases:
Case 1: A neighbor w of zi that is not in suv (T ) has degree 3. By Property 5, w is
the only non-spine vertex adjacent to zi . Also, π2 (zi−1 ) < π2 (w) < π2 (zi+1 ).
Let w1 and w2 be the neighbors of w distinct from zi . They cannot be both to the
left of zi in π1 or both to the right of zi in π1 because otherwise there would be
a fan crossing. Assume that π1 (w1 ) < π1 (zi ) < π1 (w2 ). This means that (w, w1 )
crosses (zi−1 , zi ) and (w, w2 ) crosses (zi , zi+1 ). By Lemma 8, the dangling component T1 of (w, w1 ) is a path whose length is at most d(λ(zi ), zi ), while the dangling component T2 of (w, w2 ) is a path whose length is at most d(zi ρ(zi )). This
means that the weighted contraction of the tree consisting of T1 , T2 , and (zi , w)
is a feasible y-tree whose root is zi .
Case 2: All neighbors of zi that are not in suv (T ) have degree at most 2. We distinguish two sub-cases:
Algorithmica
Case 2.1: deg(zi ) > 3. In this case zi has more than one neighbor not in suv (T ).
By Property 6 at most two of these neighbors have degree two. Assume that they
both exist and denote them as w1 and w2 . Let wj be the vertex adjacent to wj
distinct from zi and let Tj be the dangling component of (wj , wj ) (j ∈ {1, 2}).
Without loss of generality assume that π2 (w1 ) < π2 (w2 ). If π2 (zi−1 ) < π2 (w1 ),
then π2 (w1 ) < π2 (zi+1 ) because w1 is to the left of w2 and they cannot be
both to the right of zi+1 by Property 6. Also, π1 (w1 ) < π1 (zi ) because otherwise (w1 , w1 ) would create a fan crossing with (zi , zi+1 ) and (zi , w2 ). Thus,
(w1 , w1 ) crosses (zi , zi−1 ). By Property 7, T1 is a path whose length is at most
d(λ(zi ), zi ). If π2 (w1 ) < π2 (zi−1 ), then (zi , w1 ) crosses (zi−1 , zi−2 ) and by
Property 7, T1 is a path whose length is at most d(λ(zi−1 ), zi ) − 2. Notice,
however, that in this case it must be deg(zi−1 ) = 2 because an edge incident
to zi−1 distinct from (zi−2 , zi−1 ) and from (zi−1 , zi ) would form a fan crossing either with (zi , w1 ) and (zi−2 , zi−1 ) or with (zi , w2 ) and (zi , zi+1 ). Since
deg(zi−1 ) = 2, then λ(zi−1 ) = λ(zi ), and therefore also in this case T1 is a
path whose length is at most d(λ(zi ), zi ). With a symmetric argument we can
show that T2 is a path whose length is at most d(zi , ρ(zi )). This means that the
weighted contraction of the tree consisting of T1 , T2 , (zi , w1 ), (zi , w2 ), and all
edges connecting zi to its non-spine neighbors is a feasible star-tree.
Case 2.2: deg(zi ) = 3. In this case zi has exactly one neighbor w not in suv (T ).
Let Σ be the maximal sequence, containing zi , of degree-3 vertices of suv (T )
each adjacent to a vertex of degree at most 2. We further distinguish the following cases:
Case 2.2.1: Σ contains a single vertex, i.e., zi . If w is a leaf then edge (zi , w)
is a feasible star tree with root zi . Consider now the case when deg(w) = 2.
Let w be the vertex adjacent to w distinct from zi and let T be the dangling
component of (w, w ). If π2 (zi−1 ) < π2 (w) < π2 (zi+1 ), then π1 (w ) < π1 (zi )
or π1 (zi ) < π1 (w ); in the first case T is a path of length at most d(λ(zi ), zi )
(Property 7), in the second case T is a path of length at most d(zi , ρ(zi ))
(Property 7). In both cases the weighted contraction of the subtree consisting of
T and (zi , w) is a feasible star tree with root zi . If π2 (w) < π2 (zi−1 ) then, by
Property 7, T is a path whose length is at most d(λ(zi−1 ), zi ) − 2. In this case,
however, deg(zi−1 ) = 2 (see Case 2.1) and we have λ(zi−1 ) = λ(zi ). Hence,
also in this case T is a path of length at most d(λ(zi−1 ), zi ). With a symmetric
argument we can show that if π2 (zi+1 ) < π2 (w), then T is a path of length at
most d(zi , ρ(zi )). Thus, also in these two cases the weighted contraction of the
subtree consisting of T and (zi , w) is a feasible star tree with root zi .
Case 2.2.2: Σ contains two vertices. Assume that the vertex in Σ distinct from
zi is zi−1 (if it is zi+1 the proof is analogous). Let w1 be the non-spine vertex
adjacent to zi and let w2 be the non-spine vertex adjacent to zi−1 . Let wj
be the non-spine vertex adjacent to wj (if any) and let Tj be the dangling
component of (wj , wj ), j ∈ {1, 2}. If wj has degree one, Tj is defined as the
path consisting only of vertex wj , so it has length 0. We consider first the
case when π2 (zi−1 ) < π2 (w1 ). If π2 (zi−1 ) < π2 (w1 ) < π2 (zi+1 ) then either
π1 (w1 ) < π1 (zi ), in which case Property 7 implies that T1 is a path whose
length is at most 1 because λ(zi ) = zi−1 , or π1 (zi ) < π1 (w1 ), in which case
Algorithmica
Property 7 implies that T1 is a path whose length is at most d(zi , ρ(zi )). In
both cases the length of T1 is at most d(zi , ρ(zi )). If π2 (zi+1 ) < π2 (w1 ) then
T1 is a path whose length is at most d(zi , ρ(zi+1 )) − 2. In this case, however,
ρ(zi+1 ) = ρ(zi ) because zi+1 must have degree 2. Thus, also in this case the
length of T1 is at most d(zi , ρ(zi )). Concerning T2 , notice that if π2 (zi−1 ) <
π2 (w1 ), it must be π1 (w2 ) < π1 (zi ) because otherwise (zi−1 , w2 ), (zi , w1 ),
and (zi , zi+1 ) would form a fan crossing. With an argument symmetric to the
previous one we can show that T2 is a path whose length is at most d(λ(zi ), zi ).
In summary, we have that if π2 (zi−1 ) < π2 (w1 ), then T1 is a path whose length
is at most d(zi , ρ(zi )) and T2 is a path whose length is at most d(λ(zi ), zi ),
which implies that the weighted contraction of the subtree consisting of T1 , T2 ,
(zi−1 , zi ), (zi−1 , w2 ), (zi , w1 ) is a feasible maximal 2-fence whose chain root
is zi−1 , zi .
Consider now the case when π2 (w1 ) < π2 (zi−1 ), which implies that π1 (zi ) <
π1 (w2 ) because otherwise (zi−1 , w2 ), (zi , w1 ), and (zi−2 , zi−1 ) would form
a fan crossing. Then, by Property 7, T1 is a path whose length is at most
d(λ(zi−1 ), zi )−2, while T2 is a path whose length is at most d(zi−1 , ρ(zi ))−2.
Also in this case he weighted contraction of the subtree consisting of T1 , T2 ,
(zi−1 , zi ), (zi−1 , w2 ), (zi , w1 ) is a feasible maximal 2-fence whose chain root
is zi−1 , zi .
Case 2.2.3: Σ contains three vertices. Assume that the three vertices of Σ are
zi−1 , zi , and zi+1 . Also, let w1 be the non-spine vertex adjacent to zi , let w2
be the non-spine vertex adjacent to zi−1 , and let w3 be the non-spine vertex
adjacent to zi+1 . Let wj be the non-spine vertex adjacent to wj (if any) and
let Tj be the dangling component of (wj , wj ), j ∈ {1, 2}. If wj has degree
one, Tj is defined as the path consisting only of vertex wj , so it has length 0.
We consider first the case when π2 (zi−1 ) < π2 (w1 ) < π2 (zi+1 ). In this case
either π1 (w1 ) < π1 (zi ), in which case Property 7 implies that T1 is a path
whose length is at most 1 because λ(zi ) = zi−1 , or π1 (zi ) < π1 (w1 ), in which
case Property 7 implies that T1 is a path whose length is at most 1 because
ρ(zi ) = zi+1 . Also, it must be π1 (w2 ) < π1 (zi ) and π1 (zi ) < π1 (w3 ) because
otherwise there would be a fan crossing. If π2 (zi−1 ) < π2 (w2 ) then Property 7
implies that T2 is a path whose length is at most 1 because ρ(zi−1 ) = zi . If
π2 (w2 ) < π2 (zi−1 ) then Property 7 implies that T2 is a path whose length is
at most d(λ(zi−1 , zi−1 )). In both cases T2 is a path whose length is at most
d(λ(zi−1 ), zi−1 ). With symmetric arguments we can prove that T3 is a path
whose length is at most d(zi+1 , ρ(zi+1 )). Thus, in the case when π2 (zi−1 ) <
π2 (w1 ) < π2 (zi+1 ), the subtree consisting of T1 , T2 , T3 , (zi−1 , zi ),(zi , zi+1 ),
(zi , w1 ), (zi−1 , w2 ), (zi+1 , w3 ) is a feasible maximal 3-fence (for which both
conditions of the definition of feasible 3-fence hold).
Consider now the case when π2 (w1 ) < π2 (zi−1 ). Analogously to Case 2.2.2,
this implies that π1 (zi ) < π1 (w2 ) and, by Property 7, T1 is a path whose
length is at most d(λ(zi−1 ), zi ) − 2, while T2 is a path whose length is at
most d(zi−1 , ρ(zi )) − 2 which is 0 because ρ(zi ) = zi+1 (in other words
w2 is a leaf). Thus, the subtree consisting of T1 , T2 , (zi−1 , zi ), (zi , w1 ), and
(zi−1 , w2 ) is a feasible maximal 2-fence. Consider now vertex w3 ; it must
Algorithmica
be π1 (w2 ) < π1 (w3 ) because otherwise (zi , zi+1 ), (zi+1 , w3 ), and (zi−1 , w2 )
would form a fan crossing. If π1 (w3 ) < π1 (zi+2 ) then T3 is a path whose length
is at most d(zi+1 , ρ(zi+1 )). If π1 (zi+2 ) < π1 (w3 ) then T3 is a path whose
length is at most d(zi+1 , ρ(zi+2 ))−2. In this case, however, ρ(zi+2 ) = ρ(zi+1 )
because zi+2 must have degree 2. Thus, also in this case the length of T3 is at
most d(zi+1 , ρ(zi+1 )). Thus, in the case when π2 (w1 ) < π2 (zi−1 ), the subtree
consisting of T1 , T2 , T3 , (zi−1 , zi ), (zi , zi+1 ), (zi , w1 ), (zi−1 , w2 ), (zi+1 , w3 )
is a feasible maximal 3-fence (for which the first condition of the definition of
feasible 3-fence holds).
The case when π2 (zi+1 ) < π2 (w1 ) can be treated symmetrically to the case
when π2 (w1 ) < π2 (zi−1 ), thus proving that the subtree consisting of T1 , T2 ,
T3 , (zi−1 , zi ), (zi , zi+1 ), (zi , w1 ), (zi−1 , w2 ), (zi+1 , w3 ) is a feasible maximal
3-fence (for which the second condition of the definition of feasible 3-fence
holds).
Case 2.2.4: Σ contains more than three vertices. Let zj , zj +1 , . . . , zk be the
vertices in Σ.2 Let wl be the vertex adjacent to zl (l ∈ {j, j + 1, . . . , k}). By
using the same arguments as in Case 2.2.2 we can show that the weighted
contraction of the subtree induced by zj , zj +1 , wj , wj +1 and the dangling
components incident to wj and wj +1 is a feasible maximal 2-fence with chain
root zj , zj +1 . Analogously, the weighted contraction of the subtree induced
by zk−1 , zk , wk−1 , wk and the dangling components incident to wk−1 and wk
is a feasible maximal 2-fence with chain root zk−1 , zk .
Let zr be a vertex of Σ with j + 1 < r < k − 1 and assume that zr ∈ V1 .
Consider first the case when π2 (zr−1 ) < π2 (wr ) < π2 (zr+1 ). If wr has degree
2, let wr be the vertex adjacent to wr distinct from zr . Either π1 (wr ) < π1 (zr ),
in which case the dangling component Tr of (wr , wr ) is a path of length at most
d(λ(zr ), zr ) where λ(zr ) = zr−1 , or π1 (zr ) < π1 (wr ), in which case Tr is a
path of length at most d(zr , ρ(zr )) where ρ(zr ) = zr+1 . Thus, in both cases, the
length of Tr is 1 (i.e. it consists of the single edge (wr , wr )). If wr has degree
1, then Tr consists only of vertex wr . Consider now the case when π2 (wr ) <
π2 (zr−1 ). The length of Tr is at most d(λ(zr−1 ), zr ) − 2 where λ(zr−1 ) = zr−2 .
But this means that the length of Tr is zero, i.e., Tr consists only of vertex wr .
The same is true when π2 (zr+1 ) < π2 (wr ). In summary, the subtree consisting
of (zr , wr ) and Tr is a path of length at most 2. This means that the subtree
induced by zj , zj +1 , . . . , zk , wj , wj +1 , . . . , wk , and all dangling components
incident to one of the wj , wj +1 , . . . , wk is a feasible maximal k-fence whose
chain root is zj , zj +1 , . . . , zk .
5.5 Overall Characterization and Testing Algorithm for Trees
The following theorem summarizes Lemmas 7 and 9 and proves the existence of a
linear time testing and embedding algorithm.
2 Notice that j ≤ i ≤ k because z is in Σ .
i
Algorithmica
Theorem 4 Let T be a tree and let u, v be two leaves of T . Tree T is 2-layer RAC
drawable with respect to u and v if and only if suv (T ) is a feasible spine. Also, if
T has n vertices, there exists an O(n)-time algorithm that tests whether T admits a
2-layer RAC drawing with respect to u and v and, if so, it computes such a drawing.
Proof The proof of the characterization is immediate from Lemmas 7 and 9. In order
to test whether T admits a 2-layer RAC drawing with respect to u and v we first compute wc(T ) and scuv (T ). Then we check whether the subtrees rooted at the vertices
of scuv (T ) are feasible maximal k-fence, feasible y-trees, and feasible star-trees. This
check can be performed by scanning the vertices of scuv (T ) in time O(deg(z)) for
each vertex z ∈ scuv (T ), i.e., O(n) time in total. If suv (T ) is a feasible spine a drawing can be computed in O(n) time by using the embedding algorithm described in
the proof of Lemma 7 and the drawing technique of Theorem 1.
The following theorem gives a characterization and a testing and embedding algorithm of 2-layer RAC drawable trees without any fixed leftmost and rightmost
vertices.
Theorem 5 A tree T is 2-layer RAC drawable if and only if it admits a feasible spine.
Also, if T has n vertices, there exists an O(n)-time algorithm that tests whether T is
2-layer RAC drawable and, if so, it computes a 2-layer RAC drawing of T .
Proof If T admits a feasible spine then it is 2-layer RAC drawable by Lemma 7.
Suppose vice-versa that T is 2-layer RAC drawable. Then by Lemma 6 it has a
2-layer RAC embedding with respect to a pair of leaves u and v and by Lemma 9,
suv (T ) is a feasible spine of T .
To prove that there exists a linear time testing algorithm we will show that the
number of pairs of leaves {u, v} such that suv (T ) can be a feasible spine is bounded
by a constant c, and that the set of these pairs of leaves can be computed in linear
time. This leads to an O(n)-time testing algorithm that applies a constant number
of times the testing algorithm of Theorem 4. If the testing algorithm finds a feasible
spine, then a drawing can be computed in O(n) time by applying the embedding
algorithm of Lemma 7 and the drawing algorithm of Theorem 1.
In order to compute the pairs of leaves that are candidate to define a feasible spine,
we first compute wc(T ). If a spine suv (T ) is feasible, each vertex of wc(T ) must have
distance at most two from a vertex of scuv (T ). Hence, we remove twice the leaves
from wc(T ) and test whether the remaining tree is a path: if not the test fails. So
assume that the remaining tree is a path Π from a vertex u to a vertex v ; we call this
path the spine core of wc(T ). Let Vu (Vv respectively) be the set of vertices that are
connected to u (v respectively) by a path that is edge disjoint from Π . We consider
u ∈ Vu (v ∈ Vv respectively). A leaf of Vu ∪ Vv is said to be heavy if its incident
edge in wc(T ) has weight larger than one. The weighted contraction of every spine
candidate to be feasible must contain the spine core; which implies that one of the
end-vertices of the candidate spine must be a leaf of Vu and the other one must be
a leaf of Vv . Consider the leaves of Vu (analogous considerations hold for Vv ); it is
easy to see that a feasible spine can exist only if u has at most two adjacent vertices
Algorithmica
Fig. 12 Illustration for the proof of Theorem 5. The bold line represents the spine core and the gray
vertices represent the heavy leaves of Vu . (a) All leaves of Vu are candidate leaves. (b) There are six
candidate leaves: the heavy ones and one of the non-heavy ones. (c) There are seven candidate leaves: the
heavy ones, one of the non-heavy ones adjacent to u , and one of the non-heavy ones not adjacent to u
in Vu having degree larger than two (otherwise for any possible choice of the spine,
u would have two non-spine adjacent vertices of degree larger than two in wc(T ),
which is not possible by Property 5). This implies that the number of heavy leaves in
Vu is at most five (refer also to Fig. 12). Namely, given a candidate spine suv (T ), the
vertices of Vu that are in scuv (T ) and are not leaves are at most two: one of them is u
and the other one is a vertex u adjacent to u . The subtrees rooted at u and u can
have at most two heavy leaves each. Since one heavy leaf can be u, there can be at
most five heavy leaves in Vu . Each of these leaves must be considered as a possible
end-vertex for a candidate spine. We also need to consider as possible end-vertices for
a candidate spine any arbitrarily chosen non-heavy leaf in the subtree rooted at u and
a arbitrarily chosen non-heavy leaf in the subtree rooted at u . In summary there are
seven leaves in Vu candidate to be an end-vertex of a feasible spine. Symmetrically,
there are seven leaves in Vv candidate to be an end-vertex of a feasible spine and
therefore there are forty-nine pairs of candidate leaves to be tested.
6 Characterization of 2-layer RAC Graphs
We now combine the characterizations of 2-layer RAC drawable trees and 2-layer
RAC biconnected graphs to give a characterization of general 2-layer RAC drawable
graphs. Since a graph G is 2-layer RAC drawable if and only if every connected
component of G is a 2-layer RAC drawable graph, we concentrate on connected
graphs.
A graph G is outerplanarly biconnectible if G is outerplanar and there exist two
vertices {s, t} of G such that G ∪ (s, t) is biconnected. Note that, in this case, a planar
embedding of G ∪ (s, t) is obtained by adding edge (s, t) on the external face of an
outerplanar embedding of G. Let G be a bipartite graph that is neither biconnected
nor a tree. The skeleton of G, denoted as skel(G), is the subgraph of G obtained by
repeatedly removing the vertices of degree one. We denote by {B1 , . . . , Bk } the nontrivial biconnected components of skel(G). We say that skel(G) is feasible if skel(G)
is outerplanarly biconnectible and each Bi (i = 1, . . . , k) contains two independent
edges e and e such that: (a) Each cut-vertex of G belonging to Bi is an end-vertex
of e or e ; (b) Bi is 2-layer RAC drawable with respect to e and e . Note that, for a
feasible skeleton there may be different choices for the extremal edges e or e of each
Algorithmica
Fig. 13 (a) A graph G. The dashed edges are the edges that are not in skel(G). (b) The skeleton skel(G),
which is a feasible skeleton; for each component Bi , the gray vertices represent the cut-vertices of G in
Bi , and the edges in bold represent two edges e, e that cover all the cut-vertices in Bi and such that Bi is
2-layer RAC drawable with respect to e, e . (c) A 2-layer RAC embedding of skel(G). (d) A 2-layer RAC
embedding of G
Bi that guarantee (a) and (b). Each of these choices will be called a feasible choice of
the extremal edges for skel(G) and will be denoted as E(skel(G)).
Figures 13(a)–13(c) show a graph G, its skeleton skel(G) (which is feasible), and
a 2-layer RAC embedding of skel(G). Observe that, if skel(G) is feasible then each
Bi contains at most four cut-vertices of G. Also, the components {B1 , . . . , Bk } form
a sequence such that Bi and Bi+1 are connected by a path Πi from a vertex ui of Bi
to a vertex vi of Bi+1 (i = 1, . . . , k − 1), where ui may coincide with vi . For each
path Πi , we denote by Ti the tree obtained by the union of Πi and all the induced
subtrees of G rooted at the internal vertices of Πi (subtrees rooted at the end-vertices
of Πi will be dealt later). A path Πi is called a bridge of skel(G) and tree Ti is called
the tree of Πi . Note that, if Πi consists of a single vertex then Ti coincides with Πi ;
in this case Πi is also called a degenerate bridge.
It is easy to see that G is 2-layer RAC drawable only if skel(G) is feasible and
each Πi is a feasible spine of Ti (i.e., Ti is 2-layer RAC drawable with respect to ui
and vi ). However, for the characterization, we need some other conditions.
Let T be a tree that is 2-layer RAC drawable with respect to two leaves u and v. We
denote by ν(u, T ) the vertex closest to u along suv (T ) such that deg(ν(u, T )) ≥ 3 in
T . If such a vertex does not exist then ν(u, T ) coincides with v. We can analogously
define ν(v, T ). Let w be a cut-vertex of G that belongs to Bi (1 ≤ i ≤ k). Denote by
T (w) the subtree of G rooted at w. Clearly G is the union of all Bi , all Ti , and all
T (w), for each cut-vertex w of G that belongs to some Bi . Each tree T (w) is called
an addendum of skel(G).
Algorithmica
Fig. 14 Illustration of the different types of addendum. Each addendum in this picture is feasible; bold
edges represent the extremal edges of Bi
We now classify each addendum T (w) of skel(G) and correspondingly define the
partner of T (w) (the concept of “partner” will be used in the proof of Theorem 6).
Also, we define the properties that each type of addendum must satisfy to be embedded correctly in a 2-layer RAC embedding of G whose skeleton is feasible (refer
to Fig. 14). Assume that skel(G) is feasible and that a feasible choice E(skel(G)) is
fixed.
• If w coincides with the single vertex of a degenerate bridge, then T (w) is a tree of
type 1 and it has no partner. T (w) is feasible if it is a star centered at w.
• If w coincides with an end-vertex of a non-degenerate bridge Πi , then T (w) is a
tree of type 2 and its partner is Ti . T (w) is feasible if it consists of a star centered
at w plus at most one path from w to a leaf x such that d(w, x) ≤ d(w, z) + 1,
where z = ν(w, Ti ).
• If w is adjacent to an end-vertex w of a non-degenerate bridge Πi by means of
an extremal edge e of Bi , then T (w) is a tree of type 3 and its partner is Ti . T (w)
is feasible if it consists of a path from w to a leaf x such that d(w, x) ≤ d(w , z),
where z = ν(w , Ti ).
• Otherwise, by the properties of a feasible skeleton, w is a cut-vertex of B ∈
{B1 , Bk } such that one of the two following cases applies:
– w is adjacent, by means of an extremal edge, to another cut-vertex w of G
that belongs to B and that does not belong to any Πi . In this case T (w) and
T (w ) are trees of type 4 and each of them is the partner of the other. Trees
T (w) and T (w ) are feasible if (i) w is a leaf of T (w) and there exists another
leaf u of T (w) such that T (w) is 2-layer RAC drawable with respect to u and
w; (ii) T (w ) is a path from w to a leaf x such that d(w , x) ≤ d(w, z), where
z = ν(w, T (w)).
– w is not adjacent to a cut-vertex, in which case T (w) is of type 5 and has no
partner. T (w) is feasible if it can be decomposed into two subtrees T1 (w) and
Algorithmica
T2 (w) such that: (i) T1 (w)∩T2 (w) = {w} (T2 (w) can consist of w only); (ii) w is
a leaf of T1 (w) and there exists another leaf u of T1 (w) such that T1 (w) is 2-layer
RAC drawable with respect to u and w; (iii) T2 (w) consists of a star centered
at w plus at most one path from w to a leaf x, such that d(w, x) ≤ d(w, z) + 1,
where z = ν(w, T1 (w)).
Observe that, the definition of an addendum T (w) of type 3 and 4 and its feasibility
depend on the choice of the extremal edges of the non-trivial biconnected component
Bi containing w. Hence, in these cases, we also say that T (w) is feasible with respect
to the extremal edges of Bi .
The next theorem gives a characterization of those graphs that are 2-layer RAC
drawable. The proof of the theorem combines the arguments used to prove Theorems 2–5. Figure 13(a) shows a 2-layer RAC drawable graph and Fig. 13(d) depicts
a 2-layer RAC embedding of G.
Theorem 6 A graph G is 2-layer RAC drawable if and only if one of the following
cases holds: (i) G is biconnected and it is a spanning subgraph of a ladder. (ii) G is
a tree that admits a feasible spine. (iii) skel(G) is feasible, each path of skel(G) is a
feasible spine of its tree, and there exists a feasible choice such that each addendum
of skel(G) is feasible. Furthermore, if G has n vertices, there exists an O(n)-time
algorithm that tests whether G is 2-layer RAC drawable and, if so, it computes a
2-layer RAC drawing of G.
Proof We concentrate on case (iii), because cases (i) and (ii) are immediate from
Theorems 3 and 5.
We start by proving the sufficiency. Let B1 , B2 , . . . , Bk be the non-trivial biconnected components of skel(G). If skel(G) is feasible, then B1 , B2 , . . . , Bk form a
sequence such that Bi and Bi+1 are connected by a path Πi from a vertex ui of Bi
to a vertex vi of Bi+1 (i = 1, . . . , k − 1), where ui may coincide with vi . Thus, the
components B1 , B2 , . . . , Bk and the paths Π1 , Π2 , . . . , Πk−1 are embedded from left
to right according to the left-to-right order defined by skel(G). Consider a feasible
choice E(skel(G)) such that each addendum of skel(G) is feasible. Each Bi is embedded according to the algorithm of Lemma 4, with respect to the extremal edges
defined by E(skel(G)), and such that vi−1 is a leftmost vertex and ui is a rightmost
vertex; this is possible because of the feasibility of skel(G). Each path Πi , if not
degenerate, is embedded as a monotone path from ui to vi . See Fig. 13(c) for an
example.
The embedding of each Ti can be completed as described in the proof of Lemma 7.
Each subtree rooted at an internal vertex of Πi can be added to the embedding according to Cases 1, 2, or 3 of Lemma 7. Clearly these additions do not introduce fan
crossings in the embedding of Ti by Lemma 7. It is easy to see that they do not cause
a fan crossing in the embedding of Bi or Bi+1 since all vertices of each subtree rooted
at an internal vertex of Πi are to the right of the rightmost vertices of Bi and to the
left of the leftmost vertices of Bi+1 .
The embedding of G can finally be completed by adding the addenda. Each feasible addendum consists at most of a path and a set of leaves. The structure of each type
of feasible addendum is such that the leaves can be added to the existing embedding
Algorithmica
Fig. 15 2-layer RAC embedding for different types of addendum
without creating a fan crossing; also, the conditions on the length of the path in the
addendum (if present) allow us to embed this path by “interlacing” it with the spine
of its partner without causing fan crossings, similarly to what described in the proof
of Lemma 7 (for a type-5 addendum T (w) we first embed T1 (w) with the algorithm
for trees and then add T2 (w) as if T1 (w) were its partner). Figure 15 shows how to
embed each type of addendum (refer also to Fig. 14). It is immediate to see that the
constructed embedding does not contain fan crossings, and hence it is a 2-layer RAC
embedding of G.
We now prove the necessity condition. If G is 2-layer RAC drawable then it has a
2-layer RAC embedding γ , which fixes a feasible choice E(skel(G)) for the extremal
edges of each non-trivial biconnected component Bi of skel(G). Denote by γBi the
embedding of Bi in γ . By Theorem 2, Bi is a spanning subgraph of a ladder (and
hence it is outerplanar) and its embedding is a 2-layer RAC embedding with respect
to its extremal edges e and e ; also, the simple cycle passing through all vertices of
the ladder has an interlaced embedding in γBi . If Bi contains a cut-vertex w of G that
is not incident to e or e , then an edge incident to w that does not belong to Bi would
cause a fan crossing. Also, Bi can share at most two cut-vertices w and w with some
other non-trivial biconnected components, where w is an end-vertex of e and w is
an end-vertex of e ; if not, there would be some fan crossings. Hence, skel(G) is also
biconnectible, and then it is feasible; also the embedding of skel(G) in γ is such that
each γBi is to the left of γBi+1 and each path Πi is embedded as a monotone path (see
Fig. 13(c)).
Denote by γTi the embedding of Ti in γ . Clearly, γTi is a 2-layer RAC embedding
and since Πi is a monotone path in γ , the end-vertices ui and vi of Πi are the leftmost
and the rightmost vertex of Πi in γ , respectively. Also, there cannot be a vertex of Ti
to the left of ui or a vertex of Ti to the right of vi in γ , because otherwise an edge of
Algorithmica
Ti would traverse a butterfly blocker of Bi or Bi+1 . Since, ui and vi are leaves of Ti
by definition, Theorem 4 implies that Πi is a feasible spine of Ti .
Let w be a cut-vertex of G that belongs to some Bi . We prove that, for the given
feasible choice E(skel(G)), T (w) is feasible. We distinguish between the different
types of addendum:
T (w) is of type 1: No vertex of T (w) can be to the left of a vertex of Bi or to the
right of a vertex of Bi+1 because otherwise an edge of T (w) would traverse a
butterfly blocker of Bi or Bi+1 . Thus T (w) consists of a star centered at w.
T (w) is of type 2: Also in this case no vertex of T (w) can be to the left of a vertex
of Bi . So any path of T (w) whose length is more than one (long path), must be
embedded to the left of the extremal edge (w, w ) of Bi ; on the other hand there
cannot be more than one long path to the left of (w, w ) because otherwise there
would be a fan crossing. Thus T (w) consists of at most one long path and of an
arbitrary number of vertices adjacent to w (possibly zero). Finally the length of
the long path must be at most d(w, z) + 1 with z = ν(w, Ti ) because otherwise
the path would traverse a degree-3 blocker.
T (w) is of type 3: Also in this case any long path of T (w) must be embedded to the
left of the extremal edge (w, w ) of Bi and there can be at most one long path. On
the other hand there can be at most one edge incident to w in T (w) because any
pair of edges incident to w would form a fan crossing with the first edge of Πi .
Thus T (w) consists of a single path whose length must be at most d(w, z) with
z = ν(w , Ti ) because otherwise the path would traverse a degree-3 blocker.
T (w) is of type 4: Analogous to type 3.
T (w) is of type 5: Analogous to type 2.
Concerning the time complexity of the testing algorithm, we observe that skel(G),
the non-trivial biconnected components Bi , the bridges Πi and their trees Ti can all be
computed easily in O(n) time. The feasibility of a non-trivial biconnected component
Bi with respect to two edges e, e can be tested in O(nBi ) time by Theorem 2, where
nBi is the number of vertices of Bi . Indeed, the test of Theorem 2 is executed a
constant number of times for each Bi , because the number of pairs of edges {e, e }
with respect to which Bi can be embedded is at most four. Namely, Bi contains at
least one cut-vertex w of G, and therefore one among e and e must coincide with
one of the two edges incident to w; for each of the two possible choices, the other
edge among e and e is uniquely identified by the fact that the distances between
the end-vertices of the extremal edges of a ladder with nBi vertices is nBi /2. Also,
testing that e, e contain all the cut-vertices of G in Bi can be done in constant time.
Thus, the feasibility of the skeleton can be tested in O(n) time. Note that, if Bi is
feasible with respect to different pairs {e, e }, one can arbitrarily choose one of these
pairs in order to embed skel(G). Hence, to test the feasibility of skel(G) it would
be sufficient to find that at least one such pair exists. However, while the choice of
any pair guarantees the embeddability of skel(G), not all choices guarantee that the
addenda can be added to the embedding of skel(G). Hence, during the feasibility test
of each Bi , we store in a set S(Bi ) all pairs {e, e } of edges with respect to which
Bi can be embedded. The sets S(Bi ) will be used later to test the feasibility of the
addenda and to fix a feasible choice E(skel(G)) accordingly.
Algorithmica
The feasibility of each Ti with respect to two leaves can be tested in O(nTi ) time
by Theorem 4, where nTi is the number of vertices of Ti .
Finally, consider an addendum T (w) and denote by nT (w) its number of vertices.
If T (w) is of type 1, 2 or 5 (recall that these types do not depend on the particular
feasible choice), its feasibility can be tested in O(nT (w) ) time with a technique similar
to that described in Theorem 4. Otherwise, for each pair of extremal edges stored in
S(Bi ), we determine the type (3 or 4) of T (w) and we test its feasibility with respect
to that pair in O(nT (w) ) time using again a technique similar to that described in
Theorem 4. If there exists at least one pair such that T (w) is feasible with respect to
that pair, then Bi is embedded with respect to that pair (recall that any pair in S(Bi )
guarantees the feasibility of skel(G)). If T (w) is not feasible with respect to any pair
in S(Bi ), then there is no pair that guarantees both the feasibility of skel(G) and of
T (w) and therefore the whole test fails.
Thus the overall time complexity for the testing algorithm is O(n). If G is
2-layer RAC drawable, a 2-layer RAC embedding can be computed, as described
in the sufficiency proof, by suitably combining and adapting the algorithms for biconnected graphs and for trees. It is easy to see that the embedding algorithm runs in
O(n) time.
Since by Theorem 6, ladders are the densest graphs admitting a 2-layer RAC drawing, it is immediate to derive the following bound.
Corollary 1 A 2-layer RAC drawable graph with n vertices has at most 1.5n − 2
edges, which is a tight bound.
7 Crossing Minimization
We show that if G is a 2-layer RAC drawable graph then a 2-layer RAC drawing of
G with the minimum number of crossings can be computed in polynomial time. If
G is a biconnected graph then each 2-layer RAC drawing of G has the same number
of crossings by Lemma 1 and Theorem 3; this number is equal to (n − 2)/2, where
n is the number of vertices of G. In the following we first explain how to solve the
crossing minimization problem for 2-layer RAC drawable trees, and then we explain
how to deal with general graphs.
7.1 Trees
Suppose that T is a 2-layer RAC drawable tree with respect to two leaves u and v
and let scuv (T ) = u = z0 , z1 , z2 , . . . , zh , zh+1 = v. For the sake of simplicity, we
consider first the case when wc(T ) does not contain maximal k-fences, i.e., each zi is
the root of a subtree T that is either a y-tree or a star-tree of wc(T ). In both cases, the
non-contracted version of T contains at most two paths Πi,1 and Πi,2 , going from zi
to two leaves xi,1 and xi,2 , respectively, such that d(zi , xi,1 ) > 1 and d(zi , xi,2 ) > 1.
Note that, if T is a y-tree, Πi,1 and Πi,2 share the first edge. In a 2-layer RAC
embedding γ of T , Πi,1 and Πi,2 are embedded one to the left and one to the right
Algorithmica
Fig. 16 (a) Two matched paths Πi−1,l and Πi,j . We have d(zi−1 , xl ) = 4, d(zi , xj ) = 7, and
d(zi−1 , zi ) = 6. The number of crossings between Πi−1,l and Πi,j is 2. (b) A schematic view of the
spine of a 2-layer RAC drawable tree T and of the paths Πi,j . (c) The network N associated with the tree
T schematized in (b)
of zi , as explained in Sect. 5.3 (see Fig. 8(b), where zi = z, xi,1 = a, xi,2 = b, and
Fig. 8(c), where zi = z, xi,1 = w1 , xi,2 = w4 ). If d(zi−1 , zi ) and d(zi , zi+1 ) are both
greater than or equal to max{d(zi , xi,1 ) − 1, d(zi , xi,2 ) − 1}, then we can arbitrarily
decide which path Πi,j goes to the left of zi and which one goes to the right of zi (j =
1, 2); in this case, we say that Πi,1 and Πi,2 are free paths, otherwise we say that they
are constrained paths. The number of crossings that Πi,j forms with the spine suv (T )
is the same for each of the two choices, and it is equal to d(zi , xi,j ) − 1. However, the
path Πi,j embedded to the left of zi may form some crossings with a path Πi−1,l (l =
1, 2) embedded to the right of zi−1 , if such a path exists; if so, the number of crossings
between the two paths is at least d(zi , xi,j ) + d(zi−1 , xi−1,l ) − d(zi−1 , zi ) − 3, and
the embedding constructed with our technique (see the proof of Lemma 7) matches
this number (see also Fig. 16(a)). Hence, the problem of computing a 2-layer RAC
embedding of T with the minimum number of crossings reduces to the problem of
embedding each path Πi,j to the left or to the right of zi so that the total number
of crossings between all paths is minimized. In the following we assume that for
each vertex zi (i = 1, . . . , h) there are exactly two paths Πi,1 and Πi,2 . If not, we
can attach to zi dummy paths of length 1, which can always be embedded without
crossings.
If γ is a 2-layer RAC embedding where Πi,j is to the left of zi and Πi−1,l is to the
right of zi−1 we say that Πi,j and Πi−1,l are matched, and the cost of their matching
equals max{0, d(zi , xi,j ) + d(zi−1 , xi−1,l ) − d(zi−1 , zi ) − 3}. Observe that, each path
Πi,j is matched with some other path in γ , except the path to the left of z1 and the
path to the right of zh (because these two paths do not cross any other path). Hence,
if γ is a 2-layer RAC embedding with the minimum number of crossings, γ corresponds to a maximum matching among 2h − 2 paths whose total cost is minimum.
Furthermore, the path to the left of z1 in γ is the longest between Π1,1 and Π1,2 ,
unless Π1,1 and Π1,2 are constrained to be embedded in the other way. Similarly, the
path to the right of zh is the longest between Πh,1 and Πh,2 , unless Πh,1 and Πh,2
are constrained to be embedded in the other way.
To compute a 2-layer RAC embedding γ with the minimum number of crossings,
we compute the corresponding optimal matching by solving a minimum cost flow
problem on a suitable capacitated network N , having a single source and a single
sink. In the description of the network, we assume that Π1,2 is the path that will be
embedded to the right of z1 and that Πh,1 is the path that will be embedded to the
Algorithmica
left of zh (if not, we can relabel the paths). Network N is defined as follows (refer to
Figs. 16(b) and 16(c)):
• Nodes: N has a node vi,j for each path Πi,j (i = 2, . . . , h − 1), (j = 1, 2). Also it
has a node v1,2 associated with the path Π1,2 , and a node vh,1 associated with the
path Πh,1 . Finally, N has two extra nodes s (the source) and t (the sink).
• Arcs: For each index 1 ≤ i ≤ h, N has the arcs (vi,j , vi+1,l ) and (vi,j , vi−1,l )
(j = 1, 2), (l = 1, 2), for those indices for which the corresponding nodes exist.
So far, the subgraph induced by all vertices distinct from s and t is a bipartite
graph. Orient all arcs from the vertices that are in one partite set to the vertices in
the other partite set. Finally, add to N directed arcs from s to every source and
directed arcs from every sink to t, so that s and t become the only source and the
only sink of N , respectively.
• Costs and capacities: Arcs (s, vi,j ) and (vi,j , t) have cost 0 and capacity 1.
Each arc (vi,j , vi+1,l ) has cost equal to max{0, d(zi , xi,j ) + d(zi+1 , xi+1,l ) −
d(zi , zi+1 ) − 3} and each arc (vi,j , vi−1,l ) has cost equal to max{0, d(zi , xi,j ) +
d(zi−1 , xi−1,l ) − d(zi−1 , zi ) − 3}. Also, if Πi,1 and Πi,2 are free paths (2 ≤ i ≤
h − 1), then all arcs incident to vi,1 and vi,2 have capacity 1. Otherwise, assume
that Πi,1 (resp. Πi,2 ) is constrained to be embedded to the left (resp. right) of zi ;
in this case the capacities of arcs (vi,1 , vi+1,l ) and (vi,2 , vi−1,l ) are 0, while the
capacities of (vi,1 , vi−1,l ) and (vi,2 , vi+1,l ) are 1.
An integer feasible flow on N corresponds to a matching among paths Πi,j .
Namely, a flow of value 1 on an arc (vi,j , vi−1,l ) means that Πi,j and Πi−1,l are
matched. By construction, N always admits a feasible integer flow of value h − 1,
which is also maximum. Thus, a maximum flow of minimum cost in N corresponds
to a maximum matching of minimum cost among paths Πi,j , and this matching correctly defines the crossings in a 2-layer RAC embedding γ . Since h = O(n) and both
the number of nodes and the number of arcs of N are O(h), a maximum flow of
minimum cost can be computed in O(n2 log n) time by using the successive shortest
path algorithm [2].
Observe that, a matching that is not maximum might not correspond to a feasible 2-layer RAC embedding. For example, in Fig. 16, a matching such that Π3,1 is
matched with Π4,1 and Π3,2 is matched with Π4,2 does not correspond to any 2-layer
RAC embedding. However, such a matching would not be maximum, because Π5,1
would not be matched with any path.
7.1.1 Extending the model to maximal k-fences
In the discussion above we considered only the case when the weighted contracted
version of the tree does not contain maximal k-fences and we have seen that the
problem reduces to that of suitably embedding the two paths that are “attached” to
each vertex of the spine of wc(T ). If wc(T ) contains a maximal k-fence T , then
there is only one path “attached” to each vertex of the chain root of wc(T ); on the
other hand, while in the case of star-trees and y-trees the fact that a path can be
embedded to the left or to the right of its root depends only on its length, in the case
of maximal k-fences one of the paths attached to a vertex of the chain root can force
Algorithmica
the embedding of the other paths. However, the problem can be still modeled as a
matching problem.
Let T be 2-layer RAC drawable tree and let suv (T ) be a spine of T ; let T be a
maximal k-fence of wc(T ) (k ≥ 2), let zi , zi+1 , . . . , zi+k−1 be the chain root of T ,
and let wj be the leaf adjacent to zj in T (i ≤ j ≤ i + k − 1). Finally, denote by Πj
the path of T corresponding to edge (zj , wj ) of T . We consider the following cases:
• k = 2. We have two choices for the embedding of Πi and Πi+1 : (i) Πi is embedded to the left of zi and Πi+1 is embedded to the right of zi+1 (see Fig. 8(d) where
i = 1); or (ii) Πi is embedded to the right of zi and of zi+1 and Πi+1 is embedded
to the left of zi+1 and of zi (see Fig. 8(e) where i = 1). We call the embedding of
case (i) a standard embedding, and the embedding of type (ii) a non-standard embedding. For a standard embedding, Πi is matched with either Πi−1,1 or Πi−1,2 ,
while Πi+1 is matched with either Πi+2,1 or Πi+2,2 . For a non-standard embedding Πi is matched with either Πi+2,1 or Πi+2,2 , while Πi+1 is matched with
either Πi−1,1 or Πi−1,2 .
Hence, the network N has nodes vi and vi+1 that represent Πi and Πi+1 and
arcs (vi , vi−1,1 ), (vi , vi−1,2 ), (vi , vi+2,1 ), (vi , vi+2,2 ), (vi+1 , vi−1,1 ), (vi+1 , vi−1,2 ),
(vi+1 , vi+2,1 ), and (vi+1 , vi+2,2 ) (see Fig. 17). Again, the network induced by the
vertices distinct from s and t is bipartite, and the arcs can be oriented from the
partite set connected to s to the one connected to t.
The weights of these edges is given by a formula slightly different from the
ones used above. Let xj be the end-vertex of Πj distinct from zj (j = i, i + 1).
If Πj has a standard embedding it crosses the spine d(zj , xj ) − 1 times; if Πj
has a non-standard embedding it crosses the spine d(zj , xj ) times. Also, let Πj be
matched with and Πg,l and let zg,l be the end-vertex of Πg,l distinct from zg (g ∈
{i − 1, i + 2}, l ∈ {1, 2}). If both Πj and Πg,l have a standard embedding (if a path
belongs to a y-tree or a start-tree its embedding is always considered a standard
embedding), then Πj and Πg,l form a number of crossings that is d(zj , xj ) +
d(zg , xg,l ) − d(zj , zg ) − 3 (see Fig. 18(a)). If only one among Πj and Πg,l has
a non-standard embedding, the number of crossing between them is d(zj , xj ) +
d(zg , xg,l ) − d(zj , zg ) − 1 (see Fig. 18(b)). Finally, if both Πj and Πg,l have a nonstandard embedding, the number of crossing is d(zj , xj )+d(zg , xg,l )−d(zj , zg )+
1 (see Fig. 18(c)). Thus, the cost of edge (vj , vg,l ) (j ∈ {i, i + 1}, g ∈ {i − 1, i + 2},
l ∈ {1, 2}) in the network N is given by:
Fig. 17 (a) Schematic view of a portion of the spine of a 2-layer RAC drawable tree T that contains a
maximal 2-fence. (b) Portion of the network N that models the 2 fence
Algorithmica
Fig. 18 Two matched paths Πi,j and Πg,l . In all the three pictures we have d(zi , xi,j ) = d(zg , xg,l ) = 6
and d(zi , zg ) = 8. (a) Both Πi,j and Πg,l have a standard embedding; Πi,j and Πg,l form 1 crossing;
also, both Πi,j and Πg,l form 5 crossings with the spine. (b) Πi,j has a non-standard embedding while
Πg,l has a standard embedding; Πi,j and Πg,l form 3 crossing; also, Πi,j forms 6 crossings with the
spine while Πg,l form 5 crossings with the spine. (c) Both Πi,j and Πg,l have a non-standard embedding;
Πi,j and Πg,l form 5 crossing; also, both Πi,j and Πg,l form 6 crossings with the spine
– max{0, d(zj , xj ) + d(zg , xg,l ) − d(zj , zg ) − 3} if the matching represented by
edge (vj , vg,l ) corresponds to a standard embedding for both Πj and Πg,l ;
– max{0, d(zj , xj ) + d(zg , xg,l ) − d(zj , zg )} if the matching represented by edge
(vj , vg,l ) corresponds to a non-standard embedding for only one among Πj and
Πg,l (notice that the formula includes the additional crossing that Pj or Pg,l
forms with the spine);
– max{0, d(zj , xj ) + d(zg , xg,l ) − d(zj , zg ) + 2} if the matching represented by
edge (vj , vg,l ) corresponds to a non-standard embedding for both Πj and Πg,l
(also in this case the formula includes the two additional crossing that Pj and
Pg,l form with the spine).
• k = 3. In this case there are different choices for embedding the three paths Πi ,
Πi+1 , and Πi+2 . Case 1: Πi is forced to have a standard embedding (which happens if Πi consists of more than one edge); in this case Πi+1 , and Πi+2 either have
both a standard embedding or they have both a non-standard embedding. Case 2:
Πi+2 is forced to have a standard embedding (which happens if Πi+2 consists of
more than one edge); Πi , and Πi+1 either have both a standard embedding or they
have both a non-standard embedding. Case 3: Neither Πi nor Πi+2 are forced to
have standard embeddings (which implies that they have length one) and Πi+1
has length at most two; in this case the minimum number of crossings is obtained
by choosing a standard embedding for all the three paths. Case 4: Neither Πi nor
Πi+2 are forced to have standard embeddings (which implies that they have length
one) and Πi+1 has length more than two; in this case either Πi , Πi+1 have a nonstandard embedding and Πi+2 has a standard one or Πi has a standard embedding
and Πi+1 , Πi+2 have a non-standard one. The network N has the following nodes
and arcs (see Fig. 19 for an illustration):
Case 1: N has nodes vi+1 and vi+2 to represent Πi+1 and Πi+2 , respectively; also N has a vertex vi,1 that represents Πi and a dummy vertex
vi,2 (vi,1 and vi,2 will belong to the same partite set); this dummy vertex is necessary to guarantee that the two partite sets of the network still
have the same number of vertices, and therefore that each vertex of the network distinct from s and t will be covered by a maximum matched. The
arcs are (vi,1 , vi−1,1 ), (vi,1 , vi−1,2 ), (vi+1 , vi,2 ), (vi+1 , vi+3,1 ), (vi+1 , vi+3,2 ),
(vi+2 , vi,2 ), (vi+2 , vi+3,1 ), and (vi+2 , vi+3,2 ). The costs of these arcs are com-
Algorithmica
Fig. 19 (a) Schematic view of a portion of the spine of a 2-layer RAC drawable tree T that contains a
maximal 3-fence. (b)–(d) Portions of the network N that model the different cases for a 3-fence
puted with the same reasoning followed for k = 2; the cost of each arc incident
to the dummy vertex vi,2 is zero (this arc does not really correspond to a path,
and therefore it does not generate crossings).
Case 2: This case is symmetric to Case 1.
Case 3: N has nodes vi and vi+2 to represent Πi and Πi+2 , respectively; the
arcs are (vi , vi−1,1 ), (vi , vi−1,2 ), (vi+2 , vi+3,1 ), and (vi+2 , vi+3,2 ). The costs
of these arcs are computed with the same reasoning followed for k = 2.
Case 4: N has a node vi+1,1 that represents path Πi+1 and a dummy node
vi+1,2 , which is still inserted to guarantee that any maximum matching covers all nodes (again vi+1,1 and vi+1,2 will belong to the same partite set).
The arcs are (vi+1,1 , vi−1,1 ), (vi+1,1 , vi−1,2 ), (vi+1,1 , vi+3,1 ), (vi+1,1 , vi+3,2 ),
(vi+1,2 , vi−1,1 ), (vi+1,2 , vi−1,2 ), (vi+1,2 , vi+3,1 ), and (vi+1,2 , vi+3,2 ). The
costs of these arcs are computed with the same reasoning followed for k = 2;
the cost of each arc incident to vi+1,2 is zero.
• k ≥ 4. In this case the two 2-fences induced by zi , zi+1 , wi , and wi+1 and by
zi+k−2 , zi+k−1 , wi+k−2 , and wi+k−1 are represented in N as described for the
case k = 2. The embedding with the minimum number of crossings for each of the
paths Πj with i + 2 ≤ j ≤ i + k − 3 (if they exist) is the standard embedding; as a
consequence these paths are not represented in N .
7.2 General graphs
We conclude this section with a brief discussion on how to minimize crossings when
G is a general 2-layer RAC drawable graph (neither a tree nor a biconnected graph).
Since, as observed above, the non-trivial biconnected components have the same
Algorithmica
number of crossings in any possible 2-layer RAC embedding, minimizing the crossings consists in choosing an embedding for each tree Ti (as described in the previous
section) and for each addendum T (w). As explained in Sect. 6 the type of each addendum and its partner depends on the choice of the extremal edges of the non-trivial
biconnected components. Consider a specific feasible choice E(skel(G)). Let T (w)
be an addendum of type 2 or 3 (the addendum of type 1 does not cause any crossing),
let Ti be its partner, and let scuv (Ti ) = u = z0 , z1 , . . . , zh , zh+1 = v. Assume that
w = u if T (w) is of type 2 and that w is adjacent to u if T (w) is of type 3. T (w)
has at most one path Πw of length greater than one; also, in any possible 2-layer
RAC embedding of G that respects the feasible choice E(skel(G)), Πw is embedded
in such a way that it crosses the spine of Ti and, possibly, a path Π1,j (j ∈ {1, 2})
of Ti that is attached to z1 and that is embedded to the left of z1 , i.e., Πw and Π1,j
are matched. Thus, in order to minimize the number of crossings in the 2-layer RAC
embedding of Ti , we can define a network Ni for Ti analogously to what we do for
trees without addenda, with the only difference that both paths attached to z1 (and
to zh ) must be considered (recall that for trees without addenda we need to consider
only one of the paths attached to z1 and one of those attached to zh ) and the path
Πw must also be considered for a possible matching with Π1,1 and Π1,2 . If Tw is
of type 2, Πw has to be considered as a path of length d(w, x), where x is the endvertex of Πw distinct from w, while if Tw is of type 3, Πw has to be considered as a
path of length d(w, x) + 1, in order to take into account also edge (u, w). Addenda
of type 4 or 5 can be treated analogously. If we consider a feasible choice different
from E(skel(G)), then the partners of some addenda can be different thus leading to
a different number of crossings. Let Bi be a non-trivial biconnected component of
skel(G), let Πi−1 and Πi be the bridges preceding and following Bi along skel(G),
let vi−1 be the vertex shared by Πi−1 and Bi , and let ui be the vertex shared by Bi
and Πi . Bi has at most two addenda T (w1 ) and T (w2 ). If Bi has more than four
vertices, then the type and the partner of both addenda is uniquely defined. Namely,
w1 coincides with or is adjacent to vi−1 , while w2 coincides with or is adjacent to ui ,
which implies that the partner of T (w1 ) is Ti−1 , while the partner of T (w2 ) is Ti . If
Bi has four vertices, and if w1 and w2 are both distinct from ui and vi−1 , then the
extremal edges of Bi can be either (vi−1 , w1 ) and (ui , w2 ) (in which case the partner
of T (w1 ) is Ti−1 and the partner of T (w2 ) is Ti ) or (vi−1 , w2 ) and (ui , w1 ) (in which
case the partner of T (w1 ) is Ti and the partner of T (w2 ) is Ti−1 ) (see also Fig. 20). In
other words, we have to decide whether to embed T (w1 ) to the left of Bi and T (w2 )
to the right of Bi , or vice versa.3
Based on the discussion above we can compute a 2-layer RAC embedding of G
with the minimum number of crossings as follows. We contract each non-trivial biconnected component Bi into a single vertex bi (coinciding with vi−1 and with ui );
this replacement transforms G into a tree TG and skel(G) into a path Πskel(G) . If
Bi has no addenda, we attach to bi a dummy path of length 1. We do this to avoid
that a path attached to Πi (Πi−1 respectively) is embedded with some vertices to
3 In this discussion we consider the case when B is preceded by a bridge and followed by another bridge.
i
If Bi is the first or the last non-trivial biconnected component of skel(G) the situation is analogous, the
only difference being that the type of either T (w1 ) or T (w2 ) is 4 or 5, instead of 2 or 3.
Algorithmica
Fig. 20 Embedding of the addenda of a non-trivial biconnected component Bi with four vertices.
(a) Bi and its addenda. (b) The extremal edges are (vi−1 , w1 ) and (ui , w2 ); the partner of T (w1 ) is
Ti−1 and the partner of T (w2 ) is Ti . (c) The extremal edges are (vi−1 , w2 ) and (ui , w1 ); the partner of
T (w1 ) is Ti and the partner of T (w2 ) is Ti−1
the left of bi (to the right of bi respectively). The subtrees rooted at the vertices of
Πskel(G) are either subtrees of some Tj or addenda. The embedding of each subtree
that minimizes the total number of crossings can be computed by defining a flow
network N for TG analogous to the one described for trees. The addenda that can be
embedded only to the left or to the right of their non-trivial biconnected component
will be treated as constrained path; those for which two choices are possible will be
considered as free paths.
Theorem 7 Let G be a graph that is 2-layer RAC drawable. There exists an
O(n2 log n) time algorithm that computes a 2-layer RAC embedding of G with the
minimum number of crossings.
8 Maximum 2-layer RAC Drawable Subgraph
We prove that the problem of computing the maximum 2-layer RAC drawable subgraph of a bipartite graph is N P-hard. The corresponding decision problem can be
stated as follows:
M AXIMUM 2- LAYER RAC S UBGRAPH (M2LS)
Instance: G, k, where G is a bipartite graph and k is a positive integer
Question: Does G admit a 2-layer RAC drawable subgraph with k edges?
Theorem 8 M2LS is N P-complete
Proof Guessing an ordering of the vertices along the bottom and top layers provides
a proof that M2LS is in N P. To prove that M2LS is N P-hard, we transform HP3 to
M2LS, where HP3 is the problem of deciding whether a cubic graph has a Hamiltonian path.
H AMILTONIAN PATH ON CUBIC GRAPHS (HP3)
Input: a connected cubic graph G
Question: Does G have a Hamiltonian path?
Suppose that G is an instance of HP3 with n vertices; note that G has 3n/2 edges.
Construct a graph G by replacing each edge e = (u, v) of G by two paths pe =
Algorithmica
Fig. 21 (a) A connected cubic graph G with n = 6 vertices. The bold edges form a Hamiltonian path
of G. (b) The graph G corresponding to G. The bold edges define a 2-layer RAC drawable subgraph S
with 5n − 2 = 28 edges. (c) A 2-layer RAC embedding of S
(u, xe , v) and qe = (u, ye , v) of length 2. The two paths pe and qe form a cycle of
length 4. Note that G is bipartite where one partition set consists of the vertices
of G, and the other partition set consists of the vertices xe and ye for each edge e. Let
k = 5n − 2. We show that G has a Hamiltonian path if and only if G has a 2-layer
RAC subgraph with k edges.
Suppose that G has a Hamiltonian path Π = u1 , u2 , . . . , un ; we define a 2-layer
RAC subgraph S of G as follows. For each edge e = (ui , ui+1 ) in Π , we include all
the edges of pe and qe in S. The total number of edges in these paths is 4(n − 1).
Also, since G is cubic, there are n2 + 1 edges of G that do not belong to Π . For each
edge e = (uj , uk ) of
in Π , add to S the edges (uj , xe ) and (ye , uk ). Hence,
G not
S has 4(n − 1) + 2 n2 + 1 = 5n − 2 edges in total. It is easy to see that S is 2-layer
RAC drawable (see also Fig. 21).
Suppose viceversa that S is a 2-layer RAC drawable subgraph of G with 5n − 2
edges. Note that, each edge of G has an end-vertex of degree 2. It follows from
Theorem 3 that every non-trivial biconnected 2-layer RAC drawable subgraph of
G is a cycle (because otherwise this subgraph would contain an edge whose endvertices have both degree 3). Hence every non-trivial biconnected component of S
is a cycle. It follows that S has at most n + c − 1 edges, where n is the number of
vertices of G and c is the number of non-trivial biconnected components of S. Thus
5n − 2 ≤ n + c − 1 = 4n + c − 1, and so c ≥ n − 1. That is, S contains at least n − 1
cycles.
Now a 2-layer RAC drawing of S has the vertices of G on one layer and the vertices xe and ye on the other layer. Suppose that the left-right ordering of the vertices
of G is (u1 , u2 , . . . , un ). If C is a cycle in S then it must contain at least two vertices
of G. Also, since S is 2-layer RAC drawable and has at least n − 1 cycles, then the
number of vertices of G shared by these cycles is at most n − 2 (recall that the 2-layer
RAC drawing of each cycle is an interlaced embedding, and therefore two cycles can
only share one vertex, which is a leftmost or a rightmost vertex). Hence, if each cycle
contains exactly four vertices of G, then the total number of vertices of G in S is at
least n. Since G contains n vertices, no cycle can have more than four vertices of G.
It follows that, for each i = 1, 2, . . . , n − 1, S has a cycle that contains ui and ui+1 ,
and thus u1 , u2 , . . . , un is a Hamiltonian path of G.
Algorithmica
9 Conclusions and Open Problems
We studied straight-line drawings of bipartite graphs such that the vertices of every
partition set are aligned on one of two horizontal lines. This representation paradigm,
called 2-layer paradigm, is among the most natural and widely investigated for the
bipartite graphs. Motivated by the recent and growing interest into RAC drawings,
i.e. drawings where any two crossing edges are orthogonal to one another we studied
2-layer straight-line RAC drawings of bipartite graphs. The paper addressed both
combinatorial, and algorithmic questions. A complete characterization of the bipartite
graphs that admit a 2-layer graph drawing is presented; based on this characterization,
an O(n)-time testing and embedding algorithm is also described. Furthermore, the
problem of computing a 2-layer RAC drawing with the minimum number of edge
crossings is solved in O(n2 log n) time. Finally, we prove the N P-completeness of
the maximum 2-layer subgraph problem.
We conclude the paper by listing some open problems that we consider worth to
investigate.
1. Design heuristic methods or approximation algorithms for the Maximum 2-layer
RAC Drawable Subgraph problem. Preliminary studies in this direction can be
found in [8].
2. Study the problem of computing 2-layer drawings where the number of crossings
that form π2 angles is maximized.
3. Study the problem of computing 2-layer drawings of a bipartite graph where the
minimum crossing angle is at least a given α such that 0 ≤ α < π2 .
Acknowledgements We are very grateful to the anonymous reviewers of this work. Their valuable
comments helped us to significantly improve the quality of the paper.
References
1. Ackerman, E., Fulek, R., Tóth, C.: On the size of graphs that admit polyline drawings with few bends
and crossing angles. In: Brandes, U., Cornelsen, S. (eds.) Graph Drawing. Lecture Notes in Computer
Science, vol. 6502, pp. 1–12. Springer, Berlin/Heidelberg (2011)
2. Ahuja, R.K., Magnanti, T.L., Orlin, J.B.: Network Flows: Theory, Algorithms, and Applications. Prentice Hall, New York (1993)
3. Angelini, P., Cittadini, L., Di Battista, G., Didimo, W., Frati, F., Kaufmann, M., Symvonis, A.: On the
perspective opened by right angle crossing drawings. J. Graph Algorithms Appl. 15(1), 53–78 (2011).
Special issue on GD’09
4. Argyriou, E., Bekos, M., Symvonis, A.: The straight-line RAC drawing problem is NP-hard. In: Cerná,
I., Gyimóthy, T., Hromkovic, J., Jefferey, K., Královic, R., Vukolic, M., Wolf, S. (eds.) SOFSEM 2011:
Theory and Practice of Computer Science. Lecture Notes in Computer Science, vol. 6543, pp. 74–85.
Springer, Berlin/Heidelberg (2011)
5. Arikushi, K., Fulek, R., Keszegh, B., Moric, F., Tóth, C.D.: Graphs that admit right angle crossing
drawings. Comput. Geom. 45(4), 169–177 (2012)
6. Booth, K., Lueker, G.: Testing for the consecutive ones property, interval graphs and graph planarity
using PQ-trees. J. Comput. Syst. Sci. 13, 335–379 (1976)
7. Di Giacomo, E., Didimo, W., Eades, P., Liotta, G.: 2-layer right angle crossing drawings. In: Iliopoulos, C., Smyth, W. (eds.) Combinatorial Algorithms. Lecture Notes in Computer Science, vol. 7056,
pp. 156–169. Springer, Berlin/Heidelberg (2011)
Algorithmica
8. Di Giacomo, E., Didimo, W., Grilli, L., Liotta, G., Romeo, S.: Heuristics for the maximum 2-layer
RAC subgraph problem. In: Rahman, M., Nakano, S.-I. (eds.) WALCOM: Algorithms and Computation. Lecture Notes in Computer Science, vol. 7157, pp. 211–216. Springer, Berlin/Heidelberg (2012)
9. Di Giacomo, E., Didimo, W., Liotta, G., Meijer, H.: Area, curve complexity, and crossing resolution
of non-planar graph drawings. Theory Comput. Syst. 49(3), 565–575 (2011)
10. Didimo, W., Eades, P., Liotta, G.: Drawing graphs with right angle crossings. In: Dehne, F., Gavrilova,
M., Sack, J.-R., Tóth, C.D. (eds.) Algorithms and Data Structures. Lecture Notes in Computer Science, vol. 5664, pp. 206–217. Springer, Berlin/Heidelberg (2009)
11. Didimo, W., Eades, P., Liotta, G.: A characterization of complete bipartite RAC graphs. Inf. Process.
Lett. 110(16), 687–691 (2010)
12. Didimo, W., Eades, P., Liotta, G.: Drawing graphs with right angle crossings. Theor. Comput. Sci.
412(39), 5156–5166 (2011)
13. Didimo, W., Liotta, G.: The crossing angle resolution in graph drawing. In: Thirty Essays on Geometric Graph Theory. Springer, Berlin (2012)
14. Dujmović, V., Fellows, M.R., Hallett, M.T., Kitching, M., Liotta, G., McCartin, C., Nishimura, N.,
Ragde, P., Rosamond, F.A., Suderman, M., Whitesides, S., Wood, D.R.: A fixed-parameter approach
to 2-layer planarization. Algorithmica 45(2), 159–182 (2006)
15. Dujmovic, V., Gudmundsson, J., Morin, P., Wolle, T.: Notes on large angle crossing graphs. Chic. J.
Theor. Comput. Sci. 2011, 1–14 (2011)
16. Dujmović, V., Whitesides, S.: An efficient fixed parameter tractable algorithm for 1-sided crossing
minimization. Algorithmica 40(1), 15–31 (2004)
17. Eades, P., Kelly, D.: Heuristics for drawing 2-layered networks. Ars Comb. 21, 89–98 (1986)
18. Eades, P., Liotta, G.: Right angle crossing graphs and 1-planarity. In: van Kreveld, M., Speckmann,
B. (eds.) Graph Drawing. Lecture Notes in Computer Science, vol. 7034, pp. 148–153. Springer,
Berlin/Heidelberg (2012)
19. Eades, P., McKay, B., Wormald, N.: On an edge crossing problem. In: Proc. of 9th Australian Computer Science Conference, pp. 327–334 (1986)
20. Eades, P., Whitesides, S.: Drawing graphs in two layers. Theor. Comput. Sci. 131(2), 361–374 (1994)
21. Eades, P., Wormald, N.C.: Edge crossings in drawings of bipartite graphs. Algorithmica 11(4), 379–
403 (1994)
22. Harary, F., Schwenk, A.: A new crossing number for bipartite graphs. Util. Math. 1, 203–209 (1972)
23. Huang, W.: Using eye tracking to investigate graph layout effects. In: 6th International Asia-Pacific
Symposium on Visualization. APVIS ’07, pp. 97–100 (2007)
24. Huang, W., Hong, S.-H., Eades, P.: Effects of crossing angles. In: IEEE Pacific Visualization Symposium, 2008. PacificVIS ’08, pp. 41–46 (2008)
25. Jünger, M., Mutzel, P.: 2-layer straightline crossing minimization: Performance of exact and heuristic
algorithms. J. Graph Algorithms Appl. 1 (1997)
26. Mutzel, P.: An alternative method to crossing minimization on hierarchical graphs. SIAM J. Optim.
11(4), 1065–1080 (2001)
27. Sugiyama, K.: Graph Drawing and Applications for Software and Knowledge Engineers. World Scientific, Singapore (2002)
28. Tomii, N., Kambayashi, Y., Yajima, S.: On planarization algorithms of 2-level graphs. Inst. Elect.
Common. Eng. Jpn. (1977). Technical Report EC77-38
29. Valls, V., Martí, R., Lino, P.: A branch and bound algorithm for minimizing the number of crossing
arcs in bipartite graphs. Eur. J. Oper. Res. 90(2), 303–319 (1996)
30. van Kreveld, M.: The quality ratio of RAC drawings and planar drawings of planar graphs. In: Brandes, U., Cornelsen, S. (eds.) Graph Drawing. Lecture Notes in Computer Science, vol. 6502, pp.
371–376. Springer, Berlin/Heidelberg (2011)
31. Waterman, M.S., Griggs, J.R.: Methods for visual understanding of hierarchical system structures.
IEEE Trans. Syst. Man Cybern. 2, 109–125 (1981)