1 Introduction

A pioneering paper by Storer [22] asks whether a crossing-free orthogonal drawing with the minimum number of bends can be computed in polynomial time. The question posed by Storer is in the fixed embedding setting, i.e., the input is a plane 4-graph (an embedded planar graph with vertex degree at most four) and the wanted output is an embedding-preserving orthogonal drawing with the minimum number of bends. Tamassia [23] answers Storer’s question in the affirmative by describing an \(O(n^2 \log n)\)-time algorithm. The key idea of Tamassia’s result is the equivalence between the bend minimization problem and the problem of computing a min-cost flow on a suitable network. To date, the most efficient known solution of the bend-minimization problem for orthogonal drawings in the fixed embedding setting is due to Cornelsen and Karrenbauer [6], who show a novel technique to compute a min-cost flow on an uncapacitated network and apply this technique to Tamassia’s model achieving \(O(n^{\frac{3}{2}})\)-time complexity.

Fig. 1.
figure 1

(a) A planar embedded 3-graph G. (b) An embedding-preserving bend-minimum orthogonal drawing of G. (c) A bend-minimum orthogonal drawing of G.

A different level of complexity for the bend minimization problem is encountered in the variable embedding setting, that is when the algorithm is asked to find a bend-minimum solution over all planar embeddings of the graph. For example, the orthogonal drawing of Fig. 1(c) has a different planar embedding than the graph of Fig. 1(a) and it has no bends, while the drawing of Fig. 1(b) preserves the embedding but it is suboptimal in terms of bends.

Garg and Tamassia [13] prove that the bend-minimization problem for orthogonal drawings is NP-complete for planar 4-graphs, while Di Battista et al. [8] show that it can be solved in \(O(n^5 \log n)\) time for planar 3-graphs. Generalizations of the problem in the variable embedding setting where edges have some flexibility (i.e., they can bend a few times without cost for the optimization function) have also been the subject of recent studies by Bläsius et al. [2].

Improving the \(O(n^5 \log n)\) time complexity of the algorithm by Di Battista et al. [8] has been an elusive open problem for more than a decade (see, e.g., [3]), until a paper by Chang and Yen [4] has shown how to compute a bend-minimum orthogonal drawing of a planar 3-graph in the variable embedding setting in \(\tilde{O}(n^\frac{17}{7})\) time, which can be read as \(O(n^\frac{17}{7}\log ^k n)\) time for a positive constant k.

Similar to [8], the approach in [4] uses an SPQR-tree to explore all planar embeddings of a planar 3-graph and combines partial solutions associated with the nodes of this tree to compute a bend-minimum drawing. Both in [8] and in [4], the computationally most expensive task is computing min-cost flows on suitable variants of Tamassia’s network. However, Chang and Yen elegantly prove that a simplified flow network where all edges have unit capacity can be adopted to execute this task. This, combined with a recent result [5] about min-cost flows on unit-capacity networks, yields the improved time complexity.

Contribution and Outline. This paper provides new algorithms to compute bend-minimum orthogonal drawings of planar 3-graphs, which improve the time complexity of the state-of-the-art solution. We prove the following.

Theorem 1

Let G be an n-vertex planar 3-graph. A bend-minimum orthogonal drawing of G can be computed in \(O(n^2)\) time. If either a distinguished edge or a distinguished vertex of G is constrained to be on the external face, a bend-minimum orthogonal drawing of G that respects the given constraint can be computed in O(n) time. Furthermore, the computed drawings have at most two bends per edge, which is worst-case optimal.

As in [8] and in [4], the algorithmic approach of Theorem 1 computes a bend-minimum orthogonal drawing by visiting an SPQR-tree of the input graph. However, it does not need to compute min-cost flows at any steps of the visit, which is the fundamental difference with the previous techniques. This makes it possible to design the first quadratic-time algorithm to compute bend-minimum orthogonal drawings of planar 3-graphs in the variable embedding setting.

The second part of the statement of Theorem 1 extends previous studies by Nishizeki and Zhou [26], who give a first example of a linear-time algorithm in the variable embedding setting for planar 3-graphs that are partial two-trees. The bend-minimum drawings of Theorem 1 have at most two bends per edge, which is a desirable property for an orthogonal representation. We recall that every planar 4-graph (except the octahedron) has an orthogonal drawing with at most two bends per edge [1, 17], but minimizing the number of bends may require some edges with a \(\varOmega (n)\) bends [8, 24]. It is also proven that every planar 3-graph (except \(K_4\)) has an orthogonal drawing with at most one bend per edge [16], but the drawings of the algorithm in [16] are not bend-minimum. Finally, a non-flow based algorithm having some similarities with ours is given in [12]; it neither computes bend-minimum drawings nor guarantees at most two bends per edge.

