Computing Bend-Minimum Orthogonal Drawings of Plane Series–Parallel Graphs in Linear Time

A planar orthogonal drawing of a planar 4-graph G (i.e., a planar graph with vertex-degree at most four) is a crossing-free drawing that maps each vertex of G to a distinct point of the plane and each edge of G to a polygonal chain consisting of horizontal and vertical segments. A longstanding open question in Graph Drawing, dating back over 30 years, is whether there exists a linear-time algorithm to compute an orthogonal drawing of a plane 4-graph with the minimum number of bends. The term “plane” indicates that the input graph comes together with a planar embedding, which must be preserved by the drawing (i.e., the drawing must have the same set of faces as the input graph). In this paper we positively answer the question above for the widely-studied class of series–parallel graphs. Our linear-time algorithm is based on a characterization of the planar series–parallel graphs that admit an orthogonal drawing without bends. This characterization is given in terms of the orthogonal spirality that each type of triconnected component of the graph can take; the orthogonal spirality of a component measures how much that component is “rolled-up” in an orthogonal drawing of the graph.

a A series-parallel graph G with a given planar embedding. b A bend-minimum orthogonal drawing H of G with 5 bends, represented by cross vertices. c The SPQ * -tree T of G with reference edge e = (1, 11); series and parallel compositions are represented by S-and P-nodes; a Q * -node represents an edge or a series of edges; the root P r -node is a parallel composition between e and the rest of the graph. d Three suboptimal orthogonal drawings obtained by distributing the same number of bends of the highlighted subgraph G ν 3 in a different way In a nutshell, our bend-minimization algorithm executes a post-order visit of a series-parallel decomposition tree T of the input graph G, also called SPQ * -tree. Tree T represents the parallel and the series compositions that form G (see Fig. 1a, c, and refer to Sect. 2 for a formal definition of SPQ * -trees). Suppose that ν is a node of T and G ν its corresponding subgraph in G. When the algorithm visits ν, it must efficiently determine whether G ν is rectilinear planar and, if not, it must compute the minimum number of subdivision vertices needed to make it rectilinear planar; how to efficiently compute such a number is a first key ingredient of our approach.
A second key ingredient is proving that, when the algorithm processes a node ν in the bottom-up visit, the addition of the minimum number of subdivision vertices that make G ν rectilinear planar leads to the optimum in terms of total number of bends.
As a third key ingredient, the algorithm needs to concisely describe the set of rectilinear drawings of G ν that can be obtained by distributing these subdivision vertices in all possible ways along the edges of G ν , which gives rise to a combinatorial explosion of different possibilities. Indeed, different distributions of the same set of subdivision vertices along the edges of G ν can lead to orthogonal drawings of G that have different number of bends. For example, consider the highlighted subgraph G ν 3 (associated with node ν 3 of T ) in the graph of Fig. 1a. Any orthogonal drawing of G ν 3 requires at least three bends (subdivision vertices); placing all of them on edge (2,11) yields the optimal solution of Fig. 1b, which additionally requires two bends on edge (1,11). Conversely, placing the three bends on a different subset of edges of G ν 3 leads to (suboptimal) solutions with more bends; see Fig. 1d. To efficiently handle the combinatorially many distributions of the subdivision vertices along the edges of a subgraph G ν , we succinctly encode in O(1) space the "orthogonal shapes" that G ν can have in a bend-minimum planar orthogonal drawing of G. This is done by looking at the set of possible orthogonal spirality values that G ν can take in such a drawing.
The remainder of the paper is organized as follows. Section 2 recalls basic definitions used throughout the paper. Section 3 strengthens a result given in [5] about the interchangeability of orthogonal representations with the same spirality. Section 4 characterizes those plane series-parallel graphs that are rectilinear planar. Section 5 gives an overview of our bend-minimization algorithm. Section 6 provides details about the bottom-up visit performed by the algorithm. Section 7 summarizes our main result. Concluding remarks and open problems are in Sect. 8.
Some of our proofs are based on case analyses; in some proofs, we moved part of the case analysis to the paper appendix, when the analysis of a case resulted similar to the analysis of a previous case; also, the appendix reports a glossary of the main symbols used throughout the paper.

