1 Introduction

Orthogonal drawings of planar graphs represent a foundational graph drawing paradigm [5, 6, 23] and an active field of research [8, 10, 13, 15]. Given a planar 4-graph G, i.e., a planar graph of vertex-degree at most 4, a planar orthogonal drawing \(\Gamma \) of G is a planar drawing that maps the vertices of G to distinct points of the plane and each edge of G to a chain of horizontal and vertical segments connecting the two endpoints of the edge. A bend of \(\Gamma \) is the meeting point of two consecutive segments along the same edge. Given a graph G and \(b \in \mathbb {N}\), the \(b\)-Orthogonal Planarity problem asks for the existence of an orthogonal drawing of G with at most b bends in total. While every n-vertex planar 4-graph admits an orthogonal drawing with O(n) bends [1], \(b\)-Orthogonal Planarity is well-known to be NP-complete already when \(b=0\) [18]. In this case, the \(b\)-Orthogonal Planarity problem is also known in the literature as Rectlinear Planarity. It is even NP-hard to approximate the minimum number of bends in an orthogonal drawing with an \(O(n^{1-\varepsilon })\) error for any \(\varepsilon > 0\) [18].

From a parameterized complexity perspective, the hardness of Rectlinear Planarity rules out the possibility of finding a tractable solution for \(b\)-Orthogonal Planarity parameterized solely by the number of bends. On the positive side, a recent result of Di Giacomo et al. [8] shows that \(b\)-Orthogonal Planarity lies in the XP class when parameterized by the treewidth \(\textsf{tw}\) of the input graph. In fact, the result in [8] is based on a fixed-parameter tractable algorithm in the parameter \(b+k+\textsf{tw}\), where k is the number of vertices of degree at most two. A natural question is thus whether a subset of these three parameters suffices to establish tractability, as asked in [8]. We also remark that, in a recent Dagstuhl seminar on parameterized complexity in graph drawing [16, pag. 94], understanding whether Rectlinear Planarity is in FPT parameterized by only one of k and \(\textsf{tw}\) was identified as a prominent challenge. Very recently, Jansen et al. [21, 22] proved that Rectlinear Planarity parameterized by \(\textsf{tw}\) is W[1]-hard (hence the same holds for \(b\)-Orthogonal Planarity parameterized by \(b+\textsf{tw}\)).

Fig. 1
figure 1

The complexity landscape of the \(b\)-Orthogonal Planarity problem when parameterized by any subset of b, k, and \(\textsf{tw}\). The results presented in this paper are show with a larger circle

Contribution. We address the questions posed in [8, 16] and, as our main result, we prove that \(b\)-Orthogonal Planarity is fixed-parameter tractable parameterized by \(b+k\), hence dropping the dependency on \(\textsf{tw}\). Consequently, Rectlinear Planarity is in FPT when parameterized by k alone. Furtheremore, by extending the result in [21, 22] to graphs with no vertices of degree smaller than three, we also prove that \(b\)-Orthogonal Planarity is NP-hard when \(k=0\) and that it is W[1]-hard parameterized by \(k+\textsf{tw}\). As a consequence, we are able to trace a clear tractability landscape for the \(b\)-Orthogonal Planarity problem with respect to the three parameters k, b and \(\textsf{tw}\), as shown in Fig. 1 (in which our results are represented with larger circles).

From a technical point of view, the algorithm by Di Giacomo et al. [8] exploits treewidth to apply dynamic programming. The crux of that algorithm lies on two main ingredients. First, a fixed treewidth (and fixed vertex-degree) bounds the number of interesting embeddings in which different faces have vertices in the current bag. Second, a classic result by Tamassia [24] states that the existence of an orthogonal drawing is equivalent to the existence of a combinatorial representation describing the angles at the vertices and the bends along the edges. In this respect, a fixed number of bends and of vertices of degree at most two bounds the possible combinatorial descriptions of a face, and hence it makes the definition of small records feasible for the sake of dynamic programming. To avoid the dependency on the treewidth and prove our main result, we exploit additional insights into the structure of the problem. First, we adopt SPQ\(^*\)R-trees to decompose the input graph and to keep track of its possible planar embeddings. While it was already known how to deal with S- and P-nodes efficiently by exploiting dynamic programming on SPQ\(^*\)R-trees [6, 11], the main obstacle is represented by R-nodes, i.e., the rigid components of the graph. To overcome this obstacle, we first prove that the number of children of an R-node depends on the number of degree-2 vertices plus the number of bends. Then, we carefully combine flow-network based techniques [24] for planar embedded graphs with the notion of orthogonal spirality [6], which measures how much a component of an orthogonal drawing is “rolled-up”.

Paper organization. Section 2 contains preliminaries and basic tools that will be used throughout the paper. Sections 3 and 4 describe our FPT algorithm. Namely, in Sect. 3 we deal with biconnected graphs, which represent the main obstacle for our algorithm, and for which we exploit an SPQ\(^*\)R-tree decomposition. Next, in Sect. 4, we extend the result to simply connected graphs. In Sect. 5 we show that \(b\)-Orthogonal Planarity is para-NP-hard when parameterized by k and W[1]-hard when parameterized by \(k+\textsf{tw}\). Section 6 concludes the paper with some open problems that stem from our research.

2 Preliminaries

For a graph G, we denote by V(G) and by E(G) the set of vertices and the set of edges of G, respectively. We consider planar 4-graphs, i.e., graphs with vertex-degree at most 4. A plane graph is a planar graph with a fixed planar embedding, i.e., prescribed clockwise orderings of the edges around the vertices and prescribed external face.

Orthogonal Representations. A planar orthogonal representation H of a planar graph G describes the shape of a class of orthogonal drawings in terms of left/right bends along the edges and angles at the vertices. A drawing \(\Gamma \) of H (i.e., a planar orthogonal drawing of G that preserves H) can be computed in linear time [24]. If H has no bends, it is a rectilinear representation. Since we only deal with planar drawings, we just use the term rectilinear (orthogonal) representation in place of planar rectilinear (orthogonal) representation.

Let G be a plane graph and let \(n = |V(G) |\). In [24], it is proved that a bend-minimum orthogonal representation of G can be constructed in \(O(n^2 \log n)\) time by finding a min-cost flow on a suitable flow-network constructed from the planar embedding of G. The feasible flows on this network correspond to the possible orthogonal representations of the graph, and the total cost of the flow equals the number of bends of the corresponding representation. Fixing the values of the flow along some arcs of the network, one can force desired vertex-angles or left/right bends along the edges in the corresponding orthogonal representation. The time complexity in [24] has been subsequently improved to \(O(n^\frac{7}{4}\sqrt{\log n})\) [17] time, and later to \(O(n^\frac{3}{2})\) [4] if there is no constraints on the orthogonal representation and one can use a flow-network whose arcs all have infinite capacities.