The paper is organized as follows. Preliminary definitions and results are in Sect. 2. In Sect. 3 we prove key properties of bend-minimum orthogonal drawings of planar 3-graphs used in our approach. Sect. 4 describes our drawing algorithms. Open problems are in Sect. 5. All full proofs and more figures can be found in [11].

2 Preliminaries

We assume familiarity with basic definitions on graph connectivity and planarity (see Appendix A of [11]). If G is a graph, V(G) and E(G) denote the sets of vertices and edges of G. We consider simple graphs, i.e., graphs with neither self-loops nor multiple edges. The degree of a vertex \(v \in V(G)\), denoted as \(\deg (v)\), is the number of its neighbors. \(\varDelta (G)\) denotes the maximum degree of a vertex of G; if \(\varDelta (G) \le h\) (\(h \ge 1\)), G is an h-graph. A graph G is rectilinear planar if it admits a planar drawing where each edge is either a horizontal or a vertical segment (i.e., it has no bend). Rectilinear planarity testing is NP-complete for planar 4-graphs [13], but it is polynomially solvable for planar 3-graphs [4, 8] and linear-time solvable for subdivisions of planar triconnected cubic graphs [18]. By extending a result of Thomassen [25] on those 3-graphs that have a rectilinear drawing with all rectangular faces, Rahman et al. [21] characterize rectilinear plane 3-graphs. For a plane graph G, let \(C_o(G)\) be its external cycle (\(C_o(G)\) is simple if G is biconnected). Also, if C is a simple cycle of G, G(C) is the plane subgraph of G that consists of C and of the vertices and edges inside C. An edge \(e=(u,v) \notin E(G(C))\) is a leg of C if exactly one of the vertices u and v belongs to C; such a vertex is a leg-vertex of C. If C has exactly k legs and no edge embedded outside C joins two of its vertices, C is a k-legged cycle of G.

Theorem 2

[21] Let G be a biconnected plane 3-graph. G admits an orthogonal drawing without bends if and only if: (i) \(C_o(G)\) contains at least four vertices of degree 2; (ii) each 2-legged cycle contains at least two vertices of degree 2; (iii) each 3-legged cycle contains at least one vertex of degree 2.

As in [21], we call bad any 2-legged and any 3-legged cycle that does not satisfy Condition (ii) and (iii) of Theorem 2, respectively.

Fig. 2.
figure 2

(a) A plane 3-graph G. (b) The SPQR-tree of G with respect to e; the skeletons of a P-node \(\nu \) and of an R-node \(\mu \) are shown. (c) A different embedding of G obtained by changing the embedding of \(\mathrm {skel} (\nu )\) and of \(\mathrm {skel} (\mu )\).

SPQR-Trees of Planar 3-Graphs. Let G be a biconnected graph. An SPQR-tree T of G represents the decomposition of G into its triconnected components and can be computed in linear time [7, 14, 15]. Each triconnected component corresponds to a node \(\mu \) of T; the triconnected component itself is called the skeleton of \(\mu \) and denoted as \(\mathrm {skel} (\mu )\). A node \(\mu \) of T can be of one of the following types: (i) R-node, if \(\mathrm {skel} (\mu )\) is a triconnected graph; (ii) S-node, if \(\mathrm {skel} (\mu )\) is a simple cycle of length at least three; (iii) P-node, if \(\mathrm {skel} (\mu )\) is a bundle of at least three parallel edges; (iv) Q-nodes, if it is a leaf of T; in this case the node represents a single edge of the graph and its skeleton consists of two parallel edges. Note that, neither two S- nor two P-nodes are adjacent in T. A virtual edge in \(\mathrm {skel} (\mu )\) corresponds to a tree node \(\nu \) adjacent to \(\mu \) in T. If T is rooted at one of its Q-nodes \(\rho \), every skeleton (except the one of \(\rho \)) contains exactly one virtual edge that has a counterpart in the skeleton of its parent: This virtual edge is the reference edge of \(\mathrm {skel} (\mu )\) and of \(\mu \), and its endpoints are the poles of \(\mathrm {skel} (\mu )\) and of \(\mu \). The edge of G corresponding to the root \(\rho \) of T is the reference edge of G, and T is the SPQR-tree of G with respect to e. For every node \(\mu \ne \rho \) of T, the subtree \(T_\mu \) rooted at \(\mu \) induces a subgraph \(G_\mu \) of G called the pertinent graph of \(\mu \), which is described by \(T_\mu \) in the decomposition: The edges of \(G_\mu \) correspond to the Q-nodes (leaves) of \(T_\mu \). Graph \(G_\mu \) is also called a component of G with respect to the reference edge e, namely \(G_\mu \) is a P-, an R-, or an S-component depending on whether \(\mu \) is a P-, an R-, or an S-component, respectively.