Preliminaries
We assume familiarity with basic concepts of graph planarity and graph drawing [4,[15][16][17]. We only deal with connected graphs and we focus on orthogonal representations rather than orthogonal drawings. An orthogonal representation H of a planar graph G describes a class of equivalent planar orthogonal drawings of G in terms of planar embedding, ordered sequence of bends along the edges (i.e., sequence of left/right turns going from an end-vertex to the other) and clockwise sequence of geometric angles at each vertex, each angle formed by two (possibly coincident) consecutive edges around the vertex and expressed as a value in the set {90 • , 180 • , 270 • , 360 • } (angles of 360 • occur only at degree-1 vertices). An orthogonal representation H of G can be described by a planar embedding of G plus an angle labeling specifying: (i) for each vertex v of G, the geometric angles at v; (ii) for each edge e = (u, v) of G, the ordered sequence of bends along e as a sequence of angles in the left face (and hence in the right face) of e while moving along e from u to v (each bend determines an angle of 90 • in one of the two faces incident to e and an angle of 270 • in the other face). It is well known (see, e.g., [3]) that an angle labeling of G describes a valid orthogonal representation if and only if the following properties hold: Note that, since the set of faces of a plane graph G is a base for the set of simple cycles of G, Properties (H1) and (H2) together are equivalent to say that for every simple cycle C of G, the number of right turns minus the number of left turns, when walking clockwise around the boundary of C, is equal to four. Namely, if v is a vertex of C we count: a right turn at v if there is an angle of 90 • at v inside C; a left turn at v if the sum of the angles at v inside C equals 270 • ; two left turns at v if v has degree one. Also, a bend on an edge of C corresponds to a right (resp. left) turn if it determines an angle of 90 • (resp., 270 • ) in C.
Given an orthogonal representation H of a plane graph G, a drawing of H (which corresponds to an orthogonal drawing of G) can be computed in linear time [21]. If H has no bend, H is a rectilinear representation.

Series-parallel graphs and decomposition trees.
A two-terminal series-parallel graph G, also called series-parallel graph, has two distinct vertices s and t, called the source and the sink of G, respectively. A series-parallel graph can be inductively defined by, and naturally associated with, a decomposition tree T : (i) a single edge (s, t) is a series-parallel graph with source s and sink t, in which case T consists of a single Q-node, whose poles are s and t; (ii) given p ≥ 2 series-parallel graphs G 1 , . . . , G p , each G i with source s i and sink t i (i = 1, . . . , p), a new series-parallel graph G can be obtained with any of these two operations: -Series composition, which identifies t i with s i+1 (i = 1, . . . , p − 1); G has source s = s 1 and sink t = t p . The composition is represented in T by an S-node, with poles s 1 and t p , whose children are the roots of the decomposition trees T i of G i (i = 1, . . . , p). -Parallel composition, which identifies all sources s i (resp. all sinks t i ) together (i = 1, . . . , p); G has source s = s i and sink t = t i . The composition is represented in T by a P-node, with poles are s and t, whose children are the roots of the decomposition trees T i of G i (i = 1, . . . , p).
In our algorithm we do not distinguish between Q-nodes and S-nodes whose children are all Q-nodes. We just call any of these nodes a Q * -node. In other words, a Q * -node represents a series of edges. For a node ν of T , the pertinent graph G ν of ν is the subgraph of G formed by all edges associated with the Q * -nodes in the subtree rooted at ν. We also call G ν a component of G.
Let G be a plane (two-terminal) series-parallel graph with vertex-degree at most four. Note that G is either biconnected or it can be made biconnected with the addition of a single dummy edge; in this latter case we assume that the planar embedding of G is such that the dummy edge can be added on the external face of G. For any edge e = (s, t) (possibly a dummy edge) on the external face, we can associate with G a decomposition tree T where the root is a P-node representing the parallel composition between e and the rest of the graph. Thus, the root of T is always a P-node with two children, one of which is a Q * -node corresponding to e. It will be called the (unique) P r -node of T , to distinguish it by the other P-nodes. Edge e is the reference edge of T , and T is the SPQ * -tree of G with respect to e. Without loss of generality we assume that the external face of G is to the right of e while moving from s to t. Also, it is always possible to make T such that each (non-root) P-node has no P-node child and each Snode has no S-node child. Since G has vertex-degree at most four, a P-node has either Fig. 2 The components associated with the P-nodes ν 1 , ν 3 , and ν 5 , of the graph in Fig. 1. The alias vertices are the little squares along dashed edges. For each node ν i , i ∈ {1, 3, 5}, we report G ν i , H ν i , and the spirality σ ν i of H ν i in H . In particular, the P-component of ν 3 , with poles {u = 2, v = 11}, has spirality 5 2 ; the P-component of ν 5 , with poles {u = 1, v = 11}, has spirality 2 two or three children. Finally, we assume that the left-to-right order of the children of a P-node reflects the left-to-right order that their corresponding components have in the planar embedding of G. See Fig. 1a, c. From now on we assume that T satisfies the properties above for an n-vertex biconnected series-parallel graph. Observe that the number of nodes of T is O(n).
Spirality of series-parallel graphs. Let G be a biconnected plane series-parallel graph and let T be an SPQ * -tree with respect to a reference edge e = (s, t). Let H be an (embedding-preserving) orthogonal representation of G. Also, let ν be a node of T with poles {u, v} and let H ν be the restriction of H to G ν . We also say that H ν is a component of H . For each pole w ∈ {u, v}, let indeg ν (w) and outdeg ν (w) be the degree of w inside and outside H ν , respectively. Define two (possibly coincident) alias vertices of w, denoted by w and w , as follows: (i) if indeg ν (w) = 1, then w = w = w; (ii) if indeg ν (w) = outdeg ν (w) = 2, then w and w are dummy vertices, each splitting one of the two distinct edge segments incident to w outside H ν ; (iii) if indeg ν (w) > 1 and outdeg ν (w) = 1, then w = w is a dummy vertex that splits the edge segment incident to w outside H ν .
Let A w be the set of distinct alias vertices of a pole w. Let P uv be any simple path from u to v inside H ν and let u and v be an alias vertex of u and an alias vertex of v, respectively. The path S u v obtained concatenating (u , u), P uv , and (v, v ) is called a spine of H ν . Denote by n(S u v ) the number of right turns minus the number of left turns encountered along S u v while moving from u to v . The spirality σ (H ν ) of H ν is introduced by Di Battista et al. [5] and it is defined based on the following cases (see also Di Battista et al. [5] show that the spirality of H ν does not vary with the choice of the path P uv . For brevity, in the following we often denote by σ ν the spirality of an orthogonal representation H ν of G ν . If ν is a Q * -node or a P-node with three children, σ ν is always an integer. If ν is an S-node or a P-node with two children, σ ν is either integer or semi-integer depending on whether the total number of alias vertices for the poles of ν is even or odd. When we say that the spirality σ ν can take all values in an interval [a, b], we mean that such values are either all the integer numbers or all the semi-integer numbers in [a, b], depending on the cases described above for ν.

Substituting Orthogonal Components with the Same Spirality
Let G be a biconnected plane series-parallel graph and let T be an SPQ * -tree of G with respect to a given reference edge. Di Battista et al. [5] prove that two distinct orthogonal representations of the same component G ν that have the same spirality are "interchangeable", under some additional hypotheses. Roughly speaking, they prove that if a component H ν has a certain spirality in a given orthogonal representation H , it can be substituted with another representation H ν having the same spirality, under the assumption that the angles at the poles of ν that are outside G ν do not change.
In this subsection we formalize the concept of substituting an orthogonal component with another one and give a stronger version of the result in [5], which proves the interchangeability of two orthogonal components that have the same spirality, regardless of their angles at the poles.
Let H and H be two different orthogonal representations of G with the reference edge on the external face, and let H ν and H ν be the restrictions of H and H to G ν , respectively. If σ (H ν ) = σ (H ν ), the operation of substituting H ν with H ν in H , denoted by Sub(H ν , H ν ), defines a new plane graph H with an angle labeling, such that: (a) H corresponds to a valid orthogonal representation of G; (b) the restriction of H to G ν coincides with H ν ; (c) the restriction of H to G \ G ν stays as in H .
More formally, let u and v be the two poles of ν. The external boundary of H ν contains a left path p l and a right path p r , such that p l goes from u to v while traversing the external boundary of H ν clockwise and p r goes from u to v while traversing the external boundary of H ν counterclockwise. Denote by f l the face of H outside H ν and incident to p l , and denote by f r the face of H outside H ν and incident to p r . Also, for each pole w ∈ {u, v} of ν, denote by a w,l (resp. a w,r ) the angle at w in face f l (resp. f r ) of H . Similarly, with respect to H ν and H , define p l , p r , f l , f r , and a w,l , a w,r for each pole w ∈ {u, v}. The operation Sub(H ν , H ν ) defines H as follows (schematic illustrations are given in Figs. 3, 4, 5): • The set of vertices and the set of edges of H are the same as in G.
• The planar embedding of H is such that: all faces of H outside H ν and distinct from f l and f r , as well as all faces of H ν , are also faces of H . Also, H has two faces f l and f r obtained by replacing p l with p l and p r with p r in the boundary of f l and f r , respectively. • The angle labeling of H is such that: (i) all the angles at the vertices and along the edges of G not belonging to G ν are those in H ; (ii) all the angles at the vertices of G ν distinct from u and v are those in H ν ; (iii) all the angles along the edges of G ν are those in H ν ; (iv) for each pole w ∈ {u, v} of ν, the angles at w that are outside G ν and that are neither in f l nor in f r are those in H ; the angles at w that are inside G ν are those in H ν ; the angle a w,l at w in f l and the angle a w,r at w in f r are such that a w,l = a w,l and a w,r = a w,r if indeg ν (w) = 1, while a w,l = a w,l and a w,r = a w,r if indeg ν (w) > 1.
The next theorem proves that H is a valid orthogonal representation. It remains to show that (H1) holds for u and v, and that (H2) holds for f l and f r . To this aim, we analyze different cases based on the indegree of the two poles {u, v} of G ν . Case 1: indeg ν (u) = 1 and indeg ν (v) = 1. Refer to Fig. 3. In this case, the alias vertices u and v , associated with u and v respectively, coincide with the poles, i.e., u = u and v = v . Let ux and yv be the two edge segments of H ν incident to u and to v, respectively. Analogously, let ux and y v be the two edge segments of H ν incident to u and to v, respectively. Without loss of generality, assume that H and H are oriented in such a way that both ux and ux are vertical segments and that u is below x in any drawing of H and u is below x in any drawing of H . By definition, since u = u and v = v , the spirality σ (H ν ) (resp. σ (H ν )) equals the number of right turns minus the number of left turns while moving from u to v along any simple path of H ν (resp. of H ν ). Hence, since by hypothesis σ (H ν ) = σ (H ν ), the edge segments yv and y v are either both horizontal or both vertical, and more precisely they are incident to v in H and to v in H from the same side (south, north, west, or east). In this case, Sub(H ν , H ν ) defines a u,l = a u,l , a u,r = a u,r , a v,l = a v,l , and a v,r = a v,r , which implies that all the angles around u and v in H coincide with the angles around u and v in H . Hence, Property (H1) holds for both u and v in H . Also, let n( p l ) (resp. n( p r )) be the number of right turns minus the number of left turns along p l (resp. p r ) while moving from u to v in H . Similarly, let n( p l ) (resp. n( p r )) be the number of right turns minus the number of left turns along p l (resp. p r ) while moving from u to v in H . Since σ (H ν ) = σ (H ν ), and since u = u and v = v , we have n( p l ) = n( p l ) and n( p r ) = n( p r ). It follows that , which imply Property (H2) for f l and f r (note that, since G is biconnected, N 360 ( f ) = 0 for every face f of H and of H ). Case 2: indeg ν (u) = 1 and indeg ν (v) > 1. We distinguish two subcases: outdeg ν (v) = 1 or outdeg ν (v) = 2. Assume first that outdeg ν (v) = 1 (see Fig. 4a). In this case, u and its alias vertex u coincide and the only alias vertex v associated with v subdivides the edge segment incident to v in H and in H . As in the analysis of Case 1, assume that H and H are oriented so that each of the two edge segments ux and ux in H and in H , respectively, is incident to u from north. By definition, the spirality σ (H ν ) (resp. σ (H ν )) in this case equals the number of right turns minus the number of left turns along any simple path of H ν (resp. of H ν ) from u to v . Since σ (H ν ) = σ (H ν ), this implies that the segments vv in H and H are incident to v from the same side. In this case, Sub(H ν , H ν ) defines a u,l = a u,l , a u,r = a u,r , a v,l = a v,l , and a v,r = a v,r , which implies that all the angles around u in H coincide with the angles around u and all the angles around v in H coincide with those around v in H . Thus, Property (H1) holds for u and v in H . It remains to prove (H2) for f l and f r . Denote by P l (resp. P r ) the path of H obtained by concatenating p l (resp. p r ) with the edge segment vv . Analogously, denote by P l (resp. P r ) the path of H obtained by concatenating p l (resp. p r ) with the edge segment vv . Since σ (H ν ) = σ (H ν ), with the usual notation we have n(P l ) = n(P l ) and n(P r ) = n(P r ). Since, as observed above, the segments vv in H and H are incident to v from the same side, and since the angles at u are the same in H and in H , Suppose now that outdeg ν (v) = 2 (see Fig. 4b). In this case, u and its alias vertex u coincide while v has two alias vertices v and v , which subdivides the two edge segments incident to v in H and in H . Since deg(v) = 4, the angles at v are all 90 • degree angles, both in H and in H . It follows that, the angles at u and v in H are the same as in H , i.e., Property (H1) holds. Denote by P l (resp. P r ) the path of H obtained by concatenating p l (resp. p r ) with the edge segment vv (resp. vv ). Analogously, denote by P l (resp. P r ) the path of H obtained by concatenating p l (resp. p r ) with the edge segment vv (resp. vv ). Since σ (H ν ) = σ (H ν ), we have n(P l )+n(P r ) 2 = n(P l )+n(P r ) 2 . On the other hand, since all angles at v are right angles in H and in H , we have n(P r ) = n(P l ) + 1 and n(P r ) = n(P l ) + 1. This implies that n(P l ) = n(P l ) and n(P r ) = n(P r ), which, together with the fact that the angles at u are the same in H and H , implies that and Hence, Property (H2) holds for f l and f r . Case 3: indeg ν (u) > 1 and indeg ν (v) = 1. This case is symmetric to Case 2. Case 4: indeg ν (u) > 1 and indeg ν (v) > 1. In this case, there are three non-symmetric subcases to analyze, depending on the outdegree of u and of v, i.e., outdeg ν (u) = outdeg ν (v) = 1, or outdeg ν (u) = 1 and outdeg ν (v) = 2 (symmetrically outdeg ν (u) = 2 and outdeg ν (v) = 1), or outdeg ν (u) = outdeg ν (v) = 2. See "Appendix A" for details and refer to Fig. 5 for a schematic illustration.
Based on Theorem 1, in the following we can assume that two orthogonal components with the same spirality are equivalent, and we can describe the set of possible orthogonal representations for a component in terms of their spirality values.

Rectilinear Plane Series-Parallel Graphs
This section characterizes rectilinear plane series-parallel graphs. Let G be a plane series-parallel 4-graph. If G is biconnected let e be any edge on the external face of G; otherwise, we add a dummy edge e that makes it biconnected (recall that, if G is not biconnected we are assuming that the dummy edge e can always be added in the external face). Let T be the SPQ * -tree of G with respect to e and let ν be a node of T . We say that a component G ν admits spirality σ ν or, equivalently, that ν admits spirality σ ν , if there exists a rectilinear planar representation H ν of G ν with spirality σ ν in some rectilinear planar representation H of G. The following lemmas immediately derive from the results of Di Battista et al. [5], which for any S-node or P-node ν, relate the values of spirality for an orthogonal representation of G ν to the values of spirality of the orthogonal representations of the child components of G ν (i.e., the components corresponding to the children of ν). These types of relationships will be crucial to characterize those components that are rectilinear planar in a bottom-up traversal of T . Namely, Lemma 1 concentrates on S-nodes, Lemma 2 on P-nodes with three children, and Lemma 3 on P-nodes with two children. See also Fig. 6 for an illustration.
Lemma 1 [5] Let ν be an S-node of T with children μ 1 , . . . , μ h (h ≥ 2). The component G ν admits spirality σ ν if and only if Lemma 2 [5] Let ν be a P-node of T with three children μ l , μ c , and μ r . G ν admits spirality σ ν with G μ l , G μ c , G μ r in this left-to-right order if and only if there exist Fig. 6 Illustration of the relationships in: a Lemma 1 for S-nodes, b Lemma 2 for P-nodes with three children, and c Lemma 3 for P-nodes with two children three values σ μ l , σ μ c , and σ μ r such that: (i) G μ l , G μ c , G μ r admit spirality σ μ l , σ μ c , σ μ r , respectively; and (ii) If ν is a P-node with two children, denote by μ l and μ r its left and right child in T , respectively. If ν is a P-node with three children, denote by μ l , μ c , and μ r , the three children of ν from left to right. Also, for each pole w ∈ {u, v} of ν, the leftmost angle at w in H is the angle formed by the leftmost external edge and the leftmost internal edge of H ν incident to w. The rightmost angle at w in H is defined symmetrically. We define two binary variables α l w and α r w as follows: α l w = 0 (α r w = 0) if the leftmost (rightmost) angle at w in H is 180 • , while α l w = 1 (α r w = 1) if this angle is 90 • . Observe that if deg(w) = 4 or if ν has three children, α l w = α r w = 1. Also, if ν has two children, define two additional variables k l w and k r w as follows:

Lemma 3 [5]
Let ν be a P-node of T with two children μ l and μ r , and with poles u and v. G ν admits spirality σ ν with G μ l and G μ r in this left-to-right order if and only if there exist six values σ μ l , σ μ r , α l u , α r u , α l v , and α r v such that: (i) G μ l and G μ r admit spirality σ μ l and σ μ r , respectively; (ii) α l w ∈ {0, 1}, α r w ∈ {0, 1}, and 1 ≤ α l w +α r w ≤ 2 for any w ∈ {u, v}; and (iii) In the following we prove a condition under which the plane graph G ν is rectilinear planar, assuming that its child components (if ν is not a leaf of T ) are rectilinear planar. This condition depends on the type of node ν and is referred to as representability condition of ν (or, equivalently, of G ν ). Also, if the representability condition holds for ν, we denote by I ν the set of values of spirality for which G ν is rectilinear planar, i.e., G ν admits spirality σ ν if and only if σ ν ∈ I ν . We prove that I ν is always an interval (of all integer or all semi-integer values) and call it the representability interval of ν (or, equivalently, of G ν ).

Representability Condition for Q * -Nodes and S-Nodes
For a Q * -node ν representing a chain of edges, we say that is the length of ν. As the next lemmas prove, the components of Q * -and S-nodes are always rectilinear planar, i.e., the representability condition is always true.

Lemma 4
Let ν be a Q * -node of length . Graph G ν is always rectilinear planar (i.e., its representability condition is always true) and its representability interval is Proof G ν is a path with − 1 degree-2 vertices. For any integer k ∈ [− + 1, 0], a rectilinear planar representation H ν of G ν with spirality k is obtained by making a left turn at k degree-2 vertices of G ν (going from the source to the sink pole), and no turn at any remaining vertex of G ν . Symmetrically, for any k ∈ (0, − 1], we realize H ν with spirality k by making a right turn at exactly k degree-2 vertices of G ν . It is clear that no values of spirality out of I ν can be achieved. Lemma 5 Let ν be an S-node with h ≥ 2 children μ 1 , . . . , μ h . Suppose that, for every i ∈ [1, h], the representability interval of G μ i is Graph G ν is always rectilinear planar (i.e., its representability condition is always true) and its representability interval is Proof We use induction on the number of children of ν. In the base case h = 2. By hypothesis I μ 1 = [m 1 , M 1 ] and I μ 2 = [m 2 , M 2 ]. By Lemma 1, a series composition of a rectilinear representation of G μ 1 with spirality σ μ 1 and of a rectilinear representation of G μ 2 with spirality σ μ 2 results in a rectilinear representation of G ν with spirality σ ν = σ μ 1 + σ μ 2 . Hence, if M 1 = m 1 + r 1 and M 2 = m 2 + r 2 , for two non-negative integers r 1 and r 2 , then the possible values for σ ν are exactly m 1 + m 2 , m 1 + 1 + m 2 , . . . , m 1 + r 1 + m 2 , . . . , m 1 + r 1 + m 2 + 1, . . . , m 1 + r 1 + m 2 + r 2 , i.e., all values in the interval In the inductive case h ≥ 3; consider the series composition G 1 of G μ 1 , . . . , G μ h−1 . Graph G ν is the series composition of G 1 and G μ h . By the inductive hypothesis the representability interval of  1]. (c) A rectilinear planar representation of G ν with spirality σ ν for every σ ν ∈ I ν by Lemma 1 applied to G 1 and G μ h we have , using the same reasoning as for the base case.  Figure 8a shows an S-node ν and its three children μ 1 , μ 2 , and μ 3 , where μ 1 and μ 3 are Q * -nodes and μ 2 is a P-node. Figure 8b shows the components G ν , G μ 1 , G μ 2 , and G μ 3 , where: I μ 1 = [0, 0] and I μ 3 = [−2, 2] by Lemma 4; I μ 2 = [−1, −1], as G μ 2 only admits a rectilinear planar representation of spirality −1. By Lemma 5, Figure 8c depicts a rectilinear planar representation of G ν with spirality σ ν for every σ ν ∈ I ν .

Representability Condition for P-Nodes with Three Children
Different from S-nodes, if ν is a P-node and the pertinent graphs of the children of ν are rectilinear planar, G ν may not be rectilinear planar. In this subsection we consider the case when ν has three children.  Proof Representability condition. Suppose first that G ν is rectilinear planar and let H ν be a rectilinear planar representation of G ν with spirality σ ν . By Lemma 2, the spirality values σ μ l , σ μ c , and σ μ r for the representations of G μ l , G μ c , and G μ r in H ν are such that σ μ l = σ ν +2, σ μ c = σ ν , and Analogously to the second part of the proof of the representability condition, we can construct a rectilinear planar representation of G ν with spirality σ ν = k, by combining in parallel rectilinear planar representations of G μ l , G μ c , and G μ r with spirality values σ μ l = σ ν + 2, σ μ c = σ ν , and σ μ r = σ ν − 2.

Representability Condition for P-Nodes with Two Children
For a P-node ν with two children μ l and μ r , the representability condition and interval depend on the different configurations of indegree and outdegree of the poles of ν in G ν , G μ l , and G μ r . To distinguish the different configurations, we define the type of ν and of G ν , using a self-contained notation; refer also to Fig. 10 for a schematic illustration. Each type is denoted using one or two symbols, I (indegree) and O (outdegree), along with suitable indices. More precisely, the possible types are defined as follows: • I 2 O λβ : both poles of ν have indegree two in G ν ; also one pole has outdegree λ in G ν and the other pole has outdegree β in G ν , for 1 ≤ λ ≤ β ≤ 2. This gives rise to the specific types I 2 O 11 , I 2 O 12 , and I 2 O 22 . • I 3d O λβ : one pole of ν has indegree two in G ν , while the other pole has indegree three in G ν and indegree two in G μ d for d ∈ {l, r }; also one pole has outdegree λ in G ν and the other has outdegree β in G ν , for 1 ≤ λ ≤ β ≤ 2, where λ = β = 2 is not possible. This gives rise to the specific types I 3 l O 11 , I 3r O 11 , I 3 l O 12 , I 3r O 12 . • I 3dd : both poles of ν have indegree three in G ν ; one of the two poles has indegree two in G μ d and the other has indegree two in G μ d , for dd ∈ {ll, lr, rr} (both poles have outdegree one in G ν ). Hence, the specific types are I 3ll , I 3lr , I 3rr .
In the next three subsections, we analyze separately the properties of the different types of P-nodes with two children.

Nodes of Type I 2 O Ľ
emma 8 states the representability condition and interval for P-nodes of type I 2 O λβ . Its proof is based on the preliminary property stated by Lemma 7.

Lemma 7
Let G ν be a P-node of type I 2 O λβ with children μ l and μ r . G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and Proof We distinguish three cases, based on the values of λ and β, namely the cases I 2 O 11 , I 2 O 12 , and I 2 O 22 . Case 1: λ = β = 1, i.e., G ν is of type I 2 O 11 . We have to prove that G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r in any rectilinear planar representation of G ν . Hence, by Lemma 3, for any value of spirality . Suppose vice versa that G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r ∈ [2,4]. We define a rectilinear planar representation H ν of G ν by combining in parallel the two rectilinear planar representations of G μ l and G μ r and by suitably assigning the values of α d u and α d v (d ∈ {l, r }), depending on the value of σ μ l − σ μ r . This assignment is such that for any cycle C of G ν through u and v, the number of 90 • angles minus the number of 270 • angles in the interior of C is equal to four. Poles u and v split C into two paths π l and π r . The spirality σ μ l equals the number of right minus left turns along π l while going from u to v, which corresponds to the number of 90 • minus 270 • angles in the interior of C at the vertices of π l . Similarly, −σ μ r equals the number of right minus left turns along π r while going from v to u, which corresponds to the number of 90 • minus 270 • angles in the interior of C at the vertices of π r . By also considering the angles at u and v inside C, the number of 90 • angles minus the number of 270 • angles inside C can be expressed as and three cases are possible: (i) if σ μ l − σ μ r = 2, for every pole w ∈ {u, v} we set α l w and α r w such that α l w + α r w = 1; (ii) if σ μ l − σ μ r = 3, for one pole w ∈ {u, v} we set α l w and α r w such that α l w + α r w = 1, and for the other pole w ∈ {u, v} we set α l In all the cases above, we have that a c = 4. Also, any other cycle not passing through u and v is an orthogonal polygon because it belongs to a rectilinear planar representation of either G μ l (with spirality σ μ l ) or G μ r (with spirality σ μ r ). Case 2: λ = 1 and β = 2, i.e., G ν is of type I 2 O 12 . We have to prove that G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r ∈ [2,3]. Suppose, w.l.o.g., that outdeg ν (u) = 1 and Suppose vice versa that G μ l and G μ r are rectilinear planar with spirality σ μ l and σ μ r such that σ μ l − σ μ r ∈ [2,3]. As in the previous case, we define a rectilinear planar representation H ν of G ν , by combining in parallel the two representations of G μ l and G μ r and by suitably setting α d u and α d v (d ∈ {l, r }). Namely, we set α l v = α r v = 1, and the values of α l u and α r u as follows: With an argument similar to the previous case, for any cycle C through u and v, the number of 90 • angles minus the number of 270 • angles in C can be expressed in this case by Any other cycle not passing through u and v remains the same as in the representations of G μ l and G μ r . Case 3: λ = β = 2, i.e., G ν is of type I 2 O 22 . We prove that G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that Suppose vice versa that σ μ l − σ μ r = 2. Again, we obtain a rectilinear planar representation H ν of G ν by combining in parallel the representations of G μ l and G μ r and by suitably setting α d u and α d v (d ∈ {l, r }). In this case, for any cycle C through u and v, the number of 90 • angles minus the number of 270 • angles in C can be expressed by a c = σ μ l − σ μ r + 1 + 1 (both the angles at u and v inside C is always of 90 • degrees). We then set Proof We prove the correctness of the representability condition and the validity of the representability interval. Representability condition. Suppose that G ν is rectilinear planar. By Lemma 7, G μ l and G μ r admit spirality values σ μ l and σ μ r , respectively, such that . This implies that for every integer value k in the interval [m l − M r , M l −m r ], there exist rectilinear planar representations for G μ l and G μ r with spirality values σ μ l and σ μ r such that σ μ l − σ μ r = k. Since by hypothesis there exists , there must be two spirality values σ μ l and σ μ r for the representations of G μ l and G μ r such that σ μ l − σ μ r = k ∈ [2, 4 − γ ]. Hence, by Lemma 7, G ν is rectilinear planar.

Representability interval.
As in the proof of Lemma 7, we distinguish three cases, based on the values of λ and β. Case 1: λ = β = 1, i.e., G ν is of type I 2 O 11 . We prove that Assume first that σ ν is the spirality of a rectilinear representation of G ν . By We now distinguish the following subcases: respectively. As already observed, k + 2 ≥ m l and by hypothesis k With this choice we have 2 ≤ σ μ l − σ μ r ≤ 4, and we can combine H μ l and H μ r in parallel as in the proof of Lemma 7 to obtain a rectilinear planar representation H ν of G ν . By Lemma 3 the spirality of H ν equals . In the first case, choose any representation H μ r with spirality σ r = M l −3, which implies σ μ l −σ μ r = 3 ∈ [2,4]. In the second case, choose H μ r with spirality σ r = M l −2, which implies σ μ l − σ μ r = 2 ∈ [2,4]. H μ l and H μ r can be combined in parallel to get a representation of G ν with spirality σ ν = k. Namely, by Lemma 3 we can set α l u = 0 and α l v = 1 (or vice versa); also, if σ μ r = M l − 2 we set α r u = 0 and Case 2: λ = 1 and β = 2, i.e., G ν is of type I 2 O 12 . The arguments are similar to the previous case; see "Appendix B" for details.
Assume first that G ν is rectilinear planar and let H ν be a rectilinear planar representation of G ν with spirality σ ν . Let H μ l and H μ r be the rectilinear planar representations of G μ l and G μ r contained in H ν , and let σ μ l and σ μ r be their spirality values. Since both u and v have outdegree two in G ν we have that α l u + α r u = α l v + α r v = 2. By Lemma 3, σ μ l = σ ν + 1 and σ μ r = σ ν − 1. By the representability condition, Assume vice versa that k is an integer in the interval . We show that there exists a rectilinear planar representation of G ν with spirality σ ν = k. We have k + 1 ∈ [max{m l , m r + 2}, min{M l , M r + 2}] and therefore k + 1 ∈ [m l , M l ]. Hence there exists a rectilinear planar repre- Hence there exists a rectilinear planar representation H μ r of G μ r with spirality σ μ r = k −1. By the representability condition G ν has a rectilinear planar representation H ν ; also, following the same construction as in the proof of Lemma 7, the spirality of H ν is σ ν = k.

Nodes of Type I 3d O Ľ
emma 10 states the representability condition and interval for P-nodes of type I 2 O λβ . Its proof is based on the preliminary property stated by Lemma 9.

Lemma 9
Let G ν be a P-node of type I 3d O λβ and let μ l and μ r be its two children. G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r , respectively, such that Proof We distinguish four cases, based on the values of λ, β, and d. Case 1: λ = β = 1 and d = l, i.e., G ν is of type I 3 l O 11 . We prove that G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r ∈ [ 5 2 , 7 2 ]. For an in any rectilinear planar representation of G ν . Hence, by Lemma 3, for any value of spirality σ ν we have 7 2 ]. Suppose vice versa that G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r ∈ [ 5 2 , 7 2 ]. We define a rectilinear planar representation H ν of G ν , by combining in parallel the two rectilinear planar representations of G μ l and G μ r and by suitably assigning the values of α l u and α r u , depending on the value of σ μ l − σ μ r .
Let v be the alias vertex of G μ l that is in G ν . Any cycle C that goes through u and v also passes through v . We show that the number of 90 • angles minus the number of 270 • angles inside C is equal to four.
Vertices u and v split C into two paths π l and π r . Suppose to visit C clockwise. The number of right minus left turns along π l while going from u to v equals σ μ l + 1 2 . The number of right minus left turns along π r while going from v to u equals −σ μ r . Hence, the sum σ μ l + 1 2 − σ μ r + 2 − α r u − α l u corresponds to the number of 90 • angles minus the number of 270 • angles inside C at the vertices of π l . Notice that Any other cycle not passing through u and v remains the same as in the representations of either G μ l (with spirality σ μ l ) and G μ r (with spirality σ μ r ). Case 2: λ = 1, β = 2, and d = l, i.e., G ν is of type I 3 l O 12 . We prove that G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r = 5 2 (note that this corresponds to the interval in any rectilinear planar representation of G ν . Hence, by Lemma 3, for any value of spirality σ ν we have Suppose vice versa that G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r = 5 2 . As usual, we define H ν by combining in parallel the two rectilinear planar representations of G μ l and G μ r and we assign values Let v be the alias vertex of G μ l that is in G ν . Any cycle C that goes through u and v also passes through v . Vertices u and v split C into two paths π l and π r . Suppose to visit C clockwise. The number of right turns minus left turns along π l while going from u to v equals σ μ l + 1 2 . The number of right turns minus left turns along π r while going from v to u equals −σ μ r . Also, pole u forms a 90 • angle in C. Hence, the sum σ μ l + 1 2 − σ μ r + 1 corresponds to the number of 90 • angles minus the number of 270 • angles in C at the vertices of π l . Since σ μ l − σ μ r = 5 2 we have σ μ l + 1 2 − σ μ r + 1 = 5 2 + 1 2 + 1 = 4. Any other cycle not passing through u and v remains the same as in the rectilinear representations of G μ l (with spirality σ μ l ) and G μ r (with spirality σ μ r ). Case 3: λ = β = 1 and d = r . Symmetric to Case 1. Case 4: λ = 1, β = 2, and d = r . Symmetric to Case 2.

Lemma 10
Let ν be a P-node of type I 3d O λβ with children μ l and μ r . Suppose that G μ l and G μ r are rectilinear planar with representability intervals is a function such that φ(r ) = 1 and φ(l) = 0.
Proof We prove the correctness of the representability condition and the validity of the representability interval.
Representability condition. Suppose that G ν is rectilinear planar. By Lemma 9, G μ l and G μ r admit spirality values σ μ l and σ μ r , respectively, such that . This implies that for every semi-integer value k in the interval [m l − M r , M l − m r ], there exist rectilinear planar representations for G μ l and G μ r with spirality values σ μ l and σ μ r such that σ μ l − σ μ r = k. Since by hypothesis there , there must be two values of spirality values σ μ l and σ μ r for the representations of G μ l and G μ r such that Hence, by Lemma 9, G ν is rectilinear planar. Representability interval. As for Lemma 9, the case analysis is based on the values of λ, β, and d; w.l.o.g. we assume that v is the pole of degree four.
]. Assume first that σ ν is the spirality of a rectilinear planar representation of G ν . Since for an and consequently, σ ν + 1 2 = M l and σ ν − 1 = m r ; hence, it would be M l − m r = 3 2 and, by the representability condition, G ν would not be rectilinear planar.
Based on this observation, we can construct a rectilinear planar representation H μ l of G μ l with spirality σ μ l and a rectilinear planar representation H μ r of G μ r with spirality σ μ r , by distinguishing the following cases, one of which must be verified: We set σ μ l = σ ν + 3 2 and σ μ r = σ ν − 2.
In all the three cases we have σ μ l − σ μ r ∈ [ 5 2 , 7 2 ], hence, there exists a rectilinear planar representation H ν of G ν given the values of σ μ l and σ μ r . We have to prove that in the three cases the spirality of H ν is σ ν . By Lemma 3 we have Assume first that σ ν is the spirality of a rectilinear planar representation of G ν . Since for an We can construct a rectilinear planar representation H μ l of G μ l with spirality σ μ l = σ ν + 1 and a rectilinear planar representation H μ r of G μ r with spirality σ μ r = σ ν − 3 2 . Notice that, for this choice, we have σ μ l −σ μ r = 5 2 , hence, there exists a rectilinear planar representation H ν of G ν given the values of σ μ l and σ μ r . We have to prove that the spirality of H ν is σ ν . By Lemma 3 we have