Let \(H'\) be an orthogonal representation of a (not necessarily connected) subgraph \(G'\) of G. An orthogonal representation H of G is \(H'\)-constrained if its restriction to \(G'\) equals \(H'\). By the considerations above, the following immediately holds.

Lemma 1

Let G be an n-vertex plane 4-graph and let \(H'\) be an orthogonal representation of a subgraph \(G'\) of G. There exists an \(O(n^\frac{7}{4}\sqrt{\log n})\)-time algorithm that computes an \(H'\)-constrained orthogonal representation of G with the minimum number of bends, if it exists, or that rejects the instance otherwise.

SPQR-trees. Let G be a biconnected planar graph. The SPQR-tree T of G, introduced in [5], represents the decomposition of G into its triconnected components [20]. Each triconnected component corresponds to a non-leaf node \(\nu \) of T; the triconnected component itself is called the skeleton of \(\nu \) and is denoted as \(\textrm{skel} (\nu )\). Node \(\nu \) can be: (i) an R-node, if \(\textrm{skel} (\nu )\) is a triconnected graph; (ii) an S-node, if \(\textrm{skel} (\nu )\) is a simple cycle of length at least three; (iii) a P-node, if \(\textrm{skel} (\nu )\) is a bundle of at least three parallel edges. A degree-1 node of T is a Q-node and represents a single edge of G. A real edge (resp. virtual edge) in \(\textrm{skel} (\nu )\) corresponds to a Q-node (resp., to an S-, P-, or R-node) adjacent to \(\nu \) in T. Neither two S- nor two P-nodes are adjacent in T. The SPQR-tree of a biconnected graph can be computed in linear time [5, 19].

Let e be a designated edge of G, called the reference edge of G, let \(\rho \) be the Q-node of T corresponding to e, and let T be rooted at \(\rho \). For any P-, S-, or R-node \(\nu \) of T, \(\textrm{skel} (\nu )\) has a virtual edge, called reference edge of \(\textrm{skel} (\nu )\) and of \(\nu \), associated with a virtual edge in the skeleton of its parent. The reference edge of the root child of T is the edge corresponding to \(\rho \). The rooted tree T describes all planar embeddings of G with its reference edge on the external face; they are obtained by combining the different planar embeddings of the skeletons of P- and R-nodes with their reference edges on the external face. Namely, for a P- or R-node \(\nu \), denote by \(\textrm{skel} ^-(\nu )\) the skeleton of \(\nu \) without its reference edge. If \(\nu \) is a P-node, the embeddings of \(\textrm{skel} (\nu )\) are the different permutations of the edges of \(\textrm{skel} ^-(\nu )\); If \(\nu \) is an R-node, \(\textrm{skel} (\nu )\) has two possible embeddings, obtained by flipping \(\textrm{skel} ^-(\nu )\) at its poles. For every node \(\nu \ne \rho \), the pertinent graph \(G_\nu \) of \(\nu \) is the subgraph of G whose edges correspond to the Q-nodes in the subtree of T rooted at \(\nu \). We also say that \(G_\nu \) is a component of G. The pertinent graph \(G_\rho \) of the root \(\rho \) coincides with the reference edge of G. If H is an orthogonal representation of G, its restriction \(H_\nu \) to \(G_\nu \) is an orthogonal component of H.

3 The Biconnected Case

In this section we assume that G is a biconnected graph with k degree-2 vertices. Similar to previous works [6, 10, 11, 14], our approach exploits a variant of SPQR-tree, called SPQ \(^*\) R-tree, and the notion of spirality for orthogonal components. We recall below these two concepts; see Fig. 2 for an illustration.

Fig. 2
figure 2

a A biconnected planar graph G. b The SPQ\(^*\)R-tree of G rooted at the Q\(^*\)-node of the chain (1, 13, 14, 15). The skeletons of three nodes are shown; the virtual edges are dashed and the reference edge is thicker

SPQ \(^*\) R-trees. Assume that G is not a simple cycle (otherwise computing a bend-minimum orthogonal representation of G is trivial). In an SPQ\(^*\)R-tree of G we do not distinguish between Q-nodes and series of edges, and represent both of them with a type of node called Q \(^*\)-node. More precisely, each degree-1 node of T is a Q\(^*\)-node that corresponds to a maximal chain of edges of G (possibly a single edge) starting and ending at vertices of degree larger than two and passing through a sequence of degree-2 vertices only (possibly none). If \(\nu \) is an S-, a P-, or an R-node, and if \(\mu \) is a Q\(^*\)-node child of \(\nu \), the edge of \(\textrm{skel} (\nu )\) corresponding to \(\mu \) is virtual if \(\mu \) corresponds to a chain of at least two edges, else it is a real edge. If T is rooted at a certain Q\(^*\)-node \(\rho \), the chain corresponding to \(\rho \) is the reference chain of G. The definitions of pertinent graphs (or components) for the nodes of a rooted SPQ\(^*\)R-tree extend naturally from those of a rooted SPQR-tree. In particular \(G_\rho \) is the pertinent graph of \(\rho \), i.e., the reference chain of G. Moreover, as in [3, 6, 9,10,11,12, 14], we assume to work with a normalized SPQ\(^*\)R-tree, in which every S-node has exactly two children. Note that every SPQ\(^*\)R-tree can be easily transformed into a normalized SPQ\(^*\)R-tree by recursively splitting an S-node with more than two children into multiple S-nodes with two children. Observe that in this case an S-node may have an S-node as a child. If \(|V(G) |=n\), a normalized SPQ\(^*\)R-tree of G still has O(n) nodes and can be easily computed in O(n) time from an SPQ\(^*\)R-tree of G.

Orthogonal Spirality. Let H be an orthogonal representation of G. If \(P^{uv}\) is a path from a vertex u to a vertex v in H, the turn number of \(P^{uv}\), denoted by \(n(P^{uv})\), is the number of right turns minus the number of left turns along \(P^{uv}\), while moving from u to v. Note that a turn can occur at either a bend or a vertex. Let T be a rooted normalized SPQ\(^*\)R-tree of G and let \(\nu \) be a node of T. Let \(H_\nu \) be the restriction of H to \(G_\nu \), and denote by \(\{u,v\}\) the poles of \(\nu \), conventionally ordered according to an st-numbering of G, where s and t are the poles of the root of T. For each \(w \in \{u,v\}\), let \(\textrm{indeg} _\nu (w)\) and \(\textrm{outdeg} _\nu (w)\) be the degree of w inside and outside \(H_\nu \), respectively. Define two, possibly coincident, alias vertices of w, denoted by \(w'\) and \(w''\), as follows: (i) if \(\textrm{indeg} _\nu (w)=1\), then \(w'=w''=w\); (ii) if \(\textrm{indeg} _\nu (w)=\textrm{outdeg} _\nu (w)=2\), then \(w'\) and \(w''\) are dummy vertices, each splitting one of the two distinct edge segments incident to w outside \(H_{\nu }\); (iii) if \(\textrm{indeg} _\nu (w)>1\) and \(\textrm{outdeg} _\nu (w)=1\), then \(w'=w''\) is a dummy vertex that splits the edge segment incident to w outside \(H_{\nu }\).

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 in \(H_\nu \), and let \(u'\) and \(v'\) be alias vertices of u and v, respectively. The path \(S^{u'v'}\) obtained by concatenating \((u',u)\), \(P^{uv}\), and \((v,v')\) is a spine of \(H_\nu \). The spirality \(\sigma (H_\nu )\) of \(H_\nu \), introduced in [6], is either an integer or a semi-integer number, defined based on the following cases: (i) if \(A^u=\{u'\}\) and \(A^v=\{v'\}\) then \(\sigma (H_\nu ) = n(S^{u'v'})\); (ii) if \(A^u=\{u'\}\) and \(A^v=\{v',v''\}\) then \(\sigma (H_\nu ) = \frac{1}{2} \big (n(S^{u'v'}) + n(S^{u'v''}) \big )\); (iii) if \(A^u=\{u',u''\}\) and \(A^v=\{v'\}\) then \(\sigma (H_\nu ) = \frac{1}{2} \big ( n(S^{u'v'}) + n(S^{u''v'})\big )\); (iv) if \(A^u=\{u',u''\}\) and \(A^v=\{v',v''\}\), assume w.l.o.g. that \((u,u')\) is the edge before \((u,u'')\) counterclockwise around u and that \((v,v')\) is the edge before \((v,v'')\) clockwise around v; then \(\sigma (H_\nu ) = \frac{1}{2} \big (n(S^{u'v'}) + n(S^{u''v''})\big )\).

For brevity, in the remainder of the paper we often denote by \(\sigma _\nu \) the spirality of a component \(H_\nu \). Figure 3 shows the graph G of Fig. 2a, two P-components \(G_{\mu _1}\) and \(G_{\mu _2}\) highlighted, and an orthogonal representation H of G. The orthogonal components \(H_{\mu _1}\) and \(H_{\mu _2}\) in H have respectively spiralities \(\sigma _{\mu _1}=-1\), see Case (iv), and \(\sigma _{\mu _2}=0\), see Case (i). Figure 4a shows an orthogonal S-component with spirality \(\frac{3}{2}\), see Case (ii).

Fig. 3
figure 3

Illustration of the concept of spirality

Note that, the spirality of \(H_\nu \) does not vary if we choose a different path \(P^{uv}\). Also, it is proved in [6] that a component \(H_\nu \) of H can always be substituted by any other representation \(H'_\nu \) of \(G_\nu \) with the same spirality, getting a new valid orthogonal representation with the same set of bends on the edges of H that are not in \(H_\nu \) (see [6] and also Theorem 1 in [11]).

Testing algorithm. Let T be a rooted normalized SPQ\(^*\)R-tree of the input graph G, and let b be a non-negative integer. An orthogonal representation of G (resp. of a component \(G_\nu \) of G) with at most b bends is a b-orthogonal representation of G (resp. of \(G_\nu \)). Theorem 1 will prove that testing if G admits a b-orthogonal representation is FPT parametrized by \(k+b\). We start with a key property.

Lemma 2

Let \(\nu \) be a node of T and H be a b-orthogonal representation of G. The spirality \(\sigma _\nu \) of the restriction \(H_\nu \) of H to \(G_\nu \) belongs to \([-k-b-2, k+b+2]\).

Proof

We consider the case \(\sigma _\nu >0\) and prove that \(\sigma _\nu \le k+b+2\). When \(\sigma _\nu \) is negative, the proof that \(-k-b-2 \le \sigma _\nu \) is symmetric. If \( 0 \le \sigma _\nu \le 2\), the lemma is trivially true. Assume now that \(\sigma _\nu > 2\). Denote by uv the two poles of \(\nu \). The boundary of \(H_\nu \) can be split into two paths from u to v, which we call the left path \(P^l\) and the right path \(P^r\) of \(H_\nu \). Namely, \(P^l\) (resp. \(P^r\)) is the path from u to v while walking clockwise (resp. counterclockwise) on the external boundary of \(H_\nu \). Note that, these paths may share some edges. By the definition of spirality, we have that \(\sigma _\nu \le n(P^l) + 2\), where \(n(P^l)\) is the turn number of \(P^l\). Since we are assuming \(\sigma _\nu > 2\), this implies \(n(P^l)>0\). Also, each right turn of \(P^l\) is a \(270^o\) angle in the external face of \(H_\nu \), hence it is either a degree-2 vertex or a bend. Hence, \(n(P^l) \le k+b\) and, consequently, \(\sigma _\nu \le k+b+2\). See for example Fig. 4a, which depicts an orthogonal representation \(H_\nu \) of \(G_\nu \) with spirality \(\sigma _\nu = \frac{3}{2}\) and \(n(P^l)=3\). Path \(P^l\) has one degree-2 vertex and three bends. \(\square \)

Fig. 4
figure 4

a Illustration for the proof of Lemma 2. b Illustration for Lemma 6

Spirality sets. For each node \(\nu \) of T, we define a function \(X_\nu \) that maps each target spirality value \(\sigma _\nu \) for a representation of \(G_\nu \) to a pair \((b_\nu ,H_\nu )\) such that \(b_\nu \) is the minimum number of bends over all orthogonal representations of \(G_\nu \) with spirality \(\sigma _\nu \), and \(H_\nu \) is a \(b_\nu \)-orthogonal representation of \(G_\nu \) with spirality \(\sigma _\nu \). We say that \(b_\nu \) is the cost of \(\sigma _\nu \) for \(\nu \) and that \(H_\nu \) is the representative for \(\nu \) given \(\sigma _\nu \). If the number of bends of every orthogonal representation of \(G_\nu \) with spirality \(\sigma _\nu \) is higher than the given upper bound b to the number of bends, we write \(X_\nu (\sigma _\nu )=(\infty ,\emptyset )\). The set \(\Sigma _\nu = \{ (\sigma _\nu , X_\nu (\sigma _\nu )) \; \vert \; X_\nu (\sigma _\nu ) \ne (\infty ,\emptyset )\}\) is called the spirality set of \(\nu \).

If for some node \(\nu \) the spirality set \(\Sigma _\nu \) is empty, the instance can be safely rejected. Also, by Lemma 2, for each node \(\nu \) of T we can assume \(\vert \sigma _\nu \vert < k+b+2\). Hence, we have \(\vert \Sigma _\nu \vert =O(k+b)\). In [6] it is shown that \(\Sigma _\nu \) can be computed in time: (i) \(O(\vert \Sigma _\nu \vert )\) if \(\nu \) is a Q\(^*\)-node; (ii) \(O(\vert \Sigma _\nu \vert )\) if \(\nu \) is a P-node and \(O(\vert \Sigma _\nu \vert ^2)\) if \(\nu \) is an S-node, and if we know the spirality sets of the children of \(\nu \). For each pair \((\sigma _\nu ,X_\nu (\sigma _\nu ))\) in \(\Sigma _\nu \), the representative \(H_\nu \) for \(\nu \) is encoded in constant time by suitably linking the representatives for the children of \(\nu \) and adding a constant-size information that specifies the values of the angles at the poles of \(\nu \). By Lemma 2 we can restate the results in [6] as follows.

Lemma 3

Let \(\nu \) be a Q\(^*\)-node of T. There is an \(O(k+b)\)-time algorithm that computes \(\Sigma _\nu \).

Lemma 4

Let \(\nu \) be a P-node of T with children \(\mu _1,...,\mu _h\) (\(h \in \{2,3\}\)). Given \(\Sigma _{\mu _i}\) for each \(i \in \{1, \dots , h\}\), there is an \(O(k+b)\)-time algorithm that computes \(\Sigma _\nu \).

Lemma 5

Let \(\nu \) be an S-node of T with children \(\mu _1\) and \(\mu _2\). Given \(\Sigma _{\mu _1}\) and \(\Sigma _{\mu _2}\), there is an \(O((k+b)^2)\)-time algorithm that computes \(\Sigma _\nu \).

Let \(\rho \) be the root of T and let H be an orthogonal representation of G where \(G_\rho \) (i.e., the reference chain) is on the external face. Without loss of generality, we assume that \(G_\rho \) is to the right of H, i.e., for each simple cycle containing the end-vertices u and v of \(G_\rho \), visiting this cycle clockwise we encounter u, v, and \(G_\rho \) in this order. In any orthogonal representation H of G, the number of right turns minus the number of left turns encountered traversing clockwise any cycle of G in H equals four [5]. Hence, the following lemma immediately holds.

Lemma 6

Let H be an orthogonal representation of G, let T be the SPQ\(^*\)R-tree rooted at \(\rho \), and let \(\nu \) be the root child of T. Denoted by \(n(H_\rho ^{uv})\) the turn number of the chain \(G_\rho \) in H, moving from u to v, we have \(\sigma (H_\nu )-n(H_\rho ^{uv})=4\).

Figure 4b illustrates Lemma 6, where \(n(H_\rho ^{uv})=-5\) and \(\sigma (H_\nu )=-1\). The next lemma gives the time complexity needed to compute \(\Sigma _\nu \) when \(\nu \) is an R-node.

Lemma 7

Let \(\nu \) be an R-node of T and let \(\mu _1, \dots ,\mu _d\) be its children that are not \(Q^*\)-nodes. Given \(\Sigma _{\mu _i}\) for each \(i \in \{1, \dots , d\}\), there exists an algorithm that computes \(\Sigma _\nu \) in \(O(2^{p \cdot \log p} \cdot n^{\frac{7}{4}}\sqrt{\log n})\) time, with \(p=k+b\).

Proof

For every target value of spirality \(\sigma _\nu \in [-k-b-2,k+b+2]\), we compute \(X_\nu (\sigma _\nu )\) as follows. A valid tuple is a tuple \((\sigma _{\mu _1},...,\sigma _{\mu _d})\) such that \(\sum _{i=1}^db_i\le b\), where \(X_{\mu _i}(\sigma _{\mu _i})=(b_i,H_{\mu _i})\) for every \(i\in \{1,\dots , d\}\). Let u and v be the poles of \(\nu \). For each of the two possible embeddings of \(\textrm{skel} (\nu )\), consider the component \(G_\nu \) enhanced with a dummy edge e, connecting the poles u and v of \(\nu \), in such a way that e is on the external face of \(G_\nu \) and to the right of \(G_\nu \). Let \(G'\) be the resulting graph. We have four cases depending on the number of alias vertices of u and v: (a\(\vert A^u \vert = \vert A^v \vert =1\); (b\(\vert A^u \vert =1\) and \(\vert A^v \vert =2\); (c\( \vert A^u \vert =2\) and \(\vert A^v \vert =1\); (d\( \vert A^u \vert =\vert A^v \vert =2\).

Case (a).:

For each valid tuple, we perform the following procedure. Let \(H_e\) be an orthogonal representation of e such that \(n(H_e^{uv})=\sigma _\nu -4\), where \(n(H_e^{uv})\) is the turn number of \(H_e\) going from u to v. This means that \(H_e^{uv}\) has \(\sigma _\nu -4\) bends, each turning to the left if \(\sigma _\nu -4<0\), or each turning to the right if \(\sigma _\nu -4>0\). Also, let \(J=e \cup G_{\mu _1}\cup ...\cup G_{\mu _d}\) and let \(H_J\) be an orthogonal representation of the graph J such that: (i) the restriction of \(H_J\) to \(G_{\mu _i}\) coincides with \(H_{\mu _i}\) for each \(i\in \{1,\dots , d\}\); and (ii) the restriction of \(H_J\) to e coincides with \(H_e\). We compute an \(H_J\)-constrained orthogonal representation \(H'\) of \(G'\) with the minimum number of bends in polynomial time by Lemma 1, if it exists. Consider an SPQ\(^*\)R-tree \(T'\) of \(G'\) rooted at the Q\(^*\)-component \(\xi \) representing e. Note that \(\nu \) is the root child of \(T'\). Hence, by Lemma 6, if \(H'\) exists then its restriction \(H_\nu \) to \(G_\nu \) has spirality \(\sigma _\nu \). By Lemma 1, \(H_\nu \) is a bend-minimum orthogonal representation of \(G_\nu \) having spirality \(\sigma _\nu \) and the spirality of the restriction of \(H_\nu \) to \(G_{\mu _i}\) is \(\sigma _{\mu _i}\), for each \(i\in \{1,\dots , d\}\).

Case (b).:

We add vertex \(v'\) and edge \(e_v=(v,v')\) to \(G'\) so that e is the edge after \(e_v\) in the clockwise order of the edges incident to v. We proceed similarly as we did in Case (a). For each valid tuple, we perform the following procedure. Let \(H_e\) be an orthogonal representation of e such that \(n(H_e^{uv})=\sigma _\nu -\frac{7}{2}\), where \(H_e^{uv}\) is the turn number of \(H_e\) going from u to v. Observe that, since \(\sigma _\nu \) is a semi-integer number, \(n(H_e^{uv})\) is an integer number. Let \(J=e \cup G_{\mu _1}\cup ...\cup G_{\mu _d}\) and let \(H_J\) be an orthogonal representation of the graph J such that: (i) the restriction of \(H_J\) to \(G_{\mu _i}\) coincides with \(H_{\mu _i}\) for each \(i\in \{1,\dots , d\}\); and (ii) the restriction of \(H_J\) to e coincides with \(H_e\). We compute an \(H_J\)-constrained orthogonal representation \(H'\) of \(G'\) with the minimum number of bends in polynomial time by Lemma 1, if it exists. Consider an SPQ\(^*\)R-tree \(T'\) of \(G' \setminus \{e_v\}\) rooted at the Q\(^*\)-component \(\xi \) representing e. Suppose that \(H'\) exists. We can assume that \(e_v\) has 0 bends in \(H'\), since it is an edge incident to a degree-1 vertex. Let \(H''\) be the orthogonal representation obtained from \(H'\) removing \(e_v\). By Lemma 6, the restriction of \(H''\) to \(G_\nu \) has spirality \(\sigma _\nu +\frac{1}{2}\). By definition of spirality and by construction of \(G'\), the restriction \(H_\nu \) of \(H'\) to \(G_\nu \) has spirality \(\sigma _\nu \). By Lemma 1, \(H_\nu \) is a bend-minimum orthogonal representation of \(G_\nu \) having spirality \(\sigma _\nu \) and the spirality of the restriction of \(H_\nu \) to \(G_{\mu _i}\) is \(\sigma _{\mu _i}\), for each \(i\in \{1,\dots , d\}\).

Case (c).:

Symmetric to Case (b).

Case (d).:

We add vertex \(v'\) and edge \(e_v\) to \(G'\) as in Case (b). Also, we add vertex \(u'\) and edge \(e_u=(u,u')\) to \(G'\) so that e is the edge before \(e_u\) in the clockwise order of the edges incident to u. For each valid tuple, we perform the following procedure. Let \(H_e\) be an orthogonal representation of e such that \(n(H_e^{uv})=\sigma _\nu -1\), where \(H_e^{uv}\) is the turn number of \(H_e\) going from u to v. Let \(J=e \cup G_{\mu _1}\cup ...\cup G_{\mu _d}\) and let \(H_J\) be an orthogonal representation of the graph J such that: (i) the restriction of \(H_J\) to \(G_{\mu _i}\) coincides with \(H_{\mu _i}\) for each \(i\in \{1,\dots , d\}\); and (ii) the restriction of \(H_J\) to e coincides with \(H_e\). We compute an \(H_J\)-constrained orthogonal representation \(H'\) of \(G'\) with the minimum number of bends in polynomial time by Lemma 1, if it exists. Consider an SPQ\(^*\)R-tree \(T'\) of \(G' \setminus \{e_u, e_v\}\) rooted at the Q\(^*\)-component \(\xi \) representing e. Suppose that \(H'\) exists. We can assume that \(e_u\) and \(e_v\) have 0 bends in \(H'\). Let \(H''\) be the orthogonal representation obtained from \(H'\) removing \(e_u\) and \(e_v\). By Lemma 6, the restriction of \(H''\) to \(G_\nu \) has spirality \(\sigma _\nu +1\). By definition of spirality and by construction of \(G'\), the restriction \(H_\nu \) of \(H'\) to \(G_\nu \) has spirality \(\sigma _\nu \). By Lemma 1, \(H_\nu \) is a bend-minimum orthogonal representation of \(G_\nu \) having spirality \(\sigma _\nu \) and the spirality of the restriction of \(H_\nu \) to \(G_{\mu _i}\) is \(\sigma _{\mu _i}\), for each \(i\in \{1,\dots , d\}\).

Denote by \(b_\nu \) the number of bends of \(H_\nu \). If \(b_\nu > b\) for each of the two planar embeddings of \(\textrm{skel} (\nu )\), then \(X_\nu (\sigma _\nu )=(\infty ,\emptyset )\) and we do not insert \((\sigma _\nu ,X_\nu (\sigma _\nu ))\) in the spirality set \(\Sigma _\nu \). Else, over the two embeddings of \(\textrm{skel} (\nu )\) we retain the representation \(H_\nu \) of minimum cost \(b_\nu \), set \(X_\nu (\sigma _\nu )=(b_\nu ,H_\nu )\), and insert \((\sigma _\nu ,X_\nu (\sigma _\nu ))\) in \(\Sigma _\nu \).

Correctness. The correctness of the procedure above follows by these facts: (i) to construct a bend-minimum representation \(H_\nu \) with spirality \(\sigma _\nu \), we consider all possible combinations of values of spiralities for \(G_{\mu _1}, \dots , G_{\mu _d}\); (ii) thanks to the interchangeability of orthogonal components with the same spirality, for each such combination we aim to construct \(H_\nu \) in such a way that it contains a minimum-bend representation of each \(G_{\mu _i}\) with its target value of spirality; (iii) if \(b_\nu \le b\), the spirality determined by \(H_\nu \) for each child \(\mu \) of \(\nu \) that corresponds to a Q\(^*\)-component is surely in the spirality set of \(\mu \); (iv) By Lemma 2 it suffices to test the existence of an \(H_\nu \) for each target value of spirality \(\sigma _\nu \in [-k-b-2,k+b+2]\).

Time-complexity. By Lemma 1, for each tuple the time required for the computation is \(O(n^\frac{7}{4}\sqrt{\log n})\). By Lemma 2, we consider \(O((k+b)^d)\) valid tuples. Moreover, we can assume that \(d \le k+b\), otherwise the instance can be rejected. More precisely, since \(G_{\mu _i}\) (\(i\in \{1,\dots , d\}\)) contains at least one cycle, any orthogonal representation of \(G_{\mu _i}\) requires four \(270^\circ \) (i.e., reflex) angles on the external face, and at most two of these angles can occur at the poles of \(G_{\mu _i}\). Since each reflex angle that does not occur at a pole of \(G_{\mu _i}\) requires either a degree-2 vertex or a bend, we necessarily have \(d \le k+b\) if \(H_\nu \) exists. Hence, there are \(O((k+b)^d)=O((k+b)^{k+b})=O(2^{(k+b) \cdot \log (k+b)})\) valid tuples. \(\square \)

We can now prove the main result of this section.

Theorem 1

Let G be a biconnected graph with k degree-2 vertices, let b be an integer, and let \(p=k+b\). There exists an \(O(2^{p \cdot \log p} \cdot n^{3.75}\sqrt{\log n})\)-time algorithm that tests whether G admits a b-orthogonal representation, and that computes one with the minimum number of bends in the positive case.

Proof

If G is a simple cycle the test is trivial. Otherwise, let T be the SPQ\(^*\)R-tree of G. For each Q\(^*\)-node \(\rho \) of T, root T at \(\rho \). Recall that this rooted tree describes all planar embeddings of G with the reference chain \(G_\rho \) on the external face. We perform a post-order visit of T. We first compute \(\Sigma _\nu \) for each leaf \(\nu \) of T, that is, for each Q\(^*\)-node distinct from \(\rho \). We can do this in \(O(n(k+b))\) time by Lemma 3. During this visit of T, for every internal non-root node \(\nu \) of T the algorithm computes \(\Sigma _\nu \) by using the spirality sets of the children of \(\nu \), exploiting Lemmas 4, 5 and 7, depending on whether \(\nu \) is a P-, an S-, or an R-node, respectively. If the spirality set \(\Sigma _\nu \) of \(\nu \) is empty, then G does not have a b-orthogonal representation with the given reference edge \(G_\rho \) on the external face. In this case the algorithm stops visiting T rooted at \(\rho \), and starts visiting T rooted at another Q\(^*\)-node. Suppose that the algorithm reaches the root child \(\nu \) of T, computes the spirality set \(\Sigma _\nu \), and this spirality set is not empty. Denote by u and v the poles of \(\nu \). Then, the algorithm considers each pair \((\sigma _\nu , X_\nu (\sigma _\nu )=(b_\nu ,H_\nu ))\) in the spirality set of \(\nu \). Lemma 6 implies that G admits an orthogonal representation H with \(G_\rho \) on the external face whose restriction to \(G_\nu \) in H has spirality \(\sigma _\nu \) if and only if the restriction to \(G_\rho \) in H has an orthogonal representation \(H_\rho \) such that \(n(H_\rho ^{uv})=\sigma _\nu -4\). Let \(n_\rho \) be the number of vertices of \(G_\rho \) distinct from u and v. Since \(G_\rho \) is a chain of edges, we have that such \(H_\rho \) has \(b_\rho =0\) bends if \(n_\rho \ge \vert \sigma _\nu -4 \vert \); otherwise it has \(b_\rho =\vert \sigma _\nu -4 \vert -n_\rho \) bends and we just check if \(b_\nu +b_\rho \le b\). By the reasoning above, G admits a b-orthogonal representation H if and only if such a test is positive for some \(\sigma _\nu \). Also, if this is true, we can construct H by attaching \(H_\nu \) to \(H_\rho \), and since for each node \(\nu \) we have used the representation \(H_\nu \) with minimum number of bends among those with the same spirality, H has the minimum number of bends over all b-orthogonal representations of G.

By Lemma 4, 5 and 7 for each node we spend \(O(2^{p \cdot \log p} \cdot n^{\frac{7}{4}}\sqrt{\log n})\) time, and the condition of Lemma 6 at the root level can be tested in O(n) time. Since T has O(n) nodes and G has O(n) rooted SPQ\(^*\)R-trees, the statement follows.\(\square \)

4 The General Case

We assume first that G is connected but not biconnected; we then consider non-connected graphs in the proof of Theorem 2. A biconnected component of G is also called a block. There are two main difficulties in extending the result of Theorem 1 when G is not biconnected. In terms of drawability, some angle constraints may be required at the cutvertices of the input graph G. Namely, one cannot simply test the representability of each single block independently, as it might be impossible to merge the orthogonal representations of the different blocks into an orthogonal representation of G without additional angle constraints at the cutvertices. In terms of vertex-degree, G might also have degree-1 vertices and, more importantly, a vertex of degree three or four in G can be a degree-2 vertex in a block; hence, the sum of the degree-2 vertices in all blocks can be larger than the number of degree-2 vertices in G. To manage angle constraints at the cutvertices, we adopt a variant of a strategy used in a previous work on series–parallel graphs [10], and extend it to also consider rigid components. About the number of degree-2 vertices, similarly to [8], we extend the parameter k to include both vertices of degree one and two, and we observe that each block of G must have \(O(k+b)\) degree-2 vertices if G admits a b-orthogonal representation.

Block-cutvertex tree. Let G be a connected graph having k vertices of degree at most two, and let b be a non-negative integer. To deal with the possible planar embeddings of G, we use the BC-tree (block-cutvertex tree) of G, and combine it with the SPQ\(^*\)R-trees of its blocks. The BC-tree \(\mathcal T\) of G describes the decomposition of G in terms of its blocks and cutvertices; refer to  Fig. 5. Each node of \(\mathcal T\) represents either a block or a cutvertex of G. A block-node (resp. a cutvertex-node) of \(\mathcal T\) represents a block (resp. a cutvertex) of G. There is an edge between two nodes of \(\mathcal T\) if one of them represents a cutvertex and the other represents a block that contains the cutvertex. If \(B_1, \dots , B_q\) are the blocks of G \((q \ge 2)\), we denote by \(\beta (B_i)\) the block-node of \(\mathcal T\) corresponding to \(B_i\) \((1 \le i \le q)\) and by \(\mathcal{T}_{B_i}\) the tree \(\mathcal T\) rooted at \(\beta (B_i)\). For a cutvertex c of G, we denote by \(\chi (c)\) the node of \(\mathcal T\) that corresponds to c. Each \(\mathcal{T}_{B_i}\) describes a class of planar embeddings of G such that, for each non-root node \(\beta (B_j)\) \((1 \le j \le q)\) with parent node \(\chi (c)\) and grandparent node \(\beta (B_k)\), the cutvertex c and \(B_k\) lie on the external face of \(B_j\). An orthogonal representation of G with respect to \(\mathcal{T}_{B_i}\) is an orthogonal representation whose planar embedding belongs to the class described by \(\mathcal{T}_{B_i}\). Therefore, to test whether G admits a b-orthogonal representation we have to test if G admits a b-orthogonal representation with respect to \(\mathcal{T}_{B_i}\) for some \(i \in \{1, \dots , q\}\).

Testing algorithm. For any fixed \(i \in \{1, \dots , q\}\), testing whether G has a b-orthogonal representation with respect to \(\mathcal{T}_{B_i}\), requires to compute a bend-minimum representation for each block \(B_j\) subject to angle constraints at the cutvertices of \(B_j\), so that we can merge the representation of \(B_j\) with those of its adjacent blocks. For example, consider the orthogonal representation H in Fig. 5a, whose embedding is in the class described by the rooted BC-tree \(\mathcal{T}_{B_4}\) of Fig. 5b. H has blocks \(B_1, \dots , B_5\) (where \(B_3\) and \(B_5\) are trivial blocks) and cutvertices c, \(c'\), and \(c''\). Note that the representation of \(B_1\) must have c on its external face with a flat angle, so to accommodate the representation of \(B_3\). Also, \(c'\) must have a reflex angle in the representation of \(B_1\), so to accommodate the representation of \(B_2\). Conversely, the two orthogonal representations in Fig. 5c have embeddings that do not adhere to any rooted version of \(\mathcal T\), and they cannot be merged, because neither c nor \(c''\) lie on the external face of their components. In the following we describe in details all types of angle constraints that may be needed at the cutvertices of a block.

Fig. 5
figure 5

a An orthogonal representation H of a 1-connected graph and its blocks. b The BC-tree \(\mathcal{T}_{B_4}\); the embedding of H is in the class described by \(\mathcal{T}_{B_4}\). c Orthogonal representations of \(B_1\) and \(B_4\) that cannot be glued planarly

If \(B_j \ne B_i\) (\(\beta (B_j)\) is not the root of \(\mathcal{T}_{B_i}\)), we denote by c the cutvertex of \(B_j\) for which \(\chi (c)\) is the parent of \(\beta (B_j)\). Also, we always denote by \(c'\) any cutvertex such that \(\chi (c')\) is a child of \(\beta (B_j)\). Finally, let \(\deg (c \vert B_j)\) and \(\deg (c)\) (resp. \(\deg (c' \vert B_j)\) and \(\deg (c')\)) be the degree of c (resp. \(c'\)) in \(B_j\) and the degree of c (resp. \(c'\)) in G.

  • If \(\deg (c' \vert B_j)=2\) and \(\deg (c')=4\), then there are two cases. If \(\deg (c' \vert B_k)=2\) for some child \(\beta (B_k)\) of \(\chi (c')\) ((Fig. 6a), we need to impose on \(c'\) a reflex-angle constraint, requiring a reflex angle (270\(^\circ \)) at \(c'\) in the orthogonal representation of \(B_j\); this guarantees that we can glue the representations of \(B_j\) and of \(B_k\) at \(c'\). If \(\deg (c' \vert B_k)<2\) for every child \(\beta (B_k)\) of \(\chi (c')\), no constraint is needed for \(c'\).

  • If \(\deg (c \vert B_j) = 1\), then \(B_j\) is a trivial block (i.e., a single edge) and no constraint is needed for c.

  • If \(\deg (c \vert B_j) \ge 2\), let \(B_k\) be the block such that \(\beta (B_k)\) is the parent of \(\chi (c)\). There are three possible types of angle constraints for c, depending on the following four cases: (i) If \(\deg (c)=4\) and \(\deg (c \vert B_k)=\deg (c \vert B_j)=2\) ((Fig. 6b), then we impose an external reflex-angle constraint on c, which forces c to have a reflex angle on the external face f; block \(B_k\) will be embedded on f. (ii) If \(\deg (c)=4\) with \(\deg (c \vert B_k)=1\) (i.e., \(B_k\) is a trivial block) and \(\deg (c \vert B_j)=2\), then \(\beta (B_j)\) has a sibling \(\beta (B_h)\), where \(B_h\) is a trivial block (Fig. 6c). In this case, we impose an external non-right-angle constraint on c, which forces c to have an angle larger than \(90^\circ \) (either a flat or a reflex angle) on the external face f; block \(B_k\) will be embedded on f, while \(B_h\) will be embedded either on f (if c will have a reflex angle in f) or on the other face of \(B_j\) incident to c (if c will have a flat angle in f). (iii) If \(\deg (c)=4\) with \(\deg (c \vert B_k)=1\) and \(\deg (c \vert B_j)=3\) (Fig. 6d), we impose an external flat-angle constraint on c, which forces c to have its unique flat angle in the external face f; again, \(B_k\) will be embedded on f. (iv) If \(\deg (c)=3\) and \(\deg (c \vert B_j)=2\) (hence \(\deg (c \vert B_k)=1\)), we impose an external non-right-angle constraint on c, as in case (ii).

Fig. 6
figure 6

Schematic illustration of cases that require angle constraints

A b-constrained orthogonal representation of \(B_j\) is a representation \(H_{B_j}\) with at most b bends and that fulfills the required angle constraints at the cutvertices of G that belong to \(B_j\). We prove the following.

Lemma 8

Let G be a graph with k vertices of degree at most two and let b be a non-negative integer. Let \(B_1, \dots , B_q\) be the blocks of G, let \(\mathcal{T}_{B_i}\) be the BC-tree of G rooted at \(\beta (B_i)\) (for some \(i \in \{1, \dots , q\}\)), and let \(B_j\) be any block of G (possibly \(i=j\)), let \(n_j\) be the number of vertices in \(B_j\), and let \(p = k+b\). There exists an algorithm that tests whether \(B_j\) admits a b-constrained orthogonal representation and that computes one with the minimum number of bends in the positive case. The algorithm runs in \(O(2^{p \cdot \log p} \cdot n_j^{3.75}\sqrt{\log n_j})\) time if \(B_j=B_i\) and in \(O(2^{p \cdot \log p} \cdot n_j^{2.75}\sqrt{\log n_j})\) time if \(B_j \ne B_i\).

Proof

A degree-2 vertex of \(B_j\) is either a degree-2 vertex of G or a cutvertex of G with degree 3 or 4. We prove that if G admits a b-orthogonal representation, the number of degree-2 vertices of \(B_j\) is at most \(p'=2k+b\). Let \(\delta \) be the number of degree-2 vertices of the block \(B_{j}\). At most k of these vertices can be degree-2 vertices of G, then \(B_j\) must have at least \(\delta -k\) cut-vertices. This implies that \(\beta (B_j)\) has degree at least \(\delta -k\) in \(\mathcal{T}\) and hence \(\mathcal{T}\) has at least \(\delta -k\) leaves. Consider any block \(B_l\) such that \(\beta (B_l)\) is a leaf of \(\mathcal{T}\). We show that, if G admits a b-orthogonal representation H, then \(\beta (B_l)\) contributes at least for one unit to \(k+b\). Namely, if \(B_l\) is a trivial block then \(B_l\) has a degree-1 vertex. If \(B_l\) is not a trivial block then the restriction of H to \(B_l\) contains at least three reflex angles that are not cutvertices of G (because \(\beta (B_l)\) of is a leaf of \(\mathcal{T}\) and thus \(B_l\) contains exactly one cutvertex of G); each of these reflex angles corresponds to either a degree-2 vertex of G or a bend of H. It follows that if G admits a b-orthogonal representation, the number of leaves of \(\mathcal{T}\) is at most \(k+b\), that is, \(\delta -k \le k+b\), which gives \(\delta \le 2k+b\). Therefore, if \(B_j\) contains more than \(p'\) degree-2 vertices, we immediately conclude that the test is negative, as \(B_j\) cannot admit a b-constrained orthogonal representation.

Suppose then that \(B_j\) contains at most \(p'\) degree-2 vertices. To continue the test, we apply on \(B_j\) the same dynamic programming algorithm as Theorem 1 based on the rooted SPQ\(^*\)R-trees of \(B_j\), but we specialize this algorithm to take into account the required angle constraints at the cutvertices when every rooted SPQ\(^*\)R-trees of \(B_j\) is visited. In the following we describe how to handle each type of constraint during a visit of an SPQ\(^*\)R-tree, where again c denotes the cutvertex that must lie on the external face of \(B_j\) (if \(B_j \ne B_i\)) and \(c'\) denotes any other cutvertex of G that belongs to \(B_j\). Note that, if \(B_j \ne B_i\), we only need to consider those SPQ\(^*\)R-trees of \(B_j\) rooted at reference chains that contain c, because we must restrict to those planar embeddings of \(B_j\) with c on the external face.

  • Reflex-angle constraint at \(c'\). In this case \(c'\) has degree two in \(B_j\), thus \(c'\) belongs to a maximal chain of edges represented by a Q\(^*\)-node \(\nu \). It is enough to consider those spirality values \(\sigma _\nu \) of \(G_\nu \) that are compatible with a left/right turn at \(c'\) and, for such a value of spirality, consider a representative \(H_\nu \) having a left/right turn at \(c'\).

  • External reflex-angle constraint at c. Also in this case c has degree two in \(B_j\), and c belongs to a maximal chain of edges represented by a Q\(^*\)-node \(\rho \). In this case the SPQ\(^*\)R-tree rooted at \(\rho \) is the only one that we need to visit, thus c belongs to the reference chain and is distinct from the poles u and v of \(\rho \). Again, when we evaluate the condition of Lemma 6 at the root level, it suffices to restrict to those representations \(H^{uv}_\rho \) with a left turn at c.

  • External flat-angle constraint at c. In this case c has degree three in \(B_j\), and we visit at most three possible SPQ\(^*\)R-trees, one for each of the three maximal chains having c as one of its two end-vertices. In each of these SPQ\(^*\)R-trees, the root child \(\nu \) is either a P-node of degree two or an R-node, and c is one of the two poles of \(\nu \). If \(\nu \) is a P-node, for each target spirality value \(\sigma _\nu \), one can just consider the subset of combinations of the angles at c that guarantee a flat angle at the pole c in the external face of \(G_\nu \) when construct \(H_\nu \) (see [10] for details). If \(\nu \) is an R-node, it is enough to force a flat angle at c on the external face of the rigid component in the test of Lemma 7; this is done by fixing the value of the flow on an arc of the flow-network.

  • External non-right-angle constraint at c. In this case c has degree two in \(B_j\). Hence, similarly to the external reflex-angle constraint, c belongs to a maximal chain of edges represented by a Q\(^*\)-node \(\rho \), and we only need to visit the SPQ\(^*\)R-tree rooted at \(\rho \). When we evaluate the condition of Lemma 6 at the root level, it is enough to only consider those representations \(H^{uv}_\rho \) that have either a left turn at c or no turn at c.

All the described modifications of the testing algorithm in Theorem 1 still take \(O(p')\) time and \(p' = O(k+b)\). Hence, when \(B_j=B_i\), the testing algorithm takes the same time as in Theorem 1 on the size of \(B_i\), because it potentially evaluates all the SPQ\(^*\)R-trees of \(B_j\), i.e., \(O(2^{p \cdot \log p} \cdot n_j^{3.75}\sqrt{\log n_j})\); if \(B_j \ne B_i\) it only considers a constant number of SPQ\(^*\)R-trees of \(B_j\), thus the algorithm takes \(O(2^{p \cdot \log p} \cdot n_j^{2.75}\sqrt{\log n_j})\) time. \(\square \)

Theorem 2

Let G be a graph with k vertices of degree at most two, let b be a non-negative integer, and let \(p=k+b\). There exists an \(O(2^{p \cdot \log p} \cdot n^{3.75}\sqrt{\log n})\)-time algorithm that tests whether G admits a b-orthogonal representation, and that computes one with the minimum number of bends in the positive case.

Proof

Suppose first that G is 1-connected. Let \(B_1, \dots , B_q\) be the blocks of G. For any given rooted BC-tree \(\mathcal{T}_{B_i}\), we test whether G admits a b-orthogonal representation with respect to \(\mathcal{T}_{B_i}\). This requires to test for each block \(B_j\) whether \(B_j\) admits a b-constrained representation. This test is done with the algorithm of Lemma 8 and, if it is positive, the same algorithm computes one of these representations, call it \(H_j\), having the minimum number of bends; denote by \(b_j\) the number of bends of \(H_j\). If \(\sum _{j=1, \dots , q}b_j \le b\) then the whole test is positive, and we can obtain a b-constrained representation of G by merging all the \(H_j\) at the cutvertices. Otherwise, we discard \(\mathcal{T}_{B_i}\). We can execute this test for all rooted BC-trees, and return the b-orthogonal representation of G having the minimum number of bends among those for which the test was positive (if any). If the test for each rooted BC-tree was negative, then there is no a b-orthogonal representation of G.

About the time complexity, let \(n_j\) be the number of vertices of \(B_j\). Clearly \(\sum _j n_j = O(n)\). Hence, by Lemma 8, for each BC-tree rooted at a block \(B_i\), the algorithm takes \(O(2^{p \cdot \log p} \cdot n_i^{3.75}\sqrt{\log n_i} + n^{2.75}\sqrt{\log n})\) time. Summing up over all rooted BC-trees, i.e., over all \(i = 1, \dots , q\), we get overall \(O(2^{p \cdot \log p} \cdot n^{3.75}\sqrt{\log n})\) time.

Finally, if G is not connected we apply the above procedure to each connected component of G and test if the sum of the number of bends in the components exceeds b. Since the total number of blocks of G is O(n), by an analogous reasoning as above we obtain the same bound on the time complexity. \(\square \)

Corollary 1

Let G be a graph with k vertices of degree at most two. There exists an \(O(2^{p \cdot \log p} \cdot n^{3.75}\sqrt{\log n})\)-time algorithm that tests whether G admits a rectilinear representation, and that computes one in the positive case.

5 Complexity Lower Bounds

In this section, we show that \(b\)-Orthogonal Planarity is para-NP-hard when parameterized by the number k of vertices of degree at most two, and W[1]-hard parameterized by \(k+\textsf{tw}\), where \(\textsf{tw}\) denotes treewidth. To this aim, we build on the recent work by Jansen et al. [21, 22], in which a proof of W[1]-hardness for Rectlinear Planarity parameterized by \(\textsf{tw}\) is presented. The proof is based on a chain of parameterized reductions that also yields an NP-hardness reduction for the general (non-parameterized) Rectlinear Planarity problem. The last step of the proof describes a reduction from the Circulating Orientation problem to Rectlinear Planarity. Let P be an undirected graph and let \(c :E(P) \rightarrow \mathbb {N}\). The Circulating Orientation problem asks for an orientation of the edges of P such that, for each \(v \in V(P)\), it holds \(\sum _{e\in d_P^-(v)}c(e)=\sum _{e\in d_P^+(v)}c(e)\), where \(d^-_P(v)\) and \(d^+_P(v)\) are the set of incoming edges and the set of outgoing edges of v, respectively.

Before describing the reduction, we recall a definition originally introduced in [18]; see also Fig. 7a. Let f be a face of an orthogonal drawing and let \(\pi \) be a simple path along the boundary of f. The angle contribution of \(\pi \) to f is the number of \(270^\circ \) angles minus the number of \(90^\circ \) angles that the inner vertices and bends of \(\pi \) make in f.

Lemma 9

[18]  For every integer \(t \ge 0\), there exists a planar graph \(T_t\) with two special vertices p and q, called poles, and with external face f, such that the following properties hold:

  • \(T_t\) has O(t) vertices and edges.

  • \(T_t\) has a unique rectilinear representation H.

  • In H, the angle contributions to f of the two boundary paths from p to q are 4t and \(-4t\).

For every integer \(t \ge 0\), the graph \(T_t\) is called tendril, and t is its weight. For example, the gray shaded area in Fig. 7a highlights a tendril \(T_1\) of weight 1.

For a large part, our reduction follows the one in [21, 22] from Circulating Orientation to Rectlinear Planarity, which we recall in the following. Consider an instance \(\langle P, c \rangle \) of Circulating Orientation such that P is a maximal planar graph and \(c :E(P) \rightarrow \mathbb {N}\). Note that P has a unique planar embedding up to the choice of the external face. Let D be the dual graph of P; note that D is planar, biconnected, and of maximum degree three. Also, let \(w: E(D) \rightarrow \mathbb {N}\) be a weight function on the edges of D defined such that \(w(e) = c(e')\), where \(e' \in E(P)\), \(e \in E(D)\), and e is the dual edge of \(e'\). Next, consider the instance F obtained by subdividing each edge of D four times, that is, each edge of D is replaced with a path containing five edges. The middle edge of each such path is called the representative edge \(r_e\) of the original subdivided edge e, while the remaining four edges are called stubs. Finally, each representative edge \(r_e\) of F is further replaced with a tendril \(T_{t(e)}\), with weight \(t(e) = \theta \cdot w(e)\), such that \(\theta \) is sufficiently large, namely \(\theta \ge 2 \vert V(F) \vert + 1\). Let G be an instance of Rectlinear Planarity constructed with the procedure above: Deciding whether G is a yes-instance for Rectlinear Planarity is equivalent to deciding whether P is a yes-instance of Circulating Orientation. Therefore, as observed in [21, 22], this procedure yields an alternative NP-hardness reduction with respect to the original one by Garg and Tamassia [18]. Furthermore, since Circulating Orientation parameterized by treewidth is W[1]-hard and the reduction preserves the parameter (asymptotically), Rectlinear Planarity parameterized by treewidth is W[1]-hard. For our purposes, a key observation is that the only vertices having degree at most two in the instance G of Rectlinear Planarity are the degree-2 vertices shared by consecutive stubs and those contained in the tendrils; the same property does not hold in the original reduction by Garg and Tamassia [18] that uses additional gadgets, called wiggles, containing vertices of degree two.

Fig. 7
figure 7

a An edge of the instance D (top) and the corresponding subgraph in G (bottom); the tendril gadget, namely \(T_1\), is shown with a light gray background, its two poles p and q are depicted with squares. b The corresponding subgraph in \(G^*\) after smoothing degree-2 vertices

We are now ready to describe our reduction. Let G be the previously described instance of Rectlinear Planarity obtained by setting the parameter \(\theta = 5n\), where \(n=|V(F) |\) in the following. Given a degree-2 vertex u of G, the operation of smoothing u corresponds to removing u from the graph and connecting its two neighbors with an edge. Observe that such operation does not create parallel edges, because, by construction, no two vertices of G are connected by two edge-disjoint paths whose inner vertices (if any) all have degree two in G. Let \(G^*\) be the instance obtained from G by smoothing all its degree-2 vertices; Fig. 7b shows the effect of this transformation applied to the tendril of Fig. 7a. The subgraph in \(G^*\) corresponding to a tendril \(T_t\) in G is called a smoothed tendril. Let b be the number of degree-2 vertices removed when going from G to \(G^*\). Also, a base face of \(G^*\) is a face that is not an inner face of a smoothed tendril. We prove the following.

Lemma 10

\(\langle P,c \rangle \) is a yes-instance of Circulating Orientation if and only if \(G^*\) admits a b-orthogonal drawing.

Proof

Suppose first that \(\langle P,c \rangle \) is a yes-instance of Circulating Orientation. As shown in [21, 22], it follows that G admits a rectilinear drawing \(\Gamma \). Replacing each degree-2 vertex forming an angle different from \(180^\circ \) in \(\Gamma \) with a bend yields an orthogonal drawing \(\Gamma ^*\) of \(G^*\) with at most b bends.

Suppose now that \(G^*\) admits an orthogonal drawing \(\Gamma ^*\) with at most b bends. Observe that, given a base face f incident to a smoothed tendril \(T_t\), the angle contribution of each of the two external boundary paths of \(T_t\) to f is, in absolute value, at least 4t (i.e., it contains at least 4t bends in \(\Gamma ^*\)). We say that a smoothed tendril \(T_t\) has a positive (negative) weight t inside a base face f of \(G^*\) if its boundary path incident to f has a positive (negative) angle contribution to f Also, note that the number of degree-2 vertices in G that do not belong to any smoothed tendril is \(b^* \le 4 \cdot 2n = 8n\). Consequently, the sum of the angle contributions over all smoothed tendrils in a base face f of \(\Gamma ^*\) is \(s = a \cdot (4 \theta ) + d\), where a is an integer (possibly 0) equal to the sum of the weights of the considered tendrils in f, and \(d \in [-8n,+8n]\). On the other hand, we know that the boundary of f in \(\Gamma ^*\) is an orthogonal polygon, hence the difference between the number of \(270^\circ \) angles and the number of \(90^\circ \) angles is equal to \(-4\) if f is an inner face, and to \(+4\) if f is the external face. Thus, in absolute value, \(a \cdot (4 \theta ) \le 16n+4\), which implies that \(a=0\) (recall that \(\theta =5n\)). Construct an orientation of P as follows: for each representative edge \(r_e\) of F, orient the primal edge \(e'=(u,v)\) of e outgoing with respect to u if the angle contribution of the smoothed tendril \(T_{t(e)}\) is positive in the base face of \(G^*\) corresponding to u, and incoming otherwise. By construction we have that, for each \(v \in V(P)\), the value \(\sum _{e\in d_P^+(v)}c(e)\) is equal to \(4\theta \) times the sum of the weights over all smoothed tendrils having a positive angle contribution inside a base face of \(G^*\). Similarly, for each \(v \in V(P)\), the value \(\sum _{e\in d_P^-(v)}c(e)\) is equal to \(4\theta \) times the sum of the weights over all smoothed tendrils having a negative angle contribution inside the same base face of \(G^*\). As already shown, the sum of the weights of the smoothed tendrils along a base face is zero, thus \(\sum _{e\in d_P^+(v)}c(e)=\sum _{e\in d_P^-(v)}c(e)\), as desired. \(\square \)

Since \(G^*\) does not have vertices of degree less than three by construction, and the smoothing operation clearly preserves treewidth, the following theorem immediately follows from Lemma 10 and from the results in [21, 22].

Theorem 3

\(b\)-Orthogonal Planarity is NP-hard even for biconnected graphs with vertices of degree at least three, and it is W[1]-hard parameterized by the number of vertices of degree at most two plus treewidth.

6 Conclusions and Open Problems

In this paper we addressed two open questions posed in [8, 16] by giving a complete description of the parameterized complexity of the \(b\)-Orthogonal Planarity problem with respect to three parameters, namely the number b of bends, the number k of vertices of degree at most two, and the treewidth \(\textsf{tw}\). In particular, we described a fixed-parameter tractable algorithm for the \(b\)-Orthogonal Planarity problem parameterized by \(k+b\), we proved that the problem is para-NP-hard parameterized in k, and that it is W[1]-hard parameterized by \(k+\textsf{tw}\).

Note that the exponent of n in the time complexity of our FPT algorithms depend on the time T(n) taken by an algorithm that computes a bend-minimum orthogonal representation with constraints on edge bends and vertex angles. Based on Lemma 1, we expressed the time complexity of our algorithms assuming \(T(n)=O(n^\frac{7}{4}\sqrt{\log n})\). More in general, the time complexity of the testing algorithms in Theorem 1 and Theorem 2 can be rewritten as \(O(2^{p \log p}T(n)n^2)\). Hence, reducing T(n) would lead to a further improvement.

As an additional research direction, we find it interesting to study whether the \(b\)-Orthogonal Planarity problem parameterized by \(k+b\) admits a kernel of polynomial size. Also, we believe of interest to further explore the fixed parameter tractability of the problem with respect to other structural graph parameters such as, for example, the vertex distance to a forest or to a partial 2-tree. Moreover, the Circulating Orientation problem was recently shown to be XALP-complete parameterized by treewidth [2]. This complexity class (which contains W[1]) includes all parameterized problems that can be solved in \(f(k)n^{O(1)}\) time and \(f(k)\log n\) space on a non-deterministic Turing Machine with access to an auxiliary stack. It would be interesting to see whether \(b\)-Orthogonal Planarity parameterized by treewidth and the number of vertices of degree at most two is also XALP-complete.