The SPQR-tree T rooted at a Q-node \(\rho \) implicitly describes all planar embeddings of G with the reference edge of G on the external face. All such embeddings are obtained by combining the different planar embeddings of the skeletons of P- and R-nodes: For a P-node \(\mu \), the different embeddings of \(\mathrm {skel} (\mu )\) are the different permutations of its non-reference edges. If \(\mu \) is an R-node, \(\mathrm {skel} (\mu )\) has two possible planar embeddings, obtained by flipping \(\mathrm {skel} (\mu )\) minus its reference edge at its poles. See Fig. 2 for an illustration. The child node of \(\rho \) and its pertinent graph are called the root child of T and the root child component of G, respectively. An inner node of T is neither the root nor the root child of T. The pertinent graph of an inner node is an inner component of G. The next lemma gives basic properties of T when \(\varDelta (G) \le 3\).

Lemma 1

Let G be a biconnected planar 3-graph and let T be the SPQR-tree of G with respect to a reference edge e. The following properties hold:

Each P-node \(\mu \) has exactly two children, one being an S-node and the other being an S- or a Q-node; if \(\mu \) is the root child, both its children are S-nodes.

Each child of an R-node is either an S-node or a Q-node.

For each inner S-node \(\mu \), the edges of \(\mathrm {skel} (\mu )\) incident to the poles of \(\mu \) are (real) edges of G. Also, there cannot be two incident virtual edges in \(\mathrm {skel} (\mu )\).

3 Properties of Bend-Minimum Orthogonal Representations of Planar 3-Graphs

We prove relevant properties of bend-minimum orthogonal drawings of planar 3-graphs that are independent of vertex and bend coordinates, but only depend on the vertex angles and edge bends. To this aim, we recall the concept of orthogonal representation [23] and define some types of “shapes” that we use to construct bend-minimum orthogonal representations.

Orthogonal Representations. Let G be a plane 3-graph. If \(v \in V(G)\) and if \(e_1\) and \(e_2\) are two (possibly coincident) edges incident to v that are consecutive in the clockwise order around v, we say that \(a = \langle e_1,v,e_2 \rangle \) is an angle at v of G or simply an angle of G. Let \(\varGamma \) and \(\varGamma '\) be two embedding-preserving orthogonal drawings of G. We say that \(\varGamma \) and \(\varGamma '\) are equivalent if: (i) For any angle a of G, the geometric angle corresponding to a is the same in \(\varGamma \) and \(\varGamma '\), and (ii) for any edge \(e=(u,v)\) of G, the sequence of left and right bends along e moving from u to v is the same in \(\varGamma \) and in \(\varGamma '\). An orthogonal representation H of G is a class of equivalent orthogonal drawings of G; H can be described by the embedding of G together with the geometric value of each angle of G (90, 180, \(270^\circ \))Footnote 1 and with the sequence of left and right bends along each edge. Figure 3(a) shows a bend-minimum orthogonal representation of the graph in Fig. 2(a).

Fig. 3.
figure 3

(a) A bend-minimum orthogonal representation H with four bends of the graph in Fig. 2(a). (b) The component \(H_\nu \), which is L-shaped; the two poles of the component are the white vertices. (c) The component \(H_\mu \), which is D-shaped.eps

Let p be a path between two vertices u and v in H. The turn number of p is the absolute value of the difference between the number of right and the number of left turns encountered along p moving from u to v (or vice versa). The turn number of p is denoted by t(p). A turn along p is caused either by a bend on an edge of p or by an angle of 90 / 270 degrees at a vertex of p. For example, \(t(p)=2\) for the path \(p = \langle 3, 4, 5, 6, 7 \rangle \) in the orthogonal representation of Fig. 3(a). We remark that if H is a bend-minimum orthogonal representation, the bends along an edge, going from an end-vertex to the other, are all left or all right turns [23].