Nodes of Type I 3dd
Lemma 12 states the representability condition and interval for P-nodes of type I 2 O λβ . Its proof is based on the preliminary property stated by Lemma 11.

Lemma 11
Let G ν be a P-node of type I 3dd and let μ l and μ r be its two children. G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r , respectively, such that σ μ l − σ μ r = 3.
Proof We distinguish three cases, based on the values of d and d . The proof for type I 3rl is symmetric to the one for type I 3lr . Case 1: d = d = l, i.e., G ν is of type I 3ll . We prove that G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r = 3. For an I 3ll component we have k l u = k l v = 1 2 and k r u = k r v = 1. If G ν is rectilinear planar, we have α l u = α r u = α l v = α r v = 1 in any rectilinear planar representation of G ν . Hence, by Lemma 3, for any value of spirality σ ν we have σ μ l − σ μ r = 1 2 α l u + 1 2 α l v + α r u + α r v = 3. Suppose vice versa that G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r = 3. We define a rectilinear planar representation H ν of G ν , by combining in parallel the two rectilinear planar representations of G μ l and G μ r with values α l u = α l v = α r u = α r v = 1. Let u and v be the alias vertices of G μ l that subdivide edges of G ν . Any cycle C through u and v also passes through u and v .
Vertices u and v split C into two paths π l and π r . Suppose to visit C clockwise. The number of right turns minus left turns along π l while going from u to v equals σ μ l + 1. The number of right turns minus left turns along π r while going from v to u equals −σ μ r . The sum of these two values corresponds to the number of 90 • angles minus the number of 270 • angles in the interior of C at the vertices of π l ; we have σ μ l + 1 − σ μ r = 3 + 1 = 4. All other cycles not passing through u and v are orthogonal polygons as they remain the same as in G μ l (with spirality σ μ l ) and G μ r (with spirality σ μ r ). Case 2: d = d = r . Symmetric to Case 1, observing that k r u = k r v = 1 2 and k l u = k l v = 1. Case 3: d = l and d = r , i.e., G ν is of type I 3lr . We prove that G ν is rectilinear planar if and only if G μ l and G μ r are rectilinear planar for spirality values σ μ l and σ μ r such that σ μ l − σ μ r = 3. For an I 3lr component we have k r u = k l v = 1 2 and k l u = k r v = 1. If G ν is rectilinear planar, we have α l u = α r u = α l v = α r v = 1 in any rectilinear planar representation of G ν . Hence, by Lemma 3, for any value of spirality σ ν we have Suppose vice versa that G μ l and G μ r are rectilinear planar for values of spirality σ μ l and σ μ r such that σ μ l − σ μ r = 3. We define H ν by combining in parallel the two rectilinear planar representations of G μ l and G μ r , with values α l Let v be the alias vertex of the pole v of G μ l such that v subdivides an edge of G ν . Similarly, let u be the alias vertex of the pole u of G μ r such that u subdivides an edge of G ν . Any cycle C through u and v also passes through u and v .
Vertices u and v split C into two paths π l and π r . Visiting C clockwise, the number of right minus left turns along π l while going from u to v equals σ μ l + 1 2 . The number of right minus left turns along π r while going from v to u equals −σ μ r + 1 2 . The sum of these two values corresponds to the number of 90 • angles minus the number of 270 • angles in the interior of C at the vertices of π l , and we have is a function such that φ(r ) = 1 and φ(l) = 0.
Proof We prove the correctness of the representability condition and the validity of the representability interval. Representability condition. Suppose that G ν is rectilinear planar. By Lemma 11, G μ l and G μ r admit spirality values σ μ l and σ μ r , respectively, such that σ μ l − σ μ r = 3.
Suppose, vice versa that 3 ∈ [m l − M r , M l − m r ]. By hypothesis G μ l (resp. G μ r ) is rectilinear planar for every value of spirality in the interval [m l , M l ] (resp. [m r , M r ]). This implies that there exist rectilinear planar representations for G μ l and G μ r with spirality values σ μ l ∈ [m l , M l ] and σ μ r ∈ [m r , M r ] such that σ μ l − σ μ r = 3. Hence, by Lemma 11 G ν is rectilinear planar. Representability interval. We distinguish three cases, based on the values of d and d . Note that a possible forth case for the type I 3rl is symmetric to the case for the type I 3lr .
Assume first that σ ν is the spirality of a rectilinear planar representation of G ν . Since for an I 3ll component we have Conversely, we show that if σ ν ∈ [max{m l − 1, m r + 2}, min{M l − 1, M r + 2}], there exists a rectilinear planar representation of G ν with spirality σ ν . We have We can construct a rectilinear planar representation H μ l of G μ l with spirality σ μ l = σ ν + 1 and a rectilinear planar representation H μ r of G μ r with spirality σ μ r = σ ν − 2. Note that, for this choice, we have σ μ l − σ μ r = 3, hence, there exists a rectilinear planar representation H ν of G ν given the values of σ μ l and σ μ r . We have to prove that the spirality of H ν is σ ν . By Lemma 3 we have σ ν = σ μ l − 1 2 α l u − 1 2 α l v , where σ ν is the spirality of the representation H ν of G ν given a choice of σ μ l , α l v , and α l u . Since σ ν = σ μ l − 1, α l u = 1, and α l v = 1, we have σ ν = σ ν + 1 − 1 2 − 1 2 = σ ν . Case 2: d = d = r . Symmetric to Case 1. Case 3: d = l and d = r , i.e., G ν is of type I 3lr . We prove that . Assume first that σ ν is the spirality of a rectilinear planar representation of G ν . Since for an I 3lr component we have k r u = k l v = 1 2 and k l u = k r v = 1, by Lemma 3 we have We can construct a rectilinear planar representation H μ l of G μ l with spirality σ μ l = σ ν + 3 2 and a rectilinear planar representation H μ r of G μ r with spirality σ μ r = σ ν − 3 2 . Notice that, for this choice, we have σ μ l − σ μ r = 3, hence, there exists a rectilinear planar representation H ν of G ν given the values of σ μ l and σ μ r . We have to prove that the spirality of H ν is σ ν . By Lemma 3, σ ν = σ μ l − α l u − 1 2 α l v , where σ ν is the spirality of the representation H ν of G ν given a choice of σ μ l , α l v , and α l u . Since σ ν = σ μ l − 3 2 , α l u = 1, and α l v = 1, we have σ ν = σ ν + 3 2 − 1 − 1 2 = σ ν .

Representability Condition for the Root
To finally achieve a characterization of rectilinear series-parallel graphs we need to consider the representability condition that must be verified at the level of the root, when the reference edge is not a dummy edge. Denote by e = (u, v) the reference edge of G and let ρ be the root of T with respect to e. Let η be the child of ρ that does not correspond to e, and let u and v be the alias vertices associated with the poles u and v of G η . Suppose that G η is rectilinear planar with representability interval I η .
The next theorem summarizes the main result of this section.

Representability Condition
] P-node with two children

Representability Interval
Root condition

Overview of the Bend-Minimization Algorithm
Let G be a plane series-parallel 4-graph. If G is biconnected let e be any edge on the external face of G; otherwise, we add a dummy edge e that makes it biconnected. Let T be the SPQ * -tree of G with respect to e. Our bend-minimization algorithm works in two phases. It first visits T bottom-up (in post order) to determine the number of bends of a bend-minimum orthogonal representation of G. Then it visits T top-down to construct such an orthogonal representation. When a node ν is considered in the bottom-up visit, the algorithm assigns to ν a budget b ν of bends. This budget corresponds to the minimum number of extra bends that must be added to the budgets of the children of ν to realize an orthogonal representation of G ν . In other words, b ν can be regarded as the minimum number of extra subdivision vertices that must be inserted along the edges of G ν (besides those already inserted for the children of ν) to make it rectilinear planar. The budget b ν is larger than zero if and only if the representability condition of the rectilinear planarity testing for ν is not satisfied. Hence, according to Table 1, b ν = 0 if ν is a Q * -or an S-node, while it can be positive if ν is a P-node or the root of T . For instance, for the graph of Fig. 1a and the tree T of Fig. 1c, the first component that requires some bends in the bottom-up visit of T is G ν 3 , namely b ν 3 = 3; two more bends are required at the root level, i.e., b ρ = 2. When b ν > 0, a crucial and non-trivial aspect is how to efficiently compute b ν . The other key aspect is how to succinctly describe the set I ν of spirality values that a rectilinear representation of a subdivision of G ν can take, by considering all possible distributions of the b ν subdivision vertices along its edges. We will show that I ν is still an interval, which allows us to represent it in O(1) space. Section 6 describes how to compute the budgets b ν and the sets I ν in the bottom-up visit of T , and it proves the optimality of the solution. Section 7 describes the top-down visit and summarizes our main result.