Shapes of Orthogonal Representations. Let G be a biconnected planar 3-graph, T be the SPQR-tree of G with respect to a reference edge \(e \in E(G)\), and H be an orthogonal representation of G with e on the external face. For a node \(\mu \) of T, denote by \(H_\mu \) the restriction of H to a component \(G_\mu \). We also call \(H_\mu \) a component of H. In particular, \(H_\mu \) is a P-, an R-, or an S-component depending on whether \(\mu \) is a P-, an R-, or an S-component, respectively. If \(\mu \) is the root child of T, then \(H_\mu \) is the root child component of H. Denote by u and v the two poles of \(\mu \) and let \(p_l\) and \(p_r\) be the two paths from u to v on the external boundary of \(H_\mu \), one walking clockwise and the other walking counterclockwise. These paths are the contour paths of \(H_\mu \). If \(\mu \) is an S-node, \(p_l\) and \(p_r\) share some edges (they coincide if \(H_\mu \) is just a sequence of edges). If \(\mu \) is either a P- or an R-node, \(p_l\) and \(p_r\) are edge disjoint; in this case, we define the following shapes for \(H_\mu \), depending on \(t(p_l)\) and \(t(p_r)\) and where the poles are external corners:

\(H_\mu \) is C-shaped, or -shaped, if \(t(p_l)=4\) and \(t(p_r)=2\), or vice versa;

\(H_\mu \) is D-shaped, or -shaped, if \(t(p_l)=0\) and \(t(p_r)=2\), or vice versa;

\(H_\mu \) is L-shaped, or -shaped, if \(t(p_l)=3\) and \(t(p_r)=1\), or vice versa;

\(H_\mu \) is X-shaped, or -shaped, if \(t(p_l)=t(p_r)=1\).

For example, \(H_\nu \) in Fig. 3(b) is -shaped, while \(H_\mu \) in Fig. 3(c) is -shaped. Concerning S-components, the following lemma rephrases a result in [8, Lemma 4.1], and it is also an easy consequence of Property T3 in Lemma 1.

Lemma 2

Let \(H_\mu \) be an inner S-component with poles u and v and let \(p_1\) and \(p_2\) be any two paths connecting u and v in \(H_\mu \). Then \(t(p_1)=t(p_2)\).

Based on Lemma 2, we describe the shape of an inner S-component \(H_\mu \) in terms of the turn number of any path p between its two poles: We say that \(H_\mu \) is k-spiral and has spirality k if \(t(p)=k\). The notion of spirality of an orthogonal component was introduced in [8]. Differently from [8], we restrict the definition of spirality to inner S-components and we always consider absolute values, instead of both positive and negative values depending on whether the left turns are more or fewer than the right turns. For instance, in the representation of Fig. 3(a) the two series with poles \(\{1,14\}\) (the two filled S-nodes in Fig. 2(b)) have spirality three and one, respectively; the series with poles \(\{4,8\}\) (child of the R-node) has spirality zero, while the series with poles \(\{5,7\}\) has spirality two.

We now give a key result that claims the existence of a bend-minimum orthogonal representation with specific properties for any biconnected planar 3-graph. This result will be used to design our drawing algorithm. Given an orthogonal representation H, we denote by \(\overline{H}\) the orthogonal representation obtained from H by replacing each bend with a dummy vertex: \(\overline{H}\) is the rectilinear image of H; a dummy vertex in \(\overline{H}\) is a bend vertex. Also, if w is a degree-2 vertex with neighbors u and v, smoothing w is the reverse operation of an edge subdivision, i.e., it replaces the two edges (uw) and (wv) with the single edge (uv).

Lemma 3

A biconnected planar 3-graph G with a distinguished edge e has a bend-minimum orthogonal representation H with e on the external face such that:

Every edge of H has at most two bends, which is worst-case optimal.

Every inner P-component or R-component of H is either - or -shaped.

Every inner S-component of H has spirality at most four.

Proof

(sketch). We prove in three steps the existence of a bend-minimum orthogonal representation H that satisfies O1-O3. We start by a bend-minimum orthogonal representation of G with e on the external face, and in the first step we prove that it either satisfies O1 or it can be locally modified, without changing its planar embedding, so to satisfy O1. In the second step, we prove that from the orthogonal representation obtained in the first step we can derive a new orthogonal representation (still with same embedding) that satisfies O2 in addition to O1. Finally, we prove that this last representation also satisfies O3.