Budgets and Optimality
In the following we denote by m and M the minimum and maximum values of the representability interval I ν of ν when G ν is rectilinear planar, as defined in Table  1. Also, since when we visit ν, all its children have already been visited and have received their own budget of bends (i.e., of subdivision vertices for the corresponding component), we will simply assume that each child of ν is rectilinear planar.
As observed, if ν is either a Q * -node or an S-node, b ν = 0. Hence, we assume that ν is a P-node. A child μ of a (non-root) P-node ν is either a Q * -or an S-node. To compute b ν and I ν we define the concept of exposed edge of μ. If μ is a Q * -node, every edge of G μ is an exposed edge of μ (and of G μ ). If μ is an S-node with at least one Q * -node child μ , every edge of G μ that belongs to G μ is an exposed edge of μ (and of G μ ). Else, μ is an S-node that has no exposed edge. Lemma 14 states a crucial property. It implies that when we need to insert some subdivision vertices in an S-component μ that is a child of ν, these vertices can always be added along an exposed edge of μ, if one exists. bends. An exposed edge, shown as a red thick segment. b A different orthogonal representation H μ of the same component having the same spirality and number of bends as H μ , but such that all the bends are along the red thick exposed edge (Color figure online)

Lemma 14 Let μ be an S-node such that G μ is rectilinear planar and μ has an exposed edge e. Let H μ be an orthogonal representation of G μ having b > 0 bends. There exists an orthogonal representation H μ of G μ with b bends such that: (i) all the b bends of H μ lie on e; (ii) σ (H μ ) = σ (H μ ).
Proof Let u and v be the poles of G μ . Any path from u to v inside G μ contains the exposed edge e. Consider an orthogonal representation H μ of G μ with b > 0 bends. Let e = e be an edge with at least one bend in H μ . Let P uv be any simple path from u to v of H μ passing through e . Suppose, without loss of generality, that the bend on e corresponds to a right turn along P uv while going from u to v. Since by hypothesis G μ is rectilinear planar, we can derive from H μ a different orthogonal representation H μ with b bends by simply moving the right bend from e to e, i.e., by inserting a right bend along e and by straightening the right bend of H μ along e . With this transformation, the number of right and left turns along P uv is the same in H μ and H μ , and the angles at u and v in the two representations are also the same. This implies that σ (H μ ) = σ (H μ ). By repeatedly applying this transformation on H μ until all the b bends of H μ are moved on e we get the desired representation H μ .
An illustration of Lemma 14 is given in Fig. 11. In Fig. 11a an orthogonal representation H μ of an S-component is shown. It has spirality 3 and 3 bends. In Fig. 11b a different orthogonal representation H μ of the same component is given, having the same spirality and number of bends as H μ , where all the bends are along an exposed edge.
Observe that, if ν is a P-node with three children, each of them has an exposed edge (as the poles of ν have degree at most four). If ν has two children, it might have a child without exposed edges only if ν is of type I 3ll or I 3rr (see Fig. 10). Section 6.1 and Sect. 6.2 focus on the budget of P-nodes with three children and on the budget of P-nodes with two children, respectively. Section 6.3 concentrates on the budget of the root.

Budget of P-Nodes with Three Children
Lemma 15 handles the case of a P-node ν with three children μ l , μ c , and μ r such that the corresponding components are rectilinear planar, while G ν is not The next lemma gives the rule for computing the budget of a P-node with three children and for determining the corresponding interval of spirality values, once a number of bends equal to the budget has been added. Proof Since by hypothesis G ν is not rectilinear planar, by the representability condition in Table 1

Lemma 15 Let ν be a P-node with three children μ l , μ c , and μ r . Let G μ l , G μ c , and G μ
We prove Property (i) and (ii) separately. Figure 12b provides an illustration for the graph in Fig. 12a, where x = c, y = l, and z = r .
Proof of Property (i). We show that b ν = m z − M x . Observe that each of the three components G μ l , G μ c , and G μ r is an S-component with an exposed edge.
We first prove that b ν bends are necessary. Suppose for a contradiction that G ν admits an orthogonal representation H ν with b ν < b ν bends. Denote by b x and b z the number of bends in the restriction of H ν to G μ x and to G μ z , respectively. By Lemma 14, we can assume that all the bends b x are along an exposed edge of G μ x and all the bends b z are along an exposed edge of G μ z . Consider the underlying graph G ν of H ν obtained by replacing each bend of H ν with a subdivision vertex. G ν is rectilinear planar. Denote by [m x , M x ] and [m z , M z ] the spirality intervals of G μ x and G μ z . Note that each subdivision vertex along an exposed edge of G μ x allows one more turn (either to the left or to the right) in a rectilinear planar representation of this component with respect to a rectilinear planar representation of G μ x . Hence, the spirality interval of G μ x extends the one of G μ x by b x units, both for the minimum value and for the maximum value. The same reasoning applies to G μ z . It follows that m x = m  Figure 13 illustrates this notation for the graph of Fig. 12a.
We now prove that b ν bends suffice. Let b x and b z be two non-negative integers   Fig. 12a on any exposed edge of G μ z . Clearly no subdivision vertex has been inserted on G μ y since b x + b z = b ν . Call G μ x , G μ y , and G μ z the resulting components (note that Consider the plane graph G ν obtained by the union of G μ x , G μ y , and G μ z . To prove that G ν is rectilinear planar, by the representability condition in Table 1 We have: Hence G ν has a rectilinear planar representation H ν ; replacing its subdivision vertices with bends, we get an orthogonal representation of G ν with b ν bends. Proof of Property (ii). We show that set I ν is an interval of feasible spirality values for the orthogonal representations of G ν with b ν bends. Namely, we show that any orthogonal representation H ν of G ν with b ν bends has spirality in the interval I ν and that for every value σ ν ∈ I ν there exists an orthogonal representation of G ν with spirality σ ν and b ν bends.
Suppose that G ν has an orthogonal representation H ν with b ν bends and let σ ν be the spirality of H ν . We prove that σ ν ∈ I ν = [max{M x , m y }, min{m z , M y }]. Let b l , b c , and b r be the number of bends in the restriction of H ν to G μ l , G μ C , and G μ r , respectively, where b l + b c + b r = b ν . Let H ν be the rectilinear planar representation obtained from H ν by replacing each bend with a subdivision vertex and let G ν be the underlying graph. Clearly the spirality of H ν equals σ ν . For any t ∈ {x, y, z}, by Lemma 14 we can assume that all the b t bends are along an exposed edge of G μ t and, consequently, σ μ t ∈ [m t − b t , M t + b t ]. By using the same notation as in the proof  Fig. 13). Since G ν is rectilinear planar, by Table 1 The remainder of the proof exploits the following claim. For an example see Fig. 12b, where every bend is regarded as a subdivision vertex, and where b y = 0, b x ≤ M y − M x = 2 − 0 = 2, and b z ≤ m z − m y = 2 + 6 = 8 in the three rectilinear representations of G ν . Claim 1 These relations hold: (1)

Claim Proof
We prove the three relations by contradiction.
We now consider spirality values of the components of H ν and define related values The values σ μ y and σ μ z are defined analogously. See Fig. 13 for an illustration of the notation σ μ t for t ∈ {x, y, z}. We have  Fig. 15 for an illustration of the argument that refines Fig. 14a).   Fig. 14b). In this case I ν = [M x , M y ]. By the same reasoning as in Case (a) we have [m y , It follows that [m y , Fig. 14d). In this case since M x ≥ m y and M y ≥ m z . Hence, Suppose now that we are given σ ν ∈ I ν = [max{M x , m y }, min{m z , M y }]. We show that there exists an orthogonal representation H ν of G ν with b ν bends and with spirality σ ν . This is equivalent to showing that there exists a plane graph G ν obtained by adding b ν subdivision vertices along some edges of G ν such that G ν has a rectilinear orthogonal representation with spirality σ ν . To construct G ν we insert a suitable number b z ∈ [0, b ν ] of subdivision vertices on an exposed edge of G μ z and b x = b ν − b z subdivision vertices on an exposed edge of G μ x (as a consequence, we do not insert any subdivision vertex in G μ y ). Let G μ x , G μ y , and G μ z be the resulting graphs. Since by hypothesis G μ x , G μ y , and G μ z are rectilinear planar, we have that also G μ x , G μ y , and G μ z are rectilinear planar. Also, with the same reasoning as in the proof of Property (i), the representability intervals of G μ x , G μ y , and For any t ∈ {x, y, z} we define m t , M t , and σ μ t as in the first part of the proof of Property (ii). We now describe how to compute b x and b z , and how to set σ μ x , σ μ y , and σ μ z . Let c 1 = max{M x , m y } and c 2 = min{m z , M y }.
We have: c 1 = m y and c 2 = M y in the case of Fig. 14a; c 1 = M x and c 2 = M y in the case of Fig. 14b; c 1 = m y and c 2 = m z in the case of Fig. 14c; c 1 = M x and c 2 = m z in the case of Fig. 14d.
Hence, it is possible to set σ μ y = σ ν . By Lemma 2 we can get a rectilinear planar representation H ν of G ν by a parallel composition of rectilinear planar representations of G μ x , G μ y , and G μ z with spirality values σ μ x , σ μ y , and σ μ z , respectively. By the same lemma, the spirality of H ν is σ ν = σ μ x = σ μ y = σ μ z = σ ν . By replacing the subdivision vertices of H ν with bends we get an orthogonal representation of G ν with b ν bends and spirality σ ν .

Budget of P-Nodes with Two Children
Let μ l and μ r be the two children of ν, and suppose that G μ l and G μ r are rectilinear planar with representability intervals I μ l = [m l , M l ] and I μ r = [m r , M r ], respectively. The representability condition for ν given in Table 1 is expressed in terms of the intersection between the interval [m l − M r , M l − m r ] and another interval ν that depends on the type of P-node. Specifically: if ν is of type I 3d O λβ ; and ν = [3,3] if ν is of type I 3dd . In the following, given two non-intersecting intervals of real numbers A 1 = [m 1 , M 1 ] and A 2 = [m 2 , M 2 ], the distance between A 1 and A 2 is defined as Section 6.2.1 handles the case of a P-node with two children both having an exposed egde. Section 6.2.2 handles the more involved cases in which either the left child or the right child of the P-node has no exposed edge. Note that, since the vertex-degree is at most four, at least one of the two children of the P-node must have an exposed edge. We start giving two simple combinatorial results (Lemmas 16 and 17), which will be used in the proof of Lemma 18. They provide some basic rules about the values that some terms of the relationships in Lemma 3 can take, depending on the type of P-nodes with two children.

Lemma 16
Let ν be a P-node of type I 2 O λβ with children μ l and μ r . Let G μ l and G μ r be rectilinear planar. For any rectilinear planar representation of G μ l and G μ r , and for any d ∈ {l, r }, the following relation holds: where both h and γ 2 are either integer or semi-integer numbers.

Lemma 17
Let ν be a P-node of type I 3 l O λβ with children μ l and μ r . Let G μ l and G μ r be rectilinear planar. For any rectilinear planar representation of G μ l and G μ r , the following relations hold: where both h l and γ 2 + 1 2 are either integer or semi-integer numbers.
where both h r and γ 2 + 1 are either integer or semi-integer numbers.

P-Nodes with Both Children Having an Exposed Edge
As mentioned at the beginning of Sect. 6, in the following we denote by m and M the minimum and the maximum values of the interval I ν as defined in Table 1. The next lemma gives the rule for computing the budget of a P-node with two children each having an exposed edge, and for determining the corresponding interval of spirality values.

Lemma 18
Let ν be a P-node with two children μ l and μ r , each having an exposed edge. Let G μ l and G μ r be rectilinear planar with representability intervals I μ l =  Figure 16 illustrates the statement for a P-node ν of type I 2 O 11 , by also showing how the interval I ν of Property (ii) is defined.
Proof of Property (i). We show that b ν = δ([m l − M r , M l − m r ], ν ). We first prove that b ν bends are necessary. Suppose for a contradiction that G ν admits an orthogonal representation H ν with b ν < b ν bends. Denote by b l and b r the number of bends in the restriction of H ν to G μ l and to G μ r , respectively. By Lemma 14, we can assume that all the bends b l (resp. b r ) are along an exposed edge of G μ l (resp. G μ r ). Consider the underlying graph G ν of H ν obtained by replacing each bend of H ν with a subdivision vertex. G ν is rectilinear planar. Also, each subdivision vertex along an exposed edge of G μ l allows one more turn (either to the left or to the right) in a rectilinear representation of this component, i.e., it extends the spirality interval of G μ l by one unit, both for the minimum value and for the maximum value. The same considerations happen for G μ r . Hence G μ l and G μ r are rectilinear planar with representability intervals [m l − b l , M l + b l ] and [m r − b r , M r + b r ], respectively, and the representability condition for We now prove that b ν bends suffice. Let b l and b r be two arbitrarily chosen nonnegative integers such that b l +b r = b ν . Insert b l (resp. b r ) subdivision vertices on any exposed edge of G μ l (resp. G μ r ). Call G μ l and G μ r the resulting components. Since by hypothesis G μ l and G μ r are rectilinear planar, with the same argument as above, G μ l and G μ r are both rectilinear planar with representability intervals [m l −b l , M l +b l ] and [m r − b r , M r + b r ], respectively. Consider the plane graph G ν obtained by the union of G μ l and G μ r . Since by hypothesis It follows that G ν admits a rectilinear planar representation H ν . By replacing the b ν subdivision vertices of H ν with bends, we get an orthogonal representation of G ν with b ν bends.
. For example, in Fig. 16 We represent G μ l with spirality σ μ l = M l +b l = M l +σ ν − M l +h = σ ν +c and G μ r with spirality , and by Lemma 7, G ν is rectilinear planar. It remains to show that G ν admits a rectilinear planar representation with spirality σ ν = σ ν . Given the choice of σ μ l and σ μ r , by Lemma 3 every rectilinear planar representation of G ν has spirality , by Lemma 16 there exists a value k l u α l u + k r u α l v such that h − k l u α l u − k r u α l v = 0, and thus σ ν = σ ν . For example, in Fig. 16, for every σ ν ∈ I ν = [−2, 3], there is a rectilinear representation of G ν with σ μ l − σ μ r = 2, b l and b r chosen as described above, and spirality σ ν .
and, by Lemma 7, G ν is rectilinear planar. It remains to show that G ν admits a rectilinear representation with spirality σ ν = σ ν . Given the choice of σ μ l and σ μ r , by Lemma 3 every rectilinear representation of G ν has spirality , by Lemma 16 we can set k l u α l u + k r u α l v = 2 − γ 2 , and thus σ ν = σ ν .
Case I 3d O λβ and Case I 3dd : see "Appendix C".

P-Nodes Having a Child with No Exposed Edges
We now consider the case of a P-node ν having a child that does not contain an exposed edge (see Lemmas 20 and 21). Denote by μ such a child node; observe that μ is an S-node whose children ν 1 , ν 2 , . . . , ν h (h ≥ 2) (e.g., ordered from the bottom pole to the top pole of μ) are all P-nodes of type I 2 O 22 . This is because, if one ν i among ν 2 , . . . , ν h−1 had a pole of outdegree one, then the external edge of G ν i incident to this pole would be part of a Q * -node child of μ, thus contradicting the fact that μ has no exposed edges; also, the bottom pole of ν 1 (resp. of ν h ) coincides with the bottom pole (resp. top pole) of ν, and has outdegree two in G ν 1 (resp. in G ν h ). For a given integer value b ≥ 0, denote by σ max ν i (b) the maximum value of spirality that any orthogonal representation of G ν i with at most b bends can have (i ∈ {1, . . . , h}). When we consider the value b + 1, the value σ max ν i (b + 1) may or may not increase by one unit with respect to σ max ν i (b), i.e., either σ max . By plotting the function σ max ν i (b) as b increases, we define the positive flexibility breakpoint of G ν i as the maximum number of bends b + ν i such that for every non-negative integer Fig. 17 shows a component G ν i and a plot of the function σ max ν i (b) for b = 0, 1, . . . , 5. In the figure, the positive flexibility breakpoint is b + ν i = 3 because passing from b = 3 to b = 4 does not allow us to have an orthogonal representation of G ν i with a larger value of spirality. The positive flexibility breakpoint of the S-node μ is denoted as b + μ and it is defined as the sum of the positive flexibility breakpoints of its children, i.e., b + μ = h i=1 b + ν i . Symmetrically, for a given integer b ≥ 0, let σ min ν i (b) be the minimum value of spirality that an orthogonal representation of G ν i with at most b bends can have (i ∈ {1, . . . , h}). The value of σ min ν i (b + 1) may or may not decrease by one unit with respect to σ min ν i (b). We define the negative flexibility breakpoint of G ν i as the maximum number of bends b − ν i such that for every non-negative Fig. 18 shows the same component G ν i as in Fig. 17

Lemma 19
Let ν i be a P-node of type I 2 O 22 with children μ l and μ r such that G ν i is rectilinear planar. Let I μ l = [m l , M l ] and I μ r = [m r , M r ] be the representability intervals of G μ l and G μ r , respectively. We have b + ν i = |M r + 2 − M l | and b − ν i = |m l − 2 − m r |. Also, an orthogonal representation of G ν i with spirality σ max can be obtained by inserting all the bends on an exposed edge of either G μ l or G μ r . Table 1 is σ max ν i (0) = min{M l − 1, M r + 1}. Let σ μ l and σ μ r be the spirality values of the left and the right orthogonal components of H ν i , respectively. By Lemma 7, we know that σ μ l − σ μ r = 2. Also, by Lemma 3, σ max ν i (0) = σ μ l − 1 = σ μ r + 1. By Table 1, either σ μ l = M l or σ μ r = M r (possibly both). Three cases are possible: • σ μ l = M l and σ μ r = M r . Note that, since σ μ l = σ μ r + 2, in this case we have |M r + 2 − M l | = 0. We show that if we are allowed to subdivide an edge of G ν i with exactly one degree-2 vertex, so to obtain a graph G ν i , the maximum value of spirality that a rectilinear planar representation H ν i of G ν i equals σ max ν i (0). In other words, we show that σ max ν i (1) = σ max ν i (0). By Lemma 14, we can assume that the degree-2 vertex subdivides an exposed edge, which belongs either to G μ l or to G μ r . Suppose that this degree-2 vertex is inserted along an exposed edge of G μ l . Denote by G μ l and G μ r the left component and the right component of G ν i , respectively. The maximum spirality of a rectilinear planar representation of G μ l is M l + 1, while the maximum spirality of a rectilinear planar representation of G μ r remains M r , because G μ r coincides with G μ r . Assume for a contradiction that G ν i admits a rectilinear planar representation H ν i with spirality σ max ν i (0) + 1, and denote by σ μ l and σ μ r the spirality values of the left and right components of , which implies that G μ r should have a rectilinear planar representation with spirality M r + 1, a contradiction. A symmetric argument applies if we subdivide an exposed edge of G μ r . Hence, b + ν i = 0 = |M r + 2 − M l |. • σ μ l = M l and σ μ r < M r . Subdivide an exposed edge of G ν l with a degree 2vertex, and call G ν i the graph resulting from G ν i after this subdivision. As in the previous case, denote by G μ l and G μ r the left and the right components of G ν i , where G μ r coincides with G μ r . We show that G ν i admits a rectilinear planar representation with spirality σ ν = σ max ν i (0)+1. Since we have added a subdivision vertex on an exposed edge of G μ l , there exists a rectilinear planar representation H μ l of G μ l with spirality σ μ l = M l + 1. Also, since σ μ r < M r , there exists a rectilinear planar representation of G μ r with spirality σ μ r = σ μ r + 1. Hence, σ μ l − σ μ r = 2 and therefore, by Lemma 7, we can merge the representations H μ l and H μ r into a rectilinear planar representation H ν i of G ν i . The spirality of H ν i is σ ν i = σ max ν i (0) + 1. By replacing the subdivision vertex of H μ l with a bend, we get an orthogonal representation of G ν i with one bend and with spirality σ max ν i (0) + 1, i.e., σ max ν i (1) = σ max ν i (0)+1. Iterate this procedure until σ μ r = M r , i.e., until σ ν i = M r +1. Denote by b the number of bends added in total. By Lemma 3, the spirality of the resulting orthogonal representation is σ max ν i (b) = M l + b − 1 = M r + 1, and hence b = M r +2− M l . If we consider the rectilinear representation H ν i where the b bends are replaced with degree-2 vertices, its left and right components have the maximum possible spirality in their representability intervals. Hence, the previous case applies, and inserting exactly one subdivision vertex to G ν i does not result into a graph that admits a rectilinear planar representation with spirality greater than the one of H ν i . It follows that b + ν i = M r + 2 − M l . • σ μ l < M l and σ μ r = M r . With a symmetric argument as in the previous case, The next lemma gives the rule for computing the budget of a P-node with two children such that the left one has no exposed edge, and for determining the corresponding interval of spirality values.

Lemma 20
Let ν be a P-node with two children μ l and μ r , such that μ l has no exposed edge. Let G μ l and G μ r be rectilinear planar with representability intervals I μ l = [m l , M l ] and I μ r = [m r , M r ], respectively. If G ν is not rectilinear planar [3,3]); and (ii) the interval obtained from G μ l by regarding each bend as a subdivision vertex admits a rectilinear planar representation H μ l with spirality σ μ l = M l + b l = M l + σ ν − M l + 1 = σ ν + 1. We now place b r bends along an exposed edge of G μ r . The graph G μ r obtained from G μ r by regarding each bend as a subdivision vertex admits a rectilinear planar representation H μ r with spirality It follows that σ μ l − σ μ r = σ ν + 1 − (σ ν − 2) = 3 and, by Lemma 11, G ν is rectilinear planar and it admits a rectilinear planar representation H ν obtained by combining in parallel H μ l and H μ r . By Lemma 3, H ν has spirality σ ν = σ μ l −k l u α l u −k l u α l v . Since u and v have degree four, we have α l u = α l v = α r u = α r v = 1. Also, by Table 2, k l u = k r u = 1 2 . Hence, σ ν = σ ν + 1 − 1 = σ ν . Replacing the subdivision vertices of H ν with bends we get an orthogonal representation of G ν with b ν bends and spirality σ ν .
The proof of Lemma 21 considers the case where the right child of a P-node with two children has no exposed edge. The proof is symmetric to that of Lemma 20, hence it is omitted.