.Suppose that H is a bend-minimum orthogonal representation of G with e on the external face and having an edge g (possibly \(g = e\)) with at least three bends. Let \(\overline{H}\) be the rectilinear image of H, and let \(\overline{G}\) be the plane graph underlying \(\overline{H}\). Since \(\overline{H}\) has no bend, \(\overline{G}\) satisfies Conditions \((i)-(iii)\) of Theorem 2. Let \(v_1\), \(v_2\), \(v_3\) be three bend vertices in \(\overline{H}\) that correspond to three bends of g in H. Assume first that g is an internal edge of G and let \(\overline{G'}\) be the plane graph obtained from \(\overline{G}\) by smoothing \(v_1\). We claim that \(\overline{G'}\) still satisfies Conditions \((i)-(iii)\) of Theorem 2. Indeed, if this is not the case, there must be a bad cycle in \(\overline{G'}\) that contains both \(v_2\) and \(v_3\). This is a contradiction, because no bad cycle can contain two vertices of degree two. Hence, there exists an (embedding-preserving) representation \(\overline{H'}\) of \(\overline{G'}\) without bends, which is the rectilinear image of an orthogonal representation of G with fewer bends than H, a contradiction. Assume now that g is on the external cycle \(C_o(G)\) of G. If \(C_o(\overline{G})\) contains more than four vertices of degree two, we can smooth \(v_1\) and apply the same argument as above to contradict the optimality of H (note that, such a smoothing does not violate Condition (i) of Theorem 2). Suppose vice versa that \(C_o(\overline{G})\) contains exactly four vertices of degree two (three of them being \(v_1\), \(v_2\), and \(v_3\)). In this case, just smoothing \(v_1\) violates Condition (i) of Theorem 2. However, we can smooth \(v_1\) and subdivide an edge of \(C_o(\overline{G}) \cap C_o(G)\) (such an edge exists since \(C_o(G)\) has at least three edges and, by hypothesis and a simple counting argument, at least one of its edges has no bend in H). The resulting plane graph \(\overline{G''}\) still satisfies the three conditions of Theorem 2 and admits a representation \(\overline{H''}\) without bends; the representation of which \(\overline{H''}\) is the rectilinear image is a bend-minimum orthogonal representation of G with at most two bends per edge. To see that two bends per edge is worst-case optimal, just consider a bend-minimum representation of the complete graph \(K_4\).

. Let H be a bend-minimum orthogonal representation of G that satisfies \(\textsf {O1}\) and let \(\overline{H}\) be its rectilinear image. The plane underlying graph \(\overline{G}\) of \(\overline{H}\) satisfies the three conditions of Theorem 2. Rhaman, Nishizeki, and Naznin [21, Lemma 3] prove that, in this case, \(\overline{G}\) has an embedding-preserving orthogonal representation \(\overline{H'}\) without bends in which every 2-legged cycle C is either -shaped or -shaped, where the two poles of the shape are the two leg-vertices of C. On the other hand, if \(G_\mu \) is an inner P- or R-component, the external cycle \(C_o(G_\mu )\) is a 2-legged cycle of G, where the two leg-vertices of \(C_o(G_\mu )\) are the poles of \(G_\mu \). Hence, the representation \(H'\) of G whose rectilinear image is \(\overline{H'}\) satisfies O2, as \(H'_\mu \) is either -shaped or -shaped. Also, the bends of \(H'\) are the same as in H, because the bend vertices of \(\overline{H}\) coincide with those of \(\overline{H'}\). Hence, \(H'\) still satisfies O1 and has the minimum number of bends.

. Suppose now that H is a bend-minimum orthogonal representation of G (with e on the external face) that satisfies both O1 and O2. More precisely, assume that \(H = H'\) is the orthogonal representation obtained in the previous step, where its rectilinear image \(\overline{H}\) is computed by the algorithm of Rhaman et al. [21]. By a careful analysis of how this algorithm works, we prove that each series gets spirality at most four in H (see Appendix B of [11]).

4 Drawing Algorithm

Let G be a biconnected 3-planar graph with a distinguished edge e and let T be the SPQR-tree of G with respect to e. Section 4.1 gives a linear-time algorithm to compute bend-minimum orthogonal representations of the inner components of T. Section 4.2 handles the root child of T to complete a bend-minimum representation with e on the external face and it proves Theorem 1. Lemma 3 allows us to restrict our algorithm to search for a representation satisfying Properties O1-O3.

4.1 Computing Orthogonal Representations for Inner Components

Let T be the SPQR-tree of G with respect to reference edge e and let \(\mu \) be an inner node of T. A key ingredient of our algorithm is the concept of ‘equivalent’ orthogonal representations of \(G_\mu \). Intuitively, two representations of \(G_\mu \) are equivalent if one can replace the other in any orthogonal representation of G. Similar equivalence concepts have been used for orthogonal drawings [8, 10]. As we shall prove (see Theorem 3), for planar 3-graphs a simpler definition of equivalent representations suffices. If \(\mu \) is a P- or an R-node, two representations \(H_\mu \) and \(H'_\mu \) are equivalent if they are both -shaped or both -shaped. If \(\mu \) is an inner S-node, \(H_\mu \) and \(H'_\mu \) are equivalent if they have the same spirality.

Lemma 4

If \(H_\mu \) and \(H'_\mu \) are two equivalent orthogonal representations of \(G_\mu \), the two contour paths of \(H_\mu \) have the same turn number as those of \(H'_\mu \).

Suppose that \(H_\mu \) is an inner component of H with poles u and v, and let \(p_l\) and \(p_r\) be the contour paths of \(H_\mu \). Replacing \(H_\mu \) in H with an equivalent representation \(H'_\mu \) means to insert \(H'_\mu \) in H in place of \(H_\mu \), in such a way that: (i) if \(H_\mu \) and \(H'_\mu \) are -shaped, the contour path \(p'\) of \(H'_\mu \) for which \(t(p')=t(p_l)\) is traversed clockwise from u to v on the external boundary of \(H'_\mu \) (as for \(p_l\) on the external boundary of \(H_\mu \)); (ii) in all cases, the external angles of \(H'_\mu \) at u and v are the same as in \(H_\mu \). This operation may require to mirror \(H'_\mu \) (see Fig. 4). The next theorem uses arguments similar to [8].

Fig. 4.
figure 4

(a) An orthogonal representation H; a D-shaped R-component with poles \(\{w,z\}\) and an equivalent representation of it are in the blue frames. (b) A representation obtained from H by replacing the R-component with the equivalent one; a 1-spiral S-component with poles \(\{u,v\}\) and an equivalent one are shown in the red frames. (c) The representation obtained by replacing the S-component with the equivalent one.

Theorem 3

Let H be an orthogonal representation of a planar 3-graph G and \(H_\mu \) be the restriction of H to \(G_\mu \), where \(\mu \) is an inner component of the SPQR-tree T of G with respect to a reference edge e. Replacing \(H_\mu \) in H with an equivalent representation \(H'_\mu \) yields a planar orthogonal representation \(H'\) of G.

We are now ready to describe our drawing algorithm. It is based on a dynamic programming technique that visits bottom-up the SPQR-tree T with respect to the reference edge e of G. Based on Lemma 3 and Theorem 3, the algorithm stores for each visited node \(\mu \) of T a set of candidate orthogonal representations of \(G_{\mu }\), together with their cost in terms of bends. For a Q-node, the set of candidate orthogonal representations consists of three representations, with 0, 1, and 2 bends, respectively. This suffices by Property O1. For a P- or an R-node, the set of candidate representations consists of a bend-minimum -shaped and a bend-minimum -shaped representation. This suffices by Property O2. For an S-node, the set of candidate representations consists of a bend-minimum representation for each value of spirality \(0 \le k \le 4\). This suffices by Property O3. In the following we explain how to compute the set of candidate representations for a node \(\mu \) that is a P-, an S-, or an R-node (computing the set of a Q-node is trivial). To achieve overall linear-time complexity, the candidate representations stored at \(\mu \) are described incrementally, linking the desired representation in the set of the children of \(\mu \) for each virtual edge of \(\mathrm {skel} (\mu )\).

Candidate Representations for a P-node. By property T1 of Lemma 1, \(\mu \) has two children \(\mu _1\) and \(\mu _2\), where \(\mu _1\) is an S-node and \(\mu _2\) is an S-node or a Q-node. The cost of the -shaped representation of \(\mu \) is the sum of the costs of \(\mu _1\) and \(\mu _2\) both with spirality one. The cost of the -shaped representation of \(\mu \) is the minimum between the cost of \(\mu _1\) with spirality two and the cost of \(\mu _2\) with spirality two. This immediately implies the following.

Lemma 5

Let \(\mu \) be an inner P-node. There exists an O(1)-time algorithm that computes a set of candidate orthogonal representations of \(G_\mu \), each having at most two bends per edge.

Candidate Representations for an S-node. By property T3 of Lemma 1, \(\mathrm {skel} (\mu )\) without its reference edge is a sequence of edges such that the first edge and the last edge are real (they correspond to Q-nodes) and at most one virtual edge, corresponding to either a P- or an R-node, appears between two real edges. Let \(c_0\) be the sum of the costs of the cheapest (in terms of bends) orthogonal representations of all P-nodes and R-nodes corresponding to the virtual edges of \(\mathrm {skel} (\mu )\). By Property O2, each of these representations is either - or -shaped. Let \(n_Q\) be the number of edges of \(\mathrm {skel} (\mu )\) that correspond to Q-nodes and let \(n_D\) be the number of edges of \(\mathrm {skel} (\mu )\) that correspond to P- and R-nodes whose cheapest representation is -shaped. Obviously, any bend-minimum orthogonal representation of \(G_\mu \) satisfying O2 has cost at least \(c_0\). We have the following.

Lemma 6

An inner S-component admits a bend-minimum orthogonal representation respecting Properties O1-O3 and with cost \(c_0\) if its spirality \(k \le n_Q+n_D-1\) and with cost \(c_0 + k - n_Q-n_D+1\) if \(k > n_Q+n_D-1\).

Note that the possible presence in \(\mathrm {skel} (\mu )\) of virtual edges corresponding to P- and R-nodes whose cheapest representation is -shaped does not increase the spirality reachable at cost \(c_0\) by the S-node. Lemma 6 also provides an alternative proof of a known result ([8, Lemma 5.2]), stating that for a planar 3-graph the number of bends of a bend-minimum k-spiral representation of an inner S-component does not decrease when k increases. Moreover, since for an inner S-component \(n_Q \ge 2\), a consequence of Lemma 6 is Corollary 1. It implies that every bend-minimum k-spiral representation of an inner S-component does not require additional bends with respect to the bend-minimum representations of their subcomponents when \(k \in \{0,1\}\).

Corollary 1

For each \(k \in \{0,1\}\), every inner S-component admits a bend-minimum orthogonal representation of cost \(c_0\) with spirality k.

Lemma 7

Let \(\mu \) be an inner S-node and \(n_\mu \) be the number of vertices of \(\mathrm {skel} (\mu )\). There exists an \(O(n_\mu )\)-time algorithm that computes a set of candidate orthogonal representations of \(G_\mu \), each having at most two bends per edge.

Candidate Representations for an R-node. If \(\mu \) is an R-node, its children are S- or Q-nodes (Property T2 of Lemma 1). To compute a bend-minimum orthogonal representation of \(G_\mu \) that satisfies Properties O1-O3, we devise a variant of the linear-time algorithm by Rahman, Nakano, and Nishizeki [19] that exploits the properties of inner S-components.

Lemma 8

Let \(\mu \) be an inner R-node and \(n_\mu \) be the number of vertices of \(\mathrm {skel} (\mu )\). There exists an \(O(n_\mu )\)-time algorithm that computes a set of candidate orthogonal representations of \(G_\mu \), each having at most two bends per edge.

Proof

(sketch). Let \(\{u,v\}\) be the poles of \(\mu \). Our algorithm works in two steps. First, it computes an -shaped orthogonal representation and a -shaped orthogonal representation of \(\tilde{G}_\mu = \mathrm {skel} (\mu ) \setminus (u,v)\), with a variant of the recursive algorithm in [19]. Then, it computes a bend-minimum -shaped representation and a bend-minimum -shaped representation of \(G_\mu \), by replacing each virtual edge \(e_S\) in each of and with the representation in the set of the corresponding S-node whose spirality equals the number of bends of \(e_S\). Every time the algorithm needs to insert a degree-2 vertex along an edge of a bad cycle, it adds this vertex on a virtual edge, if such an edge exists. By Corollary 1, this vertex does not cause an additional bend in the final representation when the virtual edge is replaced by the corresponding S-component.

4.2 Handling the Root Child Component

Let T be the SPQR-tree of G with respect to edge \(e=(u,v)\) and let \(\mu \) be the root child of T. Assuming to have already computed the set of candidate representations for the children of \(\mu \), we compute an orthogonal representation \(H_\mu \) of \(G_\mu \) and a bend-minimum orthogonal representation H of G (with e on the external face) depending on the type of \(\mu \).

Let \(\mu \) be a P-node with children \(\mu _1\) and \(\mu _2\). By Property T1 of Lemma 1, both \(\mu _1\) and \(\mu _2\) are S-nodes. Let \(k_1\) (\(k_2\)) be the maximum spirality of a representation \(H_{\mu _1}\) (\(H_{\mu _2}\)) at the same cost \(c_{0,1}\) (\(c_{0,2}\)) as a 0-spiral representation. W.l.o.g., let \(k_1 \ge k_2\). We have three cases:

Case 1: \(k_1 \ge 4\). Compute a -shaped \(H_\mu \) by merging a 4-spiral and a 2-spiral representation of \(\mu _1\) and \(\mu _2\), respectively; add e with 0 bends to get H.

Case 2: \(k_1 = 3\). Compute an -shaped \(H_\mu \) by merging a 3-spiral and a 1-spiral representation of \(\mu _1\) and \(\mu _2\), respectively; add e with 1 bend to get H.

Case 3: \(k_1 = 2\) or \(k_2 = k_1 = 1\). Compute a -shaped \(H_\mu \) by merging a 2-spiral and a 0-spiral representation of \(\mu _1\) and \(\mu _2\), respectively; add e with 2 bends to get H.

Lemma 9

P-root-child computes a bend-minimum orthogonal representation of G with e on the external face and at most two bends per edge in O(1) time.

Let \(\mu \) be an S-node. if \(G_\mu \) starts and ends with one edge, we compute the candidate orthogonal representations of \(G_\mu \) as if it were an inner S-node, and we obtain H by adding e with zero bends to the 2-spiral representation of \(G_\mu \). Else, if \(G_\mu \) only starts or ends with one edge, we add e to the other end of \(G_\mu \), compute the candidate representations of \(G_\mu \cup \{e\}\) as if it were an inner S-node, and obtain G by adopting the representation of \(G_\mu \cup \{e\}\) with spirality 3 and by identifying the first and last vertex. Finally, if \(\mathrm {skel} (\mu ) \setminus \{e\}\) starts and ends with an R- or a P-node, we add two copies \(e'\), \(e''\) of e at the beginning and at the end of \(G_\mu \), compute the candidate representations of \(G_\mu \cup \{e',e''\}\) as if it were an inner S-node, and obtain H from the representation of \(G_\mu \cup \{e',e''\}\) with spirality 4, by identifying the first and last vertex of \(G_\mu \cup \{e',e''\}\) and by smoothing the resulting vertex.

Lemma 10

S-root-child computes a bend-minimum orthogonal representation of G with e on the external face and at most two bends per edge in \(O(n_\mu )\) time, where \(n_\mu \) is the number of vertices of \(\mathrm {skel} (\mu )\).

Let \(\mu \) be an R-node and let \(\phi _1\) and \(\phi _2\) be the two planar embeddings of \(\mathrm {skel} (\mu )\) obtained by choosing as external face one of those incident to e. For each \(\phi _i\), compute an orthogonal representation \(H_i\) of G by: (i) finding a representation \(\tilde{H}_i\) of \(\mathrm {skel} (\mu )\) (included e) with the variant of [19] given in the proof of Lemma 8, but this time assuming that all the four designated corners of the external face in the initial step must be found; (ii) replacing each virtual edge that bends \(k \ge 0\) times in \(\tilde{H}_i\) with a minimum-bend k-spiral representation of its corresponding S-component. H is the cheapest of \(H_1\) and \(H_2\). Since the variant of [19] applied to \(\mathrm {skel} (\mu )\) still causes at most two bends per edge, with the same arguments as in Lemma 8 we have:

Lemma 11

R-root-child computes a bend-minimum orthogonal representation of G with e on the external face and at most two bends per edge in \(O(n_\mu )\) time, where \(n_\mu \) be the number of vertices of \(\mathrm {skel} (\mu )\).

Proof of Theorem 1. If G is biconnected, Lemmas 578911 yield an O(n)-time algorithm that computes a bend-minimum orthogonal representation of G with a distinguished edges e on the external face and at most two bends per edge. Call BendMin-RefEdge this algorithm. An extension of BendMin-RefEdge to a simply-connected graph G, which still runs in O(n) time, is easily derivable by exploiting the block-cut-vertex tree of G (see Appendix C of [11]). Running BendMin-RefEdge for every possible reference edge, we find in \(O(n^2)\) time a bend-minimum orthogonal representation of G over all its planar embeddings. If v is a distinguished vertex of G, running BendMin-RefEdge for every edge incident to v, we find in O(n) time a bend-minimum orthogonal representation of G with v on the external face (recall that \(\deg (v) \le 3\)). Finally, an orthogonal drawing of G is computed in O(n) time from an orthogonal representation of G [7].

5 Open Problems

We suggest two research directions related to our results: (i) Is there an O(n)-time algorithm to compute a bend-minimum orthogonal drawing of a 3-connected planar cubic graph, for every possible choice of the external face? (ii) It is still unknown whether an O(n)-time algorithm for the bend-minimization problem in the fixed embedding setting exists [9]. This problem could be tackled with non-flow based approaches. A positive result in this direction is given in [20] for plane 3-graphs.