Lemma 21
Let ν be a P-node with two children μ l and μ r , such that μ r has no exposed edge. Let G μ l and G μ r be rectilinear planar with representability intervals I μ l = [m l , M l ] and I μ r = [m r , M r ], respectively. If G ν is not rectilinear planar, then: [3,3]

Budget of the Root
We finally show how to compute the budget of the root ρ of T . Recall that ρ is the P r -node describing the parallel composition of the reference edge e = (u, v) with the rest of the graph. If e is a dummy edge, the budget of ρ is zero, because e does not need to be drawn. Thus we assume that the graph is biconnected and e is a real edge. Let η be the child of ρ that does not correspond to e, and let u and v be the alias vertices associated with the poles u and v of G η . If G η is rectilinear planar with representability interval I η , by the root condition in Table 1 we know that G is rectilinear planar if and only if I η ∩ ρ = ∅. Recall that ρ is defined as follows: (i) ρ = [2,6] if u coincides with u and v coincides with v; (ii) ρ = [3,5] if exactly one of u and v coincides with u and v, respectively; (iii) ρ = 4 if none of u and v coincides with u and v. We prove the following.

Lemma 22
Let e = (u, v) be the reference edge of G and let ρ be the root of T with respect to e. Let η be the child of ρ that does not correspond to e. Suppose that G η is rectilinear planar with representability interval I η . If G is not rectilinear planar then b ρ = δ(I η , ρ ).
Proof See Fig. 19 for an illustration of the statement.
Let f int be the internal face of G incident to e. Note that H is an orthogonal representation of G if and only if the following two conditions hold: the restriction H η of H to G η is an orthogonal representation; the number A of right turns minus left turns of any simple cycle of G in H containing e and traversed clockwise in H is equal to 4. We have A = σ η − σ e + α u + α v , where: σ η is the spirality of H η ; σ e is the spirality of e; for w ∈ {u , v }, α w = 1, α w = 0, and α w = −1 if the angle formed by w in f int equals 90 o , 180 o , or 270 o , respectively.
Since G is not rectilinear planar, H must contain some bends. Denote by b the number of bends of H . Each of these b bends placed along an edge of G η contributes to increase or decrease σ η by at most one unit, therefore increasing or decreasing A by at most one unit. Also placing this bend along e contributes to increase or decrease A by at most one unit. Hence, without loss of generality, we can assume that all the b bends are placed along e, which implies that H η does not contain any bend. It follows that σ η ∈ I η = [m η , M η ] and σ e ∈ [−b, b]. We now show that if b is the minimum value such that A = 4 then b = b ρ . Observe that when b is minimum, we have |σ e | = b, and therefore |σ e | > 0.

Optimality of the Approach
Our bottom-up algorithm incrementally computes for each node ν of T the budget of bends needed to realize an orthogonal representation of G ν . We prove that, the total budget at the level of the root of T corresponds to the number of bends of a bend-minimum orthogonal representation of G. More formally, for a node ν of T , the cumulative budget B ν of ν is the sum of the budgets of all nodes in the subtree of T rooted at ν. If ν is a leaf of T , B ν = b ν = 0. If ν is an internal node with children  Table 3 Summary of how to compute b ν and I ν for the different types of nodes ν. In the formulas, we have γ = λ + β − 2 and φ(·) is such that φ(r ) = 1 and φ(l) = 0. Values m and M are computed as shown in Table 1 P-node with two children, each having an exposed edge-Lemma 18 P-node with three children (each child has an exposed edge)-Lemma 15  Proof We prove that once the algorithm has processed a node ν in the bottom-up visit, the cumulative budget B ν equals the number of bends of a bend-minimum orthogonal representation of G ν . This implies that once the algorithm has visited the root ρ of T , the cumulative budget B ρ equals the number of bends of a bend-minimum orthogonal representation of G ρ = G. The proof is by induction on the depth of the subtree of T rooted at ν. Base Case. For a leaf ν of T (ν is a Q * -node), the statement is trivial, as B ν = 0. Inductive Case. Let ν be a node of T that is not a leaf. Denote by μ 1 , μ 2 , . . . , μ h the children of ν. By the inductive hypothesis, each B μ i (i = 1, . . . , h) corresponds to the number of bends of a bend-minimum representation of G μ i . By definition, where b ν is the minimum number of bends that must be used in addition to i=1,...,h B μ i to realize an orthogonal representation of G ν (b ν = 0 if ν is an S-node). Budget B ν corresponds to the minimum number of bends of any orthogonal representation H ν of G ν with the property that the number of bends b(

Bend-Minimization in Linear Time
The bottom-up visit described above, equips each node ν of T with three information: the budget b ν , the cumulative budget B ν , and, if ν = ρ, an interval I ν = [m ν , M ν ] of all possible spirality values that an orthogonal representation of G ν with B ν bends can have. Once the bottom-up visit of T has been completed, our algorithm performs a top-down visit of T to suitably add to G a number B ρ of subdivision vertices, so that the resulting graph G admits a rectilinear planar representation. At the beginning of the top-down visit, the root ρ is considered. Let η be the child of ρ that does not correspond to e. If I η ∩ ρ = ∅, the algorithm selects an arbitrary value σ η ∈ I η ∩ ρ as target spirality value for a representation of G η within a rectilinear planar representation of G . If, vice versa, I η ∩ ρ = ∅, according to the proof of Lemma 22, the algorithm subdivides e with b e = δ(I η , ρ ) bends and sets the target spirality value σ η as either σ η = M η (if M η is smaller than the infimum of ρ ) or σ η = m η (if m η is larger than the supremum of ρ ). In the next step of the top-down visit, the algorithm considers node η, for which the target spirality value σ η has been previously fixed. If η is an S-node then b η = 0, i.e., no subdivision vertices must be added in this step. If η is a P-node and b η > 0, the algorithm suitably adds b η subdivision vertices along some edges of G η . To do so, it applies the procedures described in the second part of the proof of Property (ii) of Lemma 15, of Lemma 18, or of Lemmas 20 and 21, depending on whether η is a P-node with three children, a P-node with two children both having an exposed edge, or a P-node with two children one of which has no exposed edge. Then, the algorithm sets the spirality values for each child of η. Namely, we distinguish the following cases: Case 1: η is an S-node, with children μ 1 , . . . , μ h (i ∈ {1, . . . , h}). Let I μ i = [m i , M i ] be the representability interval of μ i (assuming that any orthogonal representation of G μ i will have B ν i bends). We must find a value σ μ i ∈ [m i , M i ] for each i = 1, . . . , h such that h i=i σ μ i = σ η . To this aim, initially set σ μ i = M i for each i = 1, . . . , h and consider s = ( h i=i σ μ i ) − σ η . By Lemma 1, s ≥ 0. If s = 0 we are done. Otherwise, iterate over all i = 1, . . . , h and for each i decrease both σ μ i and s by the value min{s, M i − m i }, until s = 0. Case 2: η is a P-node with three children, μ l , μ c , and μ r . By Lemma 2, it suffices to set σ μ l = σ η + 2, σ μ c = σ η , and σ μ r = σ η − 2. Case 3: η is a P-node with two children, μ l and μ r . Let u and v be the poles of η. By Lemma 3, σ μ l and σ μ r must be determined in such a way that σ μ l = σ η + k l The values of k l u , k l v , k r u , k r v are fixed by the indegree and outdegree of u and v. Hence, it suffices to choose the values of α l u , α l v , α r u , α r v such that they are consistent with the type of η and yield σ μ l ∈ I μ l and σ μ r ∈ I μ r . Since each α d w (w ∈ {u, v}, d ∈ {l, r }) is either 0 or 1, there are at most four combinations of values to consider. Case 4: η is a Q * -node. In this case the algorithm does nothing, as no further subdivision vertices must be added. In the subsequent steps of the top-down visit, for every node ν the algorithm applies the same procedure as for η to determine a target spirality value σ ν and to suitably distribute the b ν subdivision vertices along the edges of G ν .

Theorem 4 Let G be an n-vertex plane series-parallel 4-graph. There exists an O(n)time algorithm that computes a bend-minimum orthogonal representation of G.
Proof If G is biconnected let e be any edge of G on the external face; otherwise, let e be a dummy edge added on the external face to make G biconnected. Let T be an SPQ * -tree of G with respect to e. The algorithm executes the bottom-up and the top-down visits described above. Once the top-down visit is completed and B ρ subdivision vertices have been suitably inserted in G, a rectilinear planar representation of the subdivision of G is easily computed from the spirality values of each component and from the values of the angles at the poles of each component. From this representation we obtain a bend-minimum orthogonal representation of G by replacing the subdivision vertices with bends. Since the obtained orthogonal representation has B ρ bends, by Theorem 3 it has the minimum number of bends.
We now analyze the time complexity of the algorithm. T can be computed in O(n) time and it consists of O(n) nodes [4]. For a node ν of T that is not a Q * -node, we denote by n ν the number of children of ν.
Consider first the bottom-up visit. Let ν be a visited node of T . If ν is a Q * -node then b ν = 0 and, by Table 1, I ν = I ν is computed in O(1) time (we can assume that the length of the chain of edges represented by ν is stored at ν during the construction of T ). If ν is an S-node, we still have b ν = 0 and, by Table 1, I ν = I ν is computed in O(n ν ) time. If ν is a P-node with three children, by Lemma 15 b ν and I ν are computed in O(1) time. If ν is a P-node with two children each having an exposed edge, by Lemma 18 b ν and I ν are computed in O(1) time. Suppose now that ν is a P-node with an S-node child that has no exposed edge, and assume that this S-node is the left child μ l of ν. By Lemma 20, b ν and I ν can be computed in O(1) time if we know the flexibility breakpoints (positive and negative) of μ l . By Lemma 19, the flexibility breakpoints of μ l can be computed in O(n μ l ) time. By Lemma 21, the same reasoning applies if the right child of ν is an S-node with no exposed edge. Finally, if ν coincides with the root ρ of T , by Lemma  In the top-down visit, for every non-leaf node ν of T , the algorithm spends O(b ν ) time to add b ν subdivision vertices. Also, we should consider the extra time t required to decide what are the edges along which these bends must be added and what is the target spirality value for each child of ν. Namely, if ν is the root, t = O(1). If ν is an S-node, t = O(n ν ) by Case 1 of the top-down visit described above. If ν is a P-node with three children, by Case 2 of the top-down visit and by Lemma 15, t = O(1). If ν is a P-node with two children each having an exposed edge, by Case 3 of the top-down visit and by Lemma 18, t = O (1). Finally, if ν is a P-node with two children, one of which is an S-node μ with no exposed edge, by Case 3 and by Lemmas 20 and 21, t = O(n μ ). Hence, since B ρ = ν b ν = O(n) [21], the top-down visit takes O(n) overall time, and a rectilinear planar representation of the subdivision of G is easily computed in O(n) time from the spirality values of each component and from the values of the angles at the poles of each component.

Conclusions and Open Problems
We proved that there exists an optimal linear-time algorithm that computes a bendminimum orthogonal drawing of a plane series-parallel 4-graph; this result solves, for a popular and widely studied family of plane graphs, a question opened for over 30 years, thus shedding new light on the complexity of computing orthogonal drawings of plane graphs with the minimum number of bends. It is also worth remarking that, despite the sophisticated analysis and key ingredients needed to prove our main theorem, the resulting bend-minimization algorithm is relatively easy to implement, as at every node of the SPQ * -tree it just requires to apply some simple formulas, as summarized in Tables 1 and 3. We conclude by suggesting two open problems: -Problem 1. Our result holds for the series-parallel graphs that are also called two-terminal, which are either biconnected or which can be made biconnected with the addition of a single edge. Can we extend Theorem 4 to 1-connected plane 4-graphs whose biconnected components are two-terminal series-parallel graphs, also known as partial 2-trees? Here the main difficulty of extending our approach is to succinctly describe the possible spirality values for those components that contain cut-vertices. In fact, a cut-vertex requires the imposition of some constraints at its angles, in order to correctly compose the different biconnected components that contain it. These constraints forbid some vertex angles, and in turns some spirality values that an orthogonal representation can take.
-Problem 2. Is it possible to find a linear-time algorithm for the bend-minimization problem of triconnected plane 4-graphs? A positive answer to this question, together with our result, could be used to solve the problem of computing a bendminimum orthogonal drawing of a general plane 4-graph in linear time.
Funding Open access funding provided by Università degli Studi di Perugia within the CRUI-CARE Agreement.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.

A Analysis of the Missing Cases in the Proof of Theorem 1
Case 4: indeg ν (u) > 1 and indeg ν (v) > 1. We analyze the three non-symmetric subcases, depending on the outdegree of u and of v, i.e., outdeg ν (u) = outdeg ν (v) = 1, or outdeg ν (u) = 1 and outdeg ν (v) = 2 (symmetrically outdeg ν (u) = 2 and outdeg ν (v) = 1), or outdeg ν (u) = outdeg ν (v) = 2. In all these cases, for a pole w ∈ {u, v}, the angles defined by Sub(H ν , H ν ) around w in H are the same as in H (note that if outdeg ν (w) = 2, the angles at w are all right angles, and they coincide both in H and H ). Hence, Property (H1) holds for u and v in H . About Property (H2), we analyze the different subcases separately: • outdeg ν (u) = outdeg ν (v) = 1 (see Fig. 5a). Each of the two poles u and v has a single alias vertex, denoted as u and v , respectively. Let P l (resp. P r ) be the path of H obtained by concatenating p l (resp. p r ) with the segments u u and vv . Analogously, let P l (resp. P r ) be the path of H obtained by concatenating p l (resp. p r ) with the segments u u and vv . Using the same notation as in the previous cases, we have σ (H ν ) = n(P l ) = n(P r ) and σ (H ν ) = n(P l ) = n(P r ). Hence, since σ (H ν ) = σ (H ν ), we have n(P l ) = n(P r ) = n(P l ) = n(P r ), which implies that Hence, Property (H2) holds for f l and f r . • outdeg ν (u) = 1 and outdeg ν (v) = 2 (see Fig. 5b). The pole u has a single alias vertex u , while v has two alias vertices v and v . Let P l (resp. P r ) be the path of H obtained by concatenating p l (resp. p r ) with the segments u u and vv (resp. vv ). Analogously, let P l (resp. P r ) be the path of H obtained by concatenating p l (resp. p r ) with the segments u u and vv (resp. vv ). Since σ (H ν ) = σ (H ν ), we have n(P l )+n(P r ) 2 = n(P l )+n(P r ) 2 . Also, since all the angles at v are right angles, we have n(P r ) = n(P l ) + 1 and n(P r ) = n(P l ) + 1, which implies n(P l ) = n(P l ) and n(P r ) = n(P r ). • outdeg ν (u) = outdeg ν (v) = 2 (see Fig. 5c). Each of the two poles u and v has two alias vertices, denoted as {u , u } and {v , v }, respectively. Let P l (resp. P r ) be the path of H obtained by concatenating p l (resp. p r ) with the segments u u and vv (resp. u u and vv ). Analogously, let P l (resp. P r ) be the path of H resulting from the concatenation of p l (resp. p r ) with the segments u u and vv (resp. u u and vv ). Since σ (H ν ) = σ (H ν ), we have n(P l )+n(P r ) 2 = n(P l )+n(P r ) 2 . Also, since all the angles at u and v are right angles, we have n(P r ) = n(P l ) + 2 and n(P r ) = n(P l ) + 2. This implies that n(P l ) = n(P l ) and n(P r ) = n(P r ), which in turns implies that  Series-parallel graph A graph obtained in an inductive way by means of series-and parallel-compositions SPQ * -tree Rooted tree whose nodes describe the structure of a series-parallel graph in terms of its series-and parallel-compositions S-node Node of an SPQ * -tree associated with a series-composition that is not a chain of edges Table 5 continued Terminology Short description P-node Node of an SPQ * -tree associated with a parallel-composition Q * -node Leaf of an SPQ * -tree, associated with either an edge or a chain of edges Representability interval of a node ν Interval of the spirality values that a rectilinear representation of G ν can take Exposed edge For a child μ of a P-node, if μ is a Q * -node then all the edges of μ are exposed edges; if μ is an S-node, the exposed edges of μ are those corresponding to leaf-children of μ, if any 1 Department of Engineering, University of Perugia, Perugia, Italy 2 University of Tübingen, Tübingen, Germany