1 Introduction

A k-page book embedding \(\langle \pi , \sigma \rangle \) of an undirected graph \(G=(V,E)\) consists of a vertex ordering \(\pi : V \leftrightarrow \{1,2,\dots ,|V |\}\) and of an assignment \(\sigma : E \rightarrow \{1,\dots ,k\}\) of the edges of G to one of k sets, called pages, so that for any two edges (ab) and (cd) in the same page, with \(\pi (a) < \pi (b)\) and \(\pi (c) < \pi (d)\), we have neither \(\pi (a) < \pi (c)\) \(< \pi (b) < \pi (d)\) nor \(\pi (c) < \pi (a) \) \(< \pi (d) < \pi (b)\). From a geometric perspective, a k-page book embedding can be represented as a drawing \(\Gamma (\pi ,\sigma )\) of G where the k pages correspond to k half-planes sharing a vertical line, called the spine. Each vertex v is a point on the spine with y-coordinate \(\pi (v)\); each edge e is a circular arc on page \(\sigma (e)\), and no edges in the same page cross. As an example, Fig. 1a represents a 3-page book embedding of the complete graph \(K_6\).

For directed graphs (digraphs), Heath, Pemmaraju, and Trenk introduced a variant of k-page book embeddings in which all the edges are oriented in the upward direction [69]. This implies that the input digraph is acyclic and all its vertices appear along the spine in a topological ordering. This type of book embedding for digraphs is called a k-page upward book embedding of G (kUBE for short). An example of a 4UBE is shown in Fig. 1c (throughout the paper, in the figures showing a kUBE, the edges are oriented from bottom to top; for simplicity the orientation of the edges is not explicitly shown). Note that, if \(\langle \pi , \sigma \rangle \) is a \(2\)UBE and the two pages are co-planar, then \(\Gamma (\pi ,\sigma )\) is an upward planar drawing of G, i.e., a crossing-free drawing with all edges monotonically increasing in the upward direction. Upward planar drawings represent a classical subject in topological graph theory [7,8,9, 26, 27, 32,33,34, 36, 39, 40, 42, 44, 50, 63, 85].

The page number of a (di)graph G (also called book thickness or stack number) is the minimum number k such that G admits a k-page (upward) book embedding. Computing the page number of undirected and directed graphs is a widely studied problem, with applications in a variety of domains, including VLSI design, fault-tolerant processing, parallel process scheduling, sorting networks, parallel matrix computations [37, 66, 84], computational origami [2], and graph drawing [29, 46, 64, 92]. See [53, 54] for additional references and applications.

Fig. 1
figure 1

a A 3-page book embedding of \(K_6\). b An orientation of \(K_6\). c A 4-page upward book embedding of \(K_6\) oriented as in (b)

Book embeddings of undirected graphs Seminal results on book embeddings of undirected graphs are described in the paper of Bernhart and Kainen [25]. They prove that the graphs with page number one are exactly the outerplanar graphs, while graphs with page number two are the sub-Hamiltonian graphs. This second result implies that it is NP-complete to decide whether a graph admits a 2-page book embedding [91]. Yannakakis [93] proved that every planar graph has a 4-page book embedding, while the question whether four pages are sometimes necessary for planar graphs has only been recently settled in the affirmative [24, 94]. The aforementioned works have inspired several papers about the page number of specific families of undirected graphs (e.g., [18, 21, 23, 37, 58]) and about the relationship between the page number and other graph parameters (e.g., [55, 62, 76, 77]). Different authors studied constrained versions of k-page book embeddings where either the vertex ordering \(\pi \) is (totally or partially) fixed [10, 11, 38, 78, 89, 90], or the page assignment \(\sigma \) for the edges is given [12,13,14, 70], or further conditions are required for the edges that occur in the same page [3, 25]. Relaxed versions of book embeddings where edge crossings are allowed (called k-page drawings) or where edges can cross the spine (called topological book embeddings) have also been considered (e.g., [1, 17, 31, 35, 45, 56, 57]). Finally, 2-page (topological) book embeddings find applications to point-set embedding and universal point set (e.g., [15, 16, 48, 49, 59, 75]).

Book embeddings of directed graphs. As for undirected graphs, there are many papers devoted to the study of upper and lower bounds on the page number of directed graphs. Heath, Pemmaraju, and Trenk [69] show that directed trees and unicyclic digraphs have page number one and two, respectively. Alzohairi and Rival [5], and later Di Giacomo et al. [46] with an improved linear-time construction, show that series-parallel digraphs have page number two. Mchedlidze and Symvonis [79] generalize this result and prove that N-free upward planar digraphs, which include series-parallel digraphs, also have page number two (a digraph is upward planar if it admits an upward planar drawing). Bhore et al. [28] provide constant upper bounds on the page number of several subfamilies of upward outerplanar graphs. Frati et al. [61] give several conditions under which upward planar triangulations have bounded page number. Recently, Jungeblut, Merker, and Ueckerdt [73] proved the first sublinear upper bound on the page number of upward planar graphs. Overall, the question asked by Nowakowski and Parker [82] more than 30 years ago of whether the page number of planar posets, and more generally of upward planar digraphs, is bounded remains unanswered. The page number of acyclic digraphs in terms of posets is also investigated by Alhashem, Jourdan, and Zaguia [4].

About lower bounds, Nowakowski and Parker [82] give an example of an upward planar digraph that requires 3 pages in any upward book embedding (see Fig. 10a). Subsequently, Hung [72] shows an upward planar digraph with page number 4. This bounds has been improved to 5 pages by Jungeblut, Merker, and Ueckerdt [73]. Heath and Pemmaraju [67] describe acyclic n-vertex planar digraphs that are not upward planar and whose upward book embeddings require \(\lfloor n/2\rfloor \) pages. Syslo [88] provides a lower bound on the page number of a poset in terms of its bump number.

Besides the study of upper and lower bounds on the page number of digraphs, several papers concentrate on the design of testing algorithms for the existence of kUBEs. Prior to this paper, the problem was known to be NP-complete only for \(k=6\) [68]. Only very recently, the case \(k=2\) has been settled by Bekos et al. [19], who show that the 2UBE problem is NP-complete for planar st-graphs and planar posetsFootnote 1. Furthermore, for \(k=2\), Mchedlidze and Symvonis give linear-time testing algorithms for outerplanar and planar triangulated st-graphs [81]. They also present an \(O(w^2n^w)\)-time testing algorithm for 2UBEs of n-vertex planar st-graphs of width w, where the width is the minimum number of directed paths that cover all the vertices [79]. Heath and Pemmaraju [68] describe a linear-time algorithm to recognize digraphs that admit 1UBEs. As for the undirected case, constrained or relaxed variants of kUBEs for digraphs are studied [2, 47, 64], as well as applications to the point-set embedding problem [46, 64].

Contributions. Our paper is motivated by the gap present in the literature about the computational complexity of the k UBE Testing problem. Namely, as discussed above, polynomial-time algorithms are known only for \(k=1\), or for \(k=2\) and subclasses of planar digraphs, while NP-completeness is known only for exactly 6 pages. Closing this gap has been a central question in algorithmic graph theory for over 20 years. In this paper, we make a major step towards a definitive answer to the above question, and address the research direction proposed by Heath and Pemmaraju [68] about identifying graph classes for which the existence of kUBEs can be solved efficiently. Our results are as follows:

  • We prove that testing whether a digraph G admits a kUBE is NP-complete for every \(k \ge 3\), even if G is an st-graph (Section 3). An analogous result was previously known only for the constrained version in which the page assignment is given [2]. Our result and the recent work of Bekos et al. [19] close the question about the complexity of the kUBE problem for any k.

  • We describe a new meaningful subclass of upward planar digraphs that admit a \(2\)UBE (Section 4). This class is structurally different from the N-free upward planar digraphs, the largest class of upward 2-page book embeddable digraphs previously known.

  • We give a linear-time algorithm to test the existence of an embedding-preserving \(2\)UBE for a family of plane st-graphs whose faces have a special structure, namely each face is either a generalized triangle (i.e., it contains a transitive edge) or a rhombus (i.e., its left and right paths have length two); see Section 5.

  • For planar n-vertex st-graphs of bounded branchwidth \({{\,\mathrm{\beta }\,}}\), we describe an FPT algorithm for the \(2\)UBE Testing problem that runs in \(O(f({{\,\mathrm{\beta }\,}})\cdot n + n^3)\) time, where f is a singly-exponential function (Section 6). The algorithm works for both variable and fixed embedding, and it implies a sub-exponential-time algorithm for general planar st-graphs. Since the treewidth and the branchwidth of a graph are within a constant factor from each other, this result immediately yields an FPT algorithm for st-graphs of bounded treewidth.

  • The approach used in the design of the FPT algorithm also leads to an O(n)-time testing algorithm for st-graphs of treewidth at most two (also known as two-terminal series-parallel graphs) in the fixed embedding setting (Theorem 7). We recall that in the variable embedding setting an st-graphs of treewidth at most two always admits a \(2\)UBE, which can be found in O(n) time [46].

2 Preliminaries

We only consider (di)graphs without loops and multiple edges, and we denote by V(G) and E(G) the sets of vertices and edges of a (di)graph G. A graph G is 1-connected if there is a path between any two vertices. G is k-connected, for \(k \ge 2\), if the removal of \(k-1\) vertices leaves the graph 1-connected. A 2-connected (3-connected) graph is also called biconnected (triconnected).

A planar drawing of G is a geometric representation in the plane such that: (i) each vertex \(v \in V(G)\) is drawn as a distinct point \(p_v\); (ii) each edge \(e=(u,v) \in E(G)\) is drawn as a simple curve connecting \(p_u\) and \(p_v\); (iii) no two edges intersect in \(\Gamma \) except at their common end-vertices (if they are adjacent). A graph is planar if it admits a planar drawing. A planar drawing \(\Gamma \) of G divides the plane into topologically connected regions, called faces. The outer face of \(\Gamma \) is the region of unbounded size; the other faces are internal. A planar embedding of G is an equivalence class of planar drawings that define the same set of (internal and outer) faces, and it can be described by the clockwise sequence of vertices and edges on the boundary of each face plus the choice of the outer face. Graph G together with a given planar embedding is an embedded planar graph, or simply a plane graph: If \(\Gamma \) is a planar drawing of G whose set of faces is described by the planar embedding of G, we say that \(\Gamma \) preserves this embedding, or also that \(\Gamma \) is an embedding-preserving drawing of G.

A digraph G is a planar st-graph if: (i) it is acyclic; (ii) it has a single source s and a single sink t; (iii) it admits a planar embedding \({\mathcal {E}}\) with s and t on the outer face. A planar st-graph G together with \({\mathcal {E}}\) is a planar embedded st-graph or a plane st-graph.

Let G be a plane st-graph and let \(e=(u,v)\) be an edge of G. The left face (resp. right face) of e is the face to the left (resp. right) of e while moving from u to v. The boundary of every face f of G consists of two directed paths \(p_l\) and \(p_r\) from a common source \(s_f\) to a common sink \(t_f\). The paths \(p_l\) and \(p_r\) are the left path and the right path of f, respectively. The vertices \(s_f\) and \(t_f\) are the source and the sink of f, respectively. If f is the outer face, \(p_l\) (resp. \(p_r\)) consists of the edges for which f is the left face (resp. right face); in this case \(p_l\) and \(p_r\) are also called the left boundary and the right boundary of G, respectively. If f is an internal face, \(p_l\) (resp. \(p_r\)) consists of the edges for which f is the right face (resp. left face).

The dual graph \(G^*\) of a plane st-graph G is a plane st-graph (possibly with multiple edges) such that: (i) \(G^*\) has a vertex associated with each internal face of G and two vertices \(s^*\) and \(t^*\) associated with the outer face of G, that are the source and the sink of \(G^*\), respectively; (ii) for each internal edge e of G, \(G^*\) has a dual edge from the left to the right face of e; (iii) for each edge e in the left boundary of G, there is an edge from \(s^*\) to the right face of e; and (iv) for each edge e in the right boundary of G, there is an edge from the left face of e to \(t^*\).

Fig. 2
figure 2

a A plane st-graph G. b The dual of G is shown in gray. c An embedding-preserving HP-completion of G; the light blue edges form a directed Hamiltonian st-path, and the dashed edges are augmenting edges. d An embedding-preserving \(2\)UBE of G corresponding to (c)

Consider a planar st-graph G and let \({\overline{G}}\) be a planar st-graph obtained by augmenting G with directed edges in such a way that it contains a directed Hamiltonian st-path \(P_{{\overline{G}}}\). The graph \({\overline{G}}\) is an HP-completion of G. Consider now a plane st-graph G and let \({\mathcal {E}}\) be a planar embedding of G. Let \({\overline{G}}\) be an embedded HP-completion of G whose embedding \(\overline{{\mathcal {E}}}\) is such that its restriction to G is \({\mathcal {E}}\). We say that \({\overline{G}}\) is an embedding-preserving HP-completion of G. Bernhart and Kainen [25] prove that an undirected planar graph admits a 2-page book embedding if and only if it is sub-Hamiltonian, i.e., it can be made Hamiltonian by adding edges while preserving its planarity. Theorem 1 is an immediate consequence of the result in [25] for planar digraphs (see also Fig. 2); when we say that a \(2\)UBE \(\langle \pi ,\sigma \rangle \) is embedding-preserving we mean that the drawing \(\Gamma (\pi ,\sigma )\) preserves the planar embedding of G.

Theorem 1

A planar (plane) st-graph G admits a (embedding-preserving) \(2\)UBE \(\langle \pi ,\sigma \rangle \) if and only if G admits an (embedding-preserving) HP-completion \({\overline{G}}\). Also, the order \(\pi \) coincides with the order of the vertices along \(P_{{\overline{G}}}\).

3 NP-Completeness for kUBE (\(k \ge 3\))

In this section, we prove that k UBE Testing, i.e., the problem of deciding whether a digraph G admits an upward k-page book embedding, is NP-complete for each fixed \(k \ge 3\). The proof uses a reduction from the Betweenness problem [83], which is defined as follows:

Betweenness

\(\textit{Instance:}\):

A finite set S of elements and a set \(R \subseteq S \times S \times S\) of triplets.

\(\textit{Question:}\):

Does there exist an ordering \(\tau : S \rightarrow {\mathbb {N}}\) of the elements of S such that for any element \((a,b,c) \in R\) either \(\tau (a)< \tau (b) <\tau (c)\) or \(\tau (c)< \tau (b) < \tau (a)\)?

We incrementally define a set of families of digraphs and prove some properties of these digraphs. Then, we use the digraphs of these families to reduce a generic instance of Betweenness to an instance of 3UBE Testing, thus proving the hardness result for \(k=3\). We then explain how the proof can be easily adapted to work for \(k>3\).

For a digraph G, we denote by \(u \leadsto v\) a directed path from a vertex u to a vertex v in G. Let \(\gamma =\langle \pi , \sigma \rangle \) be a 3UBE of G. Two edges (uv) and (wz) of G conflict if either \(\pi (u)< \pi (w)< \pi (v) < \pi (z)\) or \(\pi (w)< \pi (u)< \pi (z) < \pi (v)\). Two conflicting edges cannot be assigned to the same page. The next property will be used in the following; it is immediate from the definition of book embedding and from the pigeonhole principle.

Property 1

In a 3UBE there cannot exist 4 edges that mutually conflict.

Shell digraphs. The first family that we define are the shell digraphs, recursively defined as follows. Digraph \(G_0\), depicted in Fig. 3a, consists of a directed path P with eight vertices denoted as \(s_0\), \(q_0\), \(p_{-1}\), \(t_{-1}\), \(s'_0\), \(q'_0\), \(t'_0\), and \(p_0\) in the order they appear along P. Besides the edges of P, the following directed edges exists in \(G_0\): \((s_0,s'_0)\), \((q_0,q'_0)\), \((t_{-1},p_0)\). Finally, there is a vertex \(t_0\) connected to P by means of the two directed edges \((p_{-1},t_0)\) and \((t'_0,t_0)\). Graph \(G_h\) is obtained from \(G_{h-1}\) with additional vertices and edges as shown in Fig. 3b. A new directed path of two vertices \(s_h\) and \(q_h\) is connected to \(G_{h-1}\) with the edge \((q_h,s_{h-1})\); a second path of four vertices \(s'_{h}\), \(q'_{h}\), \(t'_{h}\), and \(p_h\) is connected to \(G_h\) with the edge \((t_{h-1},s'_h)\). The following edges exist between these new vertices: \((s_h,s'_h)\), \((q_h,q'_h)\), \((t_{h-1},p_h)\). Finally, there is a vertex \(t_h\) connected to the other vertices by means of the two directed edges \((p_{h-1},t_h)\) and \((t'_h,t_h)\). For any \(h \ge 0\), the edges \((s_h,s'_h)\) and \((q_h,q'_h)\) are called the forcing edges of \(G_h\); the edges \((p_{h-1},t_h)\) and \((t_{h-1},p_h)\) are the channel edges of \(G_h\); the edge \((t'_h,t_h)\) is the closing edge of \(G_h\). The vertices and edges of \(G_h \setminus G_{h-1}\) are the exclusive vertices and edges of \(G_h\). The following lemma establishes basic properties of the shell digraphs.

Fig. 3
figure 3

Definition of shell digraphs

Lemma 1

Every shell digraph \(G_h\) for \(h \ge 0\) admits a 3UBE. In any 3UBE \(\gamma =\langle \pi , \sigma \rangle \) of \(G_h\) the following conditions hold for every \(i=0,1,\dots ,h\):

\(\textsf {S1}\):

all vertices of \(G_i\) are between \(s_i\) and \(t_i\) in \(\pi \);

\(\textsf {S2}\):

the channel edges of \(G_i\) are in the same page;

\(\textsf {S3}\):

if \(i > 0\), the channel edges of \(G_i\) and those of \(G_{i-1}\) are in different pages.

Proof

The proof is by induction on h.

Base case \(h=0\). We describe how to define a 3UBE \(\gamma =\langle \pi , \sigma \rangle \) of \(G_0\). The eight vertices of the directed path \(s_0 \leadsto p_0\) must appear in \(\pi \) in the same order they appear along the path. Consider now \(t_0\). Because of the closing edge \((t'_0,t_0)\), we have \(\pi (t'_0) < \pi (t_0)\). If we put \(t_0\) between \(t'_0\) and \(p_0\), the channel edges \((p_{-1},t_0)\) and \((t_{-1},p_0)\) and the forcing edges \((s_{0},s'_0)\) and \((q_{0},q'_0)\) would mutually conflict. But then a 3UBE would not exist by Property 1. Thus, the only possibility is that \(t_0\) is the last vertex in \(\pi \). This uniquely defines the order \(\pi \) and implies condition S1. As for the page assignment \(\sigma \), the two forcing edges must be in different pages because they conflict. Since each of the two channel edges conflicts with both forcing edges, the channel edges cannot be assigned to the pages used for the forcing edges. Thus, they must be in the same page, which is possible because the two channel edges do not conflict (this proves condition S2). Finally, the closing edge conflicts with the channel edge \((t_{-1},p_0)\) and thus it cannot be in the same page as the channel edges; since however it does not conflict with any other edge it can be assigned to one of the pages used for the forcing edges. This concludes the proof that a 3UBE of \(G_0\) exists and that it must satisfy conditions S1 and S2. Condition S3 does not apply in this case.

Inductive case \(h>0\). By induction, \(G_{h-1}\) admits a 3UBE \(\gamma '=\langle \pi ', \sigma ' \rangle \) that satisfies S1S3. We extend \(\gamma '\) to a 3UBE \(\gamma =\langle \pi , \sigma \rangle \) of \(G_h\) as follows. Since \(\gamma '\) satisfies S1, \(s_{h-1}\) is the first vertex in \(\pi '\) and \(t_{h-1}\) is the last one. The vertices of path \(s_h \leadsto s_{h-1}\) must appear in \(\pi \) in the same order they appear along the path. Analogously, the vertices of \(t_{h-1} \leadsto p_h\) must appear in \(\pi \) in the order they have along the path. Because of the closing edge \((t'_h,t_h)\), we have \(\pi (t'_h) < \pi (t_h)\). Therefore, \(s_h\) must be the first vertex along \(\pi \). Consider now \(t_h\). If we put \(t_h\) between \(t'_h\) and \(p_h\), the channel edges \((p_{h-1},t_h)\) and \((t_{h-1},p_h)\) and the forcing edges \((s_{h},s'_h)\) and \((q_{h},q'_h)\) would mutually conflict. But then a 3UBE would not exist by Property 1. Thus, \(t_h\) must be the last vertex in \(\pi \). This uniquely defines the order \(\pi \) and implies condition S1 for \(G_h\). As for the page assignment \(\sigma \), observe that the only exclusive edge of \(G_h\) that conflicts with some edge of \(G_{h-1}\) is the edge \((p_{h-1},t_h)\), which only conflicts with the channel edge \((p_{h-2},t_{h-1})\) of \(G_{h-1}\). This implies that \((p_{h-1},t_h)\) must be in a page different from the one of \((p_{h-2},t_{h-1})\). The two forcing edges of \(G_h\) must be in a page different from the channel edge \((p_{h-1},t_h)\) and since they conflict, they must be in different pages. The channel edge \((t_{h-1},p_h)\) conflicts with the forcing edges but not with the other channel edge \((p_{h-1},t_h)\). Thus, the channel edges must be in the same page (which proves condition S2). The fact that the page of \((p_{h-1},t_h)\) must be different from that of \((p_{h-2},t_{h-1})\), implies condition S3. Finally, the closing edge conflicts with the channel edge \((t_{h-1},p_h)\) and thus it cannot be in the same page as the channel edges; since however it does not conflict with any other edge, it can be assigned to one of the pages used for the forcing edges. This concludes the proof that a 3UBE of \(G_h\) exists and that it satisfies conditions S1, S2, and S3. \(\square \)

Note that Condition S1 uniquely defines the vertex ordering of \(G_h\) in every 3UBE. Namely, the path \(s_h \leadsto p_0\) precedes each path \(t_{i-1} \leadsto p_i\) (for \(i=1,\dots ,h\)), and each path \(t_{i-1} \leadsto p_i\) precedes the path \(t_{i} \leadsto p_{i+1}\) (for \(i=1,\dots ,h-1\)) (see Fig. 4a for an example with \(h=2\)).

Fig. 4
figure 4

a A 3UBE of the shell digraph \(G_2\); the colors of the edges represent the pages. b Definition of \(H_{h,s}\) for \(h=2\) and \(s=5\)

Filled shell digraphs. Let \(G_h\) be a shell digraph. A filled shell digraph \(H_{h,s}\) (for \(h \ge 0\) and \(s \ge 1\)) is obtained from \(G_h\) by adding \(h+2\) groups \(\alpha _{-1}, \alpha _0, \dots , \alpha _h\) of s vertices each; see Fig. 4b for an illustration. The vertices of group \(\alpha _i\) are denoted as \(v_{i,1}, v_{i,2}, \dots v_{i,s}\). These vertices will be used to map the elements of the set S of an instance of Betweenness to an instance of 3UBE Testing. For each vertex \(v_{-1,j}\) of the set \(\alpha _{-1}\) there is a directed edge \((p_{-1},v_{-1,j})\) and a directed edge \((v_{-1,j},t_{-1})\). For each vertex \(v_{i,j}\) of the set \(\alpha _i\) with \(i \ge 0\) and i even, there is a directed edge \((p_i,v_{i,j})\). Finally, for each vertex \(v_{i,j}\) of the set \(\alpha _i\) with \(i \ge 0\), there is a directed edge \((v_{i-1,j},v_{i,j})\).

Lemma 2

Every filled shell digraph \(H_{h,s}\) for \(s>0\) and even \(h \ge 0\) admits a 3UBE. In any 3UBE \(\gamma =\langle \pi , \sigma \rangle \) of \(H_{h,s}\) the following conditions hold for every \(i=-1,0,1,\dots ,h\):

\(\textsf {F1}\):

the vertices of the group \(\alpha _{i}\) are between \(p_{i}\) and \(t_{i}\) in \(\pi \);

\(\textsf {F2}\):

if \(i \ge 0\) each edge \((v_{i-1,j},v_{i,j})\) is in the page of the channel edges of \(G_i\) (for \(j=1,\dots ,s\));

\(\textsf {F3}\):

if \(i \ge 0\) the vertices of \(\alpha _{i}\) are in reverse order with respect to those of \(\alpha _{i-1}\) in \(\pi \).

Proof

The proof is by induction on h.

Base case \(h=0\). We describe how to define a 3UBE \(\gamma =\langle \pi , \sigma \rangle \) of \(H_{0,s}\). By Lemma 1, every 3UBE of the subgraph \(G_0\) of \(H_{0,s}\) satisfies conditions S1S3.

Let \(v_{-1,j}\) (with \(1 \le j \le s\)) be a vertex of \(\alpha _{-1}\). The edges \((p_{-1},v_{-1,j})\) and \((v_{-1,j},t_{-1})\) imply \(\pi (p_{-1}) < \pi (v_{-1,j})\) and \(\pi (v_{-1,j}) < \pi (t_{-1})\), which proves condition F1 for \(\alpha _{-1}\). Consider now the group \(\alpha _0\); the edge \((p_{0},v_{0,j})\) implies \(\pi (p_{0}) < \pi (v_{0,j})\). On the other hand, if we put \(v_{0,j}\) after \(t_0\), the edge \((v_{-1,j},v_{0,j})\), the channel edge \((p_{-1},t_0)\), and the two forcing edges \((s_0,s'_0)\) and \((q_0,q'_0)\) would mutually conflict. But then a 3UBE would not exist by Property 1. Thus, each vertex of group \(\alpha _0\) must be between \(p_0\) and \(t_0\) in \(\pi \), which implies condition F1 for the group \(\alpha _{0}\). As for the page assignment \(\sigma \), each \((v_{-1,j},v_{0,j})\) conflicts with each forcing edge of \(G_0\), and thus it must be in the page of the channel edges of \(G_0\). This implies condition F2. The edges \((v_{-1,j},v_{0,j})\) can be assigned to the same page only if the vertices of \(\alpha _{-1}\) appear in reverse order with respect to those of \(\alpha _0\) in \(\pi \). Thus, condition F3 holds and a 3UBE of \(H_{0,s}\) can be defined by choosing an arbitrary order for the vertices of \(\alpha _{-1}\) and the reverse order for the vertices of \(\alpha _0\).

Inductive case \(h>0\). Consider the subgraph \(H'_{h,s}\) of \(H_{h,s}\) consisting of \(H_{h-2,s}\) plus the exclusive vertices and edges of \(G_{h-1}\) and of \(G_h\). By induction and by Lemma 1, every 3UBE \(\gamma '=\langle \pi ', \sigma ' \rangle \) of \(H'_{h,s}\) satisfies conditions F1F3 and conditions S1S3. We extend \(\gamma '\) to a 3UBE \(\gamma =\langle \pi , \sigma \rangle \) of \(H_{h,s}\) as follows. By condition F1 of \(\gamma '\), each vertex \(v_{h-2,j}\) is before \(t_{h-2}\) in \(\pi '\); on the other hand, because of the edges \((p_h,v_{h,j})\), each vertex \(v_{h,j}\) must follow \(p_{h}\) in \(\pi \). This implies that each \(v_{h-1,j}\) is between \(p_{h-1}\) and \(t_{h-1}\) in \(\pi \). Indeed, if \(v_{h-1,j}\) was before \(p_{h-1}\) in \(\pi \), the edge \((v_{h-1,j},v_{h,j})\), the channel edge \((p_{h-1},t_h)\) and the two forcing edges of \(G_h\) would mutually conflict and therefore a 3UBE would not exist by Property 1. On the other hand, if \(v_{h-1,j}\) was after \(t_{h-1}\), the edge \((v_{h-2,j},v_{h-1,j})\), the channel edges \((p_{h-2},t_{h-1})\) and the two forcing edges of \(G_{h-1}\) would mutually conflict and again a 3UBE would not exist by Property 1. Thus, each vertex of group \(\alpha _{h-1}\) must be between \(p_{h-1}\) and \(t_{h-1}\), which proves condition F1 for the group \(\alpha _{h-1}\). Consider now a vertex \(v_{h,j}\). If it was after \(t_h\) in \(\pi \), then the edge \((v_{h-1,j},v_{h,j})\), the channel edge \((p_{h-1},t_{h})\) and the two forcing edges of \(G_h\) would mutually conflict – again a 3UBE would not exist by Property 1. Hence, each vertex of \(\alpha _h\) is between \(p_h\) and \(t_h\), which proves condition F1 also for \(\alpha _h\).

As for the page assignment \(\sigma \), each \((v_{h-2,j},v_{h-1,j})\) conflicts with each forcing edge of \(G_{h-1}\) and hence it must be in the page of the channel edges of \(G_{h-1}\). The same argument applies to the edges \((v_{h-1,j},v_{h,j})\) with respect to the forcing edges of \(G_h\). Thus the edges \((v_{h-1,j},v_{h,j})\) must be in the page of the channel edges of \(G_h\), which proves condition F2.

The edges \((v_{h-2,j},v_{h-1,j})\) can be assigned to the same page only if the vertices of \(\alpha _{h-2}\) appear in reverse order with respect to those of \(\alpha _{h-1}\) in \(\pi \). Similarly, the edges \((v_{h-1,j},v_{h,j})\) can be assigned to the same page only if the vertices of \(\alpha _{h-1}\) appear in reverse order with respect to those of \(\alpha _{h}\) in \(\pi \). Thus, condition F3 holds and a 3UBE of \(H_{h,s}\) can be defined by ordering the vertices of \(\alpha _{h-1}\) in reverse order with respect to those of \(\alpha _{h-2}\) and the vertices of \(\alpha _h\) with the same order as those of \(\alpha _{h-2}\). \(\square \)

Observe that, by Condition F3, all groups \(\alpha _i\) with even index have the same ordering in \(\pi \) and all groups with odd index have the opposite order. As mentioned above the vertices in the groups \(\alpha _i\) will correspond to the elements of the set S of an instance of Betweenness in the reduced instance of 3UBE Testing. If the reduced instance admits a 3UBE, the order of the odd-indexed groups in \(\pi \) will give the desired order for the instance of Betweenness.

Fig. 5
figure 5

a A gadget \(\Lambda _i\) (black edges). b The triplet edges of \(G_i\) (bold edges)

\(\mathbf {\Lambda }\)-filled shell digraphs and hardness proof. Starting from a filled shell digraph \(H_{h,s}\), a \(\Lambda \)-filled shell digraph \({\widehat{H}}_{h,s}\) is obtained by replacing some edges with a gadget that has two possible configurations in any 3UBE of \({\widehat{H}}_{h,s}\). More precisely, we replace each edge \((t'_i,p_i)\) of \(H_{h,s}\) for i odd with the gadget shown in Fig. 5a. The gadget replacing \((t'_i,p_i)\) will be denoted as \(\Lambda _i\). Notice that this replacement preserves Conditions F1F3 of Lemma 2.

Lemma 3

Every \(\Lambda \)-filled shell digraph\({\widehat{H}}_{h,s}\) for \(s>0\) and even \(h \ge 0\) admits a 3UBE. In any 3UBE \(\gamma =\langle \pi , \sigma \rangle \) of \({\widehat{H}}_{h,s}\) the following conditions hold for every odd \(i=1,3,\dots ,h-1\):

\(\textsf {G1}\):

the vertices of the gadget \(\Lambda _{i}\) are between \(t'_{i}\) and \(p_{i}\) in \(\pi \);

\(\textsf {G2}\):

the vertices \(x_{i}\) and \(y_{i}\) are between \(w_{i}\) and \(z_{i}\) in \(\pi \) and there exists a 3UBE \(\gamma '=\langle \pi ', \sigma ' \rangle \) of \({\widehat{H}}_{h,s}\) where the order of \(x_i\) and \(y_i\) is exchanged in \(\pi '\).

Proof

By Lemma 2, every 3UBE \(\gamma '=\langle \pi ',\sigma '\rangle \) of \(H_{h,s}\) is such that \(t'_{i}\) and \(p_{i}\) are consecutive in \(\pi '\) for each \(i=0,1,\dots ,h\). Notice that the gadget \(\Lambda _{i}\) admits a 3UBE (actually a 2UBE) \(\gamma _{i}\). If we replace the edge \((t'_{i},p_{i})\) with \(\gamma _{i}\), we do not create any conflict between the edges of \(\Lambda _i\) and the other edges of \(H_{h,s}\). This proves that \({\widehat{H}}_{h,s}\) has a 3UBE.

About condition G1, observe that since any vertex of the gadget \(\Lambda _{i}\) belongs to a directed path from \(t'_{i}\) to \(p_{i}\), then the vertices of \(\Lambda _{i}\) must be between \(t'_{i}\) and \(p_{i}\). About condition G2, observe that \(x_{i}\) and \(y_{i}\) both appear in a directed path from \(w_{i}\) to \(z_{i}\) and therefore they must be between \(w_i\) and \(z_i\). Also, suppose that \(\pi (x_i) < \pi (y_i)\) (the other case is symmetric). If we exchange the order of \(x_i\) and \(y_i\) in \(\pi '\) we introduce a conflict between \((w_i,x_i)\) and \((y_i,z_i)\), which do not conflict with any other edges. If they are in the same page in \(\gamma \) it is sufficient to change the page of one of them in \(\gamma '\). \(\square \)

Fig. 6
figure 6

A 3UBE of the st-graph \(G_I\) reduced from a positive instance \(I=\langle S,R\rangle \) of Betweenness; the edge colors represent the corresponding pages

Theorem 2

3UBE Testing is NP-complete even for st-graphs.

Proof

3UBE Testing is clearly in NP. To prove the hardness we describe a reduction from Betweenness. From an instance \(I=\langle S, R \rangle \) of Betweenness we construct an instance \(G_I\) of 3UBE Testing that is an st-graph; we start from the \(\Lambda \)-filled shell digraph\({\widehat{H}}_{h,s}\) with \(h=2 |R |\) and \(s=|S |\). Let \(v_1,v_2,\dots ,v_s\) be the elements of S. They are represented in \({\widehat{H}}_{h,s}\) by the vertices \(v_{i,1},v_{i,2},\dots ,v_{i,s}\) of the groups \(\alpha _i\), for \(i=-1,0,1,\dots ,h\). In the reduction each group \(\alpha _i\) with odd index is used to encode one triplet and, in a 3UBE of \(G_I\), the order of the vertices in these groups (which is the same by condition F3) corresponds to the desired order of the elements of S for the instance I. Number the triplets of R from 1 to \(|R |\) and let \((v_a,v_b,v_c)\) be the j-th triplet. We use the group \(\alpha _{i}\) and the gadget \(\Lambda _{i}\) with \(i=2j-1\) to encode the triplet \((v_a,v_b,v_c)\). More precisely, we add to \({\widehat{H}}_{h,s}\) the edges \((x_{i},v_{i,a})\), \((x_{i},v_{i,b})\), \((y_{i},v_{i,b})\), and \((y_{i},v_{i,c})\) (see Fig. 5b). These edges are called triplet edges and are denoted as \(T_i\). We will show that in any 3UBE of \(G_I\) the triplet edges are forced to be in the same page and this is possible if and only if the constraints defined by the triplets in R are respected. The digraph obtained by the addition of the triplet edges is not an st-graph because the vertices of the last group \(\alpha _{h}\) are all sinks. The desired instance \(G_I\) of 3UBE Testing is the st-graph obtained by adding the edges \((v_{h,j},t_h)\) (for \(j=1,2,\dots ,s\)). Fig. 6 shows a 3UBE of the st-graph \(G_I\) reduced from a positive instance I of Betweenness.

We now show that I is a positive instance of Betweenness if and only if the st-graph \(G_I\) constructed as described above admits a 3UBE. Suppose first that I is a positive instance of Betweenness, i.e., there exists an ordering \(\tau \) of S that satisfies all triplets in R. The subgraph \({\widehat{H}}_{h,s}\) of \(G_I\) admits a 3UBE that satisfies conditions S1S3, F1F3, and G1G2 by Lemmas 1,2 and 3. Observe that the order of the vertices of the groups \(\alpha _i\) can be arbitrarily chosen (provided that all groups with even index have the same order and the groups with odd index have the reverse order). Thus we can choose the order of the groups with odd index to be equal to \(\tau \). Let \(\gamma =\langle \pi , \sigma \rangle \) be the resulting 3UBE of \({\widehat{H}}_{h,s}\). We now show that if we add the triplet edges to \(\gamma \), these edges do not conflict. Let \((v_a,v_b,v_c)\) be the triplet encoded by the triplet edges \(T_i\) and suppose that \(\tau (v_a)< \tau (v_b) < \tau (v_c)\) (the other case is symmetric). Since the vertices of the groups with odd index are ordered in \(\pi \) as in \(\tau \), we have \(\pi (v_{i,a})< \pi (v_{i,b}) < \pi (v_{i,c})\). If \(\pi (x_i) < \pi (y_i)\) then the edges \(T_i\) do not conflict. If otherwise \(\pi (y_i) < \pi (x_i)\), by condition G2 we can exchange the order of \(x_i\) and \(y_i\), thus guaranteeing again that the triplet edges \(T_i\) do not conflict. On the other hand, the triplet edges \(T_i\) conflict with the edges \(E^{\Lambda }_i\) of \(\Lambda _i\), with the channel edges \(E^{ch}_i\) of \(G_i\), and with all the edges \(E^{\alpha }_i\) connecting group \(\alpha _{i-1}\) to group \(\alpha _{i}\). All the edges in \(E^{\Lambda }_i \cup E^{ch}_i \cup E^{\alpha }_i\) can be assigned to only two pages. Indeed, the edges \(E^{\Lambda }_i\) require two pages, while one page is enough for the edges of \(E^{ch}_i \cup E^{\alpha }_i\). Also, since the edges of \(E^{\Lambda }_i\) do not conflict with those in \(E^{ch}_i \cup E^{\alpha }_i\), two pages suffice for all of them. Hence, the triplet edges \(T_i\) can all be assigned to the third page. Since this is true for all the triplet edges, \(G_I\) admits a 3UBE.

Suppose now that \(G_I\) admits a 3UBE \(\gamma =\langle \pi ,\sigma \rangle \). By Lemmas 1,2 and 3, \(\gamma \) satisfies conditions S1S3, F1F3, and G1G2 . By condition F2 the order of the vertices of the groups \(\alpha _i\) with odd index is the same for all groups. We claim that all triplets in R are satisfied if this order is used as the order \(\tau \) for the elements of S. Let \((v_a,v_b,v_c)\) be the triplet encoded by the triplet edges \(T_i\). By condition G2, the vertices \(x_i\) and \(y_i\) of the gadget \(\Lambda _i\) are between \(w_i\) and \(z_i\) in \(\pi \). Thus the triplet edges \(T_i\) conflict with the edges \((u_i,z_i)\) and \((w_i,p_i)\). These two edges must be in two different pages because they conflict. It follows that the triplet edges \(T_i\) must all be in the same page, i.e., the third one. Since the three edges of \(T_i\) are in the same page we have either \(\pi (x_i) < \pi (y_i)\) and \(\pi (v_{i,a})< \pi (v_{i,b}) < \pi (v_{i,c})\) or \(\pi (y_i) < \pi (x_i)\) and \(\pi (v_{i,c})< \pi (v_{i,b}) < \pi (v_{i,a})\) (any other order would cause a crossing between the edges of \(T_i\)). In both cases vertex \(v_{i,b}\) is between \(v_{i,a}\) and \(v_{i,c}\), i.e., \(v_b\) is between \(v_a\) and \(v_c\) in \(\tau \). Since this is true for all triplets, I is a positive instance of Betweenness. \(\square \)

For \(k>3\), the reduction from an instance I of Betweenness to an instance \(G_I\) of k UBE Testing is similar. In the shell digraph every pair of forcing edges is replaced by a bundle of \(k-1\) edges that mutually conflict (see Fig. 7a). The edges in each bundle require \(k-1\) pages and force all edges that conflict with them to use the k-th page. Analogously, the two edges \((u_i,z_i)\) and \((w_i,p_i)\) of the gadget \(\Lambda _i\) are replaced by a bundle of \(k-1\) edges that mutually conflict (see Fig. 7b); this forces the triplet edges to be in the k-th page. Finally, observe that our reduction does not work for \(k=2\), as it would yield an instance of 2UBE that never admits a book embedding on two pages, i.e., it is always a negative instance.

Corollary 1

k UBE Testing is NP-complete for every \(k \ge 3\), even for st-graphs.

Fig. 7
figure 7

Reduction for k UBE Testing (example with \(k=5\)). a Replacement of the forcing edges. b Replacement of the gadget \(\Lambda _i\). In both figures colors represent the pages

4 Existential Results for 2UBE

Let f be an internal face of a plane st-graph, and let \(p_l\) and \(p_r\) be the left and the right path of f; f is a generalized triangle if either \(p_l\) or \(p_r\) is a single edge (i.e., a transitive edge), and it is a rhombus if each of \(p_l\) and \(p_r\) consists of exactly two edges (see Figs. 8a and 8b).

Let G be a plane st-graph. A forbidden configuration of G consists of a transitive edge \(e=(u,v)\) shared by two internal faces f and g such that \(s_f=s_g=u\) and \(t_f=t_g=v\) (i.e., two generalized triangles sharing the transitive edge); see Fig. 8c. The absence of forbidden configurations is necessary for the existence of an embedding-preserving \(2\)UBE. If G is triangulated, the absence of forbidden configurations is also a sufficient condition [81].

Fig. 8
figure 8

a A generalized triangle G. b A rhombus c A forbidden configuration

Theorem 3

Any plane st-graph such that the left and the right path of every internal face contain at least two and three edges, respectively, admits an embedding-preserving \(2\)UBE.

Proof

Let G be a plane st-graph such that the left and the right path of every internal face contain at least two and three edges, respectively. We prove how to construct an embedding preserving HP-completion. The idea is to construct \({\overline{G}}\) by adding a face of G per time from left to right. Namely, the faces of G are added according to a topological ordering of the dual graph of G. When a face f is added, its right path is attached to the right boundary of the current digraph. We maintain the invariant that at least one edge e in the left path of f belongs to the Hamiltonian path of the current digraph. The Hamiltonian path is extended by replacing e with a path that traverses the vertices of the right path of f. To this aim, dummy edges are suitably inserted inside f. When all faces are added, the resulting graph is an HP-completion \({\overline{G}}\) of G.

More precisely, let N be the number of internal faces of G, and let \(G^*\) be the dual graph of G. Let \(s^*=f_0,f_1,\dots ,f_N,f_{N+1}=t^*\) be a topological ordering of \(G^*\). Denote by \(G_0\) the left boundary of G and by \(G_i\), for \(i=1,2,\dots ,N\), the subgraph of G consisting of the faces \(f_1,f_2,\dots ,f_i\). \(G_i\) can be obtained by adding the right path \(p^i_r\) of face \(f_i\) to \(G_{i-1}\). We construct a sequence \({\overline{G}}_0, {\overline{G}}_1,\dots , {\overline{G}}_N\) of st-graphs such that \({\overline{G}}_i\) is an HP-completion of \(G_i\). Clearly, \({\overline{G}}_N\) will be an HP-completion of G. While constructing the sequence, we maintain the following invariant: given any two consecutive edges along the right boundary of \({\overline{G}}_i\), at least one of them belongs to the Hamiltonian path \(P_{{\overline{G}}_i}\) of \({\overline{G}}_i\). \({\overline{G}}_0\) coincides with \(G_0\) and all its edges are in \(P_{{\overline{G}}_0}\), so the invariant holds. Suppose then that \({\overline{G}}_{i-1}\), with \(i>1\), satisfies the invariant. To construct \({\overline{G}}_i\) we must add the right path \(p^i_r\) of \(f_i\) plus possibly some dummy edges inside \(f_i\). Let \(s_f=v_0,v_1,v_2,\dots ,v_{k-1},t_f=v_k\) be the right path \(p^i_r\) of \(f_i\) and let \(s_f=u_0,u_1,u_2,\dots ,u_{h-1},t_f=u_h\) be the left path \(p^i_l\) of \(f_i\). By hypothesis \(p^i_r\) has at least three edges, and therefore \(k \ge 3\); moreover, since G has no transitive edge, \(h\ge 2\). Notice that \(p^i_l\) is a subpath of the right boundary of \({\overline{G}}_{i-1}\) and that the right boundary of \({\overline{G}}_i\) is obtained from the right boundary of \({\overline{G}}_{i-1}\) by replacing \(p^i_l\) with \(p^i_r\). Let \((u_{-1},s_f)\) be the edge along the right boundary of \({\overline{G}}_{i-1}\) entering \(s_f\) and let \((t_f,u_{h+1})\) be the edge along the right boundary of \({\overline{G}}_{i-1}\) exiting \(t_f\); each of these edges may not exist if \(s_f=s\) or \(t_f=t\). We have different cases depending on whether \((s_f,u_1)\) and \((u_{h-1},t_f)\) belong to \(P_{{\overline{G}}_{i-1}}\) or not.

Fig. 9
figure 9

Illustration for Theorem 3: a, b Case 1; c, d Case 2; e, f Case 4

Case 1: neither \((s_f,u_1)\) nor \((u_{h-1},t_f)\) belong to \(P_{{\overline{G}}_{i-1}}\). See Fig. 9 for an illustration. By the invariant there is an edge \((u_j,u_{j+1})\) with \(0 \le j \le h-1\) between \(s_f\) and \(t_f\) that belongs to \(P_{{\overline{G}}_{i-1}}\). We add the two dummy edges \((u_j,v_1)\) and \((v_{k-1},u_{j+1})\), thus “extending” \(P_{{\overline{G}}_{i-1}}\) to a Hamiltonian path \(P_{{\overline{G}}_{i}}\) of \({\overline{G}}_i\); namely, the edge \((u_j,u_{j+1})\) is bypassed by the path \(u_j,v_1,v_2,\dots ,v_{k-1},u_{j+1}\). The only edges of \(p^i_r\) that do not belong to \(P_{{\overline{G}}_{i}}\) are \((s_f,v_1)\) and \((v_{k-1},t_f)\). If \((u_{-1},s_f)\) exists, then by the invariant it belongs to \(P_{{\overline{G}}_{i-1}}\) (because \((s_f,u_1)\) does not) and thus the invariant is preserved for \((s_f,v_1)\) and its preceding and following edges. Analogously, if \((t_f,u_{h+1})\) exists, then by the invariant it belongs to \(P_{{\overline{G}}_{i-1}}\) and thus the invariant is preserved for \((v_{k-1},t_f)\) and its preceding and following edges.

Case 2: \((s_f,u_{1})\) does not belong to \(P_{{\overline{G}}_{i-1}}\),while \((u_{h-1},t_f)\)does. See Fig. 9 for an illustration. We add the dummy edge \((u_{h-1},v_1)\). This“extends” \(P_{{\overline{G}}_{i-1}}\) to \(P_{{\overline{G}}_{i}}\) of \({\overline{G}}_i\) bypassing the edge \((u_{h-1},t_f)\) with the path \(u_{h-1},v_1,v_2,\dots ,v_{k-1},t_f\). The only edge of \(p^i_r\) that does not belong to \(P_{{\overline{G}}_{i}}\) is \((s_f,v_1)\). If \((u_{-1},s_f)\) exists, then by the invariant it belongs to \(P_{{\overline{G}}_{i-1}}\) (because \((s_f,u_1)\) does not) and thus the invariant is preserved for \((s_f,v_1)\) and its preceding and following edges.

Case 3: \((s_f,u_{1})\) belongs to \(P_{{\overline{G}}_{i-1}}\), while \((u_{h-1},t_f)\) does not. This case is symmetric to the previous one.

Case 4: both \((s_f,u_1)\)and \((u_{h-1},t_f)\) belong to \(P_{{\overline{G}}_{i-1}}\). See Fig. 9 for an illustration. We add the two dummy edges \((v_{k-2},u_1)\) and \((u_{h-1},v_{k-1})\). In this case we “extend” \(P_{{\overline{G}}_{i-1}}\) to \(P_{{\overline{G}}_{i}}\) bypassing \((s_f,u_{1})\) with the path \(s_f,v_1,\dots ,v_{k-2}\) and bypassing the edge \((u_{h-1},t_f)\) with the path \(u_{h-1}, v_{k-1}, t_f\). The only edge of \(p^i_r\) that does not belong to \(P_{{\overline{G}}_{i}}\) is \((v_{k-2},v_{k-1})\); moreover, all the edges \((s_f,v_1), (v_1,v_2), \dots , (v_{k-3},v_{k-2})\) and the edge \((v_{k-1},t_f)\) belong to \(P_{{\overline{G}}_{i}}\). Thus the invariant is preserved. \(\square \)

The next theorem is proved with a construction similar to that of Theorem 3.

Theorem 4

Let G be a plane st-graph such that every internal face of G is a rhombus. Then G admits an embedding-preserving \(2\)UBE.

Proof

During the construction of \({\overline{G}}_i\) from \({\overline{G}}_{i-1}\), we maintain the same invariant as in Theorem 3. If all faces are rhombi, when we construct \({\overline{G}}_i\) from \({\overline{G}}_{i-1}\), we have that \(p^i_l\) is a path \(s_f,u_1,t_f\) and \(p^i_r\) is a path \(s_f,v_1,t_f\). At least one of \((s_f,u_1)\) and \((u_1,t_f)\) belongs to \(P_{{\overline{G}}_{i-1}}\). If \((s_f,u_1)\) belongs to \(P_{{\overline{G}}_{i-1}}\) we add the dummy edge \((v_1,u_1)\). In this case we bypass the edge \((s_f,u_1)\) with the path \(s_f,v_1,u_1\). If \((u_1,t_f)\) belongs to \(P_{{\overline{G}}_{i-1}}\) we add the dummy edge \((u_1,v_1)\). In this case we bypass the edge \((u_1,t_f)\) with the path \(u_1,v_1,t_f\). In both cases it is easy to see that the invariant is maintained. \(\square \)

5 Testing 2UBE for Plane Graphs with Special Faces

By Theorem 3, if all internal faces of a plane st-graph G are such that their left and right path contain at least two and at least three edges, respectively, G admits an embedding-preserving \(2\)UBE. If these conditions do not hold, an embedding-preserving \(2\)UBE may not exist (see Fig. 10a). We now describe an efficient testing algorithm for a plane st-graph \(G=(V,E)\) whose internal faces are generalized triangles or rhombi (see Fig. 10b). We construct a mixed graph \(G_M=(V,E \cup E_U)\), where \(E_U\) is a set of undirected edges and \((u,v) \in E_U\) if u and v are the two vertices of a rhombus face f distinct from \(s_f\) and \(t_f\) (blue edges in Fig. 10c). For a rhombus face f, the graph obtained from G by adding the directed edge (uv) inside f is still a plane st-graph (see, e.g. [22, 41]). Since there is only one edge of \(E_U\) inside each rhombus face of G, the following holds.

Property 2

Every orientation of the edges in \(E_U\) transforms \(G_M\) into an acyclic digraph.

Fig. 10
figure 10

a A plane st-graph that does not admit a \(2\)UBE [82]. b A plane st-graph G whose faces are generalized triangles or rhombi. b The mixed graph \(G_M=(V,E,E_U)\)

Theorem 5

Let G be a plane st-graph such that every internal face of G is either a generalized triangle or a rhombus. There is an O(n)-time algorithm that decides whether G admits an embedding-preserving \(2\)UBE, and which computes it in the positive case.

Proof

The edges of \(E_U\) are the only edges that can be used to construct an embedding-preserving HP-completion of G. This, together with Theorem 1, implies that G admits a \(2\)UBE if and only if the undirected edges of \(G_M\) can be oriented so that the resulting digraph \(\overrightarrow{G_M}\) has a directed Hamiltonian path from s to t. By Property 2, any orientation of the undirected edges of \(G_M\) gives rise to an acyclic digraph. On the other hand an acyclic digraph is Hamiltonian if and only if it is unilateral (see, e.g. [6, Theorem 4]); we recall that a digraph is unilateral if each pair of vertices is connected by a directed path (in at least one of the two directions) [80]. Testing whether the undirected edges of \(G_M\) can be oriented so that the resulting digraph \(\overrightarrow{G_M}\) is unilateral, and computing such an orientation if it exists, can be done in time \(O(|V |+ |E |+ |E_U |) = O(n)\) [80, Theorem 4]. A Hamiltonian path of \(\overrightarrow{G_M}\) is given by a topological ordering of its vertices. \(\square \)

6 Testing Algorithms for 2UBE Parameterized by the Branchwidth

In this section, we show that the 2UBE Testing problem is fixed-parameter tractable with respect to the branchwidth of the input st-graph both in the fixed and in the variable embedding setting. Since the treewidth tw(G) and the branchwidth bw(G) of a graph G are within a constant factor from each other (i.e., \(bw(G) - 1 \le tw(G) \le \lfloor \frac{3}{2}bw(G) \rfloor -1\) [86]), our FPT algorithm also extends to graphs of bounded treewidth.

We use the SPQR-tree data structure [43] to efficiently handle the planar embeddings of the input digraphs, and sphere-cut decompositions [87] to develop a dynamic-programming approach on the skeletons of the rigid components.

Before presenting the testing algorithm (Subsection 6.3), we briefly recall the definition of the SPQR-tree \({\mathcal {T}}\) of a biconnected graph (Subsection 6.1) and the definitions of branchwidth and sphere-cut decomposition (Subsection 6.2).

6.1 SPQR-trees of Planar \(\textbf{st}\)-Graphs

Fig. 11
figure 11

a A biconnected planar st-graph G, where s and t are labeled 1 and 14, respectively. b The SPQR-tree of G with respect to the edge (st); for each S-, P-, or R-node of the tree, the figure depicts the skeleton of the node. In a, the left and the right outer face of the S-node with poles 8 and 13 are yellow and green, respectively

Let G be a biconnected graph. An SPQR-tree \({\mathcal {T}}\) of G is a tree-like data structure that represents the decomposition of G into its triconnected components, which can be computed in linear time [43, 65, 71]. See Fig. 11 for an illustration. Each node \(\mu \) of \({\mathcal {T}}\) of degree greater than one corresponds to a triconnected component of G (as defined in [71]) and has two special vertices, called poles. Namely, let \(\mu \) be a node of \({\mathcal {T}}\) of degree greater than one, and let u and v be its poles; \(\mu \) is associated with a multigraph \({{\,\textrm{skel}\,}}(\mu )\), called the skeleton of \(\mu \). The multigraph \({{\,\textrm{skel}\,}}^+(\mu )\) obtained by adding an edge (uv) to \({{\,\textrm{skel}\,}}(\mu )\) describes the triconnected component corresponding to \(\mu \). Node \(\mu \) is either an R-node, an S-node, or a P-node, based on the following cases:

  • R-node: If \({{\,\textrm{skel}\,}}^+(\mu )\) is triconnected;

  • S-node: If \({{\,\textrm{skel}\,}}^+(\mu )\) is a cycle of length at least three;

  • P-node: If \({{\,\textrm{skel}\,}}^+(\mu )\) is a bundle of at least three parallel edges;

Also, for each edge of G, there is a corresponding node in T having degree one, which is called a Q-node. If \(\mu \) is a Q-node that corresponds to an edge e, the poles of \(\mu \) coincide with the end-vertices of e, and \({{\,\textrm{skel}\,}}(\mu )\) coincides with e.

A virtual edge \(e_\nu \) in \({{\,\textrm{skel}\,}}(\mu )\) corresponds to a tree node \(\nu \) adjacent to \(\mu \) in \({\mathcal {T}}\). In the following, we will regard \({{\mathcal {T}}}\) as rooted at an arbitrary Q-node \(\rho \). The edge e of G corresponding to \(\rho \) is the reference edge of G, and \({\mathcal {T}}\) is the SPQR-tree of G with respect to e. For every node \(\mu \) of \({\mathcal {T}}\), the edges corresponding to the leaves (i.e., the Q-nodes) of the subtree \({\mathcal {T}}_\mu \) of \({\mathcal {T}}\) rooted at \(\mu \) induce a subgraph \({{\,\textrm{pert}\,}}({\mu })\) of G, called the pertinent graph of \(\mu \). The graph \({{\,\textrm{pert}\,}}({\mu })\) is described by \({\mathcal {T}}_\mu \) in the decomposition.

If G is planar, the SPQR-tree \({\mathcal {T}}\) of G with respect to e implicitly describes all planar embeddings of G in which e is incident to the outer face. All such embeddings are obtained by combining the different planar embeddings of the skeletons of P- and R-nodes: For a P-node \(\mu \), the different embeddings of \({{\,\textrm{skel}\,}}(\mu )\) are the different permutations of its edges. If \(\mu \) is an R-node, \({{\,\textrm{skel}\,}}(\mu )\) has two possible planar embeddings, obtained by flipping \({{\,\textrm{skel}\,}}(\mu )\) at its poles. Let \(\mu \) be a node of \({\mathcal {T}}\), let \({\mathcal {E}}\) be an embedding of G, let \({\mathcal {E}}_\mu \) be the embedding \({{\,\textrm{pert}\,}}({\mu })\) in \({\mathcal {E}}\), and let \(f^{O}_\mu \) be the outer face of \({\mathcal {E}}_\mu \). The path along \(f^{O}_\mu \) between \(s_\mu \) and \(t_\mu \) that leaves \(f^{O}_\mu \) to its left (resp. to its right) when traversing the boundary of \(f^{O}_\mu \) from \(s_\mu \) to \(t_\mu \) is the left outer path (resp. the right outer path) of \({\mathcal {E}}_\mu \). The left (resp., right) outer face of \({\mathcal {E}}_\mu \) is the face of \({\mathcal {E}}\), not belonging to \({\mathcal {E}}_\mu \), that is incident to the left (resp., to the right) outer path of \({\mathcal {E}}_\mu \). In Fig. 11a, the left and the right outer face of the S-node with poles 8 and 13 are yellow and green, respectively.

To ease the description, we can assume that each S-node has exactly two children [51]. In particular, we will exploit the following property of \({\mathcal {T}}\) when G is an st-graph containing the edge \(e=(s,t)\) and \({\mathcal {T}}\) is rooted at the Q-node of e.

Property 3

[43] Let \(\mu \) be a node of \({\mathcal {T}}\) with poles u and v. We have that \({{\,\textrm{pert}\,}}({\mu })\) is either a uv-graph or a vu-graph.

6.2 Branch decomposition and sphere-cut decomposition

A branch decomposition \(\langle T,\xi \rangle \) of a graph G consists of an unrooted binary tree T (i.e., each internal node of T has degree three) and of a bijection \(\xi : {\mathcal {L}}(T) \leftrightarrow E(G)\) between the leaf set \({\mathcal {L}}(T)\) of T and the edge set E(G) of G. For each arc a of T, let \(T^a_1\) and \(T^a_2\) be the two connected components of \(T-a\), and, for \(i=1,2\), let \(G^a_i\) be the subgraph of G that consists of the edges corresponding to the leaves of \(T^a_i\), i.e., the edge set \(\{\xi (\mu ):\mu \in {\mathcal {L}}(T) \cap V(T^a_i)\}\). The middle set \({{\,\textrm{mid}\,}}(a) \subseteq V (G)\) is the intersection of the vertex sets of \(G^a_1\) and \(G^a_2\), i.e., \({{\,\textrm{mid}\,}}(a) := V(G^a_1) \cap V(G^a_2)\). The width \({{\,\mathrm{\beta }\,}}(\langle T,\xi \rangle )\) of \(\langle T,\xi \rangle \) is the maximum size of the middle sets over all arcs of T, i.e., \({{\,\mathrm{\beta }\,}}(\langle T,\xi \rangle ) := \max \{|{{\,\textrm{mid}\,}}(a) |: a \in E(T)\}\). An optimal branch decomposition of G is a branch decomposition with minimum width; this width is called the branchwidth of G and is denoted by \({{\,\mathrm{\beta }\,}}= bw(G)\).

Let \(\Sigma \) be a sphere. A \(\Sigma \)-plane graph G is a planar graph G embedded (i.e., topologically drawn) on \(\Sigma \). A noose of a \(\Sigma \)-plane graph G is a closed simple curve on \(\Sigma \) that (i) intersects G only at vertices and (ii) traverses each face at most once.

The length of a noose O is the number of vertices it intersects. Every noose O bounds two closed discs \(\Delta ^1_O\) and \(\Delta ^2_O\) in \(\Sigma \), i.e., \(\Delta ^1_O \cap \Delta ^2_O= O\) and \(\Delta ^1_O \cup \Delta ^2_O=\Sigma \).

Let G be a \(\Sigma \)-plane graph and let \(\langle T,\xi \rangle \) be a branch decomposition of G. Suppose that, for each arc a of T, there exists a noose \(O_a\) that traverses all and only the vertices of \({{\,\textrm{mid}\,}}(a)\) and whose closed discs \(\Delta ^1_{O_a}\) and \(\Delta ^2_{O_a}\) enclose the drawing of \(G^a_1\) and of \(G^a_2\), respectively. Denote by \(\pi _a\) the circular order of the vertices in \({{\,\textrm{mid}\,}}(a)\) as they appear along \(O_a\) and by \(\Pi =\{\pi _a: a \in E(T)\}\) the set of all the circular orders \(\pi _a\). The triple \(\langle T,\xi ,\Pi \rangle \) is a sphere-cut decomposition of G. A clockwise traversal of \(O_a\) in the drawing of G defines the cyclic ordering \(\pi _a\) of \({{\,\textrm{mid}\,}}(a)\). We always assume that the vertices of each middle set \({{\,\textrm{mid}\,}}(a) = V(G^a_1) \cap V(G^a_2)\) are enumerated according to \(\pi _a\). Observe that, Condition II of the definition of noose implies that, for any arc \(a \in E(T)\), the graphs \(G^a_1\) and \(G^a_2\) are both connected. Also, the nooses are pairwise non-crossing, i.e., for any two nooses \(O_a\) and \(O_b\), it holds that \(O_b\) lies either entirely inside \(\Delta ^1_{O_a}\) or entirely inside \(\Delta ^2_{O_a}\). We will exploit the following result by Dorn et al [52, Theorem 1].

Theorem 6

[52] Let G be a connected n-vertex \(\Sigma \)-plane graph having branchwidth \({{\,\mathrm{\beta }\,}}\) and no vertex of degree one. There exists a sphere-cut decomposition of G having width \({{\,\mathrm{\beta }\,}}\) which can be constructed in \(O(n^3)\) time.

6.3 Algorithm description

Without loss of generality, we assume that the input st-graph G contains the edge (st), which guarantees that G is biconnected. In fact, in any \(2\)UBE of G vertices s and t have to be the first and the last vertex of the spine, respectively. Thus, either (st) is an edge of G or it can be added to any of the two pages of a \(2\)UBE of G to obtain a \(2\)UBE \(\langle \pi ,\sigma \rangle \) of \(G \cup (s,t)\). Clearly, the edge (st) will be incident to the outer face of \(\Gamma (\pi ,\sigma )\).

Overview. Our approach builds upon a classification of the embeddings of each triconnected component of the biconnected graph G. Intuitively, such a classification is based on the visibility of the spine that the embedding “leaves” on its outer face. Let \({{\mathcal {T}}}\) be the SPQR-tree of G with respect to the reference edge (st). For any node \(\mu \) of \({{\mathcal {T}}}\), we show that the planar embeddings of \({{\,\textrm{pert}\,}}({\mu })\) that yield a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\) can be partitioned into a finite number of equivalence classes, called embedding types. By visiting \({\mathcal {T}}\) bottom-up, we describe how to compute all the realizable embedding types of the pertinent graph of each node, that is, those embedding types that are allowed by some \(2\)UBE of it. To this aim we will exploit the realizable embedding types of the pertinent graphs of its children. If there exists at least one embedding type that is realizable by the pertinent graph of the unique child of the root of \({\mathcal {T}}\), which coincides with the whole graph G minus the edge (st), then G admits a \(2\)UBE. The most challenging part of this approach is handling the triconnected components that correspond to the P-nodes, where the problem is reduced to a maximum flow problem on a capacitated flow network with edge demands, and to the R-nodes, where a sphere-cut decomposition of bounded width is used to efficiently compute the feasible embedding types.

Embedding Types Given a \(2\)UBE \(\langle \pi , \sigma \rangle \), the two pages will be called the left page (the one to the left of the spine) and the right page (the one to the right of the spine), respectively. We write \(\sigma (e)=L\) (resp. \(\sigma (e)=R\)) if the edge e is assigned to the left page (resp. to the right page). A point p of the spine is visible from the left (right) page if it is possible to shoot a horizontal ray originating from p and directed leftward (rightward) without intersecting any edge in \(\Gamma (\pi , \sigma )\).

Let \(\mu \) be a node of the SPQR-tree \({{\mathcal {T}}}\) of G rooted at (st). Recall that, by Property 3, since \({{\mathcal {T}}}\) has been rooted at (st), the pertinent graph \({{\,\textrm{pert}\,}}({\mu })\) and the skeleton \({{\,\textrm{skel}\,}}(\mu )\) of \(\mu \) are \(s't'\)-graphs, where \(s'\) and \(t'\) are the poles of \(\mu \) . We denote by \(s_\mu \) (\(t_\mu \)) the pole of \(\mu \) that is the source (resp. the sink) of \({{\,\textrm{pert}\,}}({\mu })\) and of \({{\,\textrm{skel}\,}}(\mu )\). Let \(\langle \pi _\mu , \sigma _\mu \rangle \) be a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\). In the following we use the symbols L, R, N, and B as abbreviations for left, right, none, and both, respectively. We say that \(\langle \pi _\mu , \sigma _\mu \rangle \) has embedding type (for short, has Type or is of Type) \(\langle s\_{vis}, spine\_{vis},t\_{vis}\rangle \), with \(s\_{vis},t\_{vis} \in \{L,R,N\}\) and \(spine\_{vis} \in \{L,R,B,N\}\), where:

  1. 1.

    \(s\_{vis}\) is L (resp., R), if in \(\Gamma (\pi _\mu , \sigma _\mu )\) there is a portion of the spine incident to s and between s and t that is visible from the left page (resp., from the right page). If \(s\_{vis}\) is neither L nor R, then \(s\_{vis}\) is N.

  2. 2.

    \(t\_{vis}\) is L (resp., R), if in \(\Gamma (\pi _\mu , \sigma _\mu )\) there is a portion of the spine incident to t and between s and t that is visible from the left page (resp., from the right page). If \(t\_{vis}\) is neither L nor R, then \(t\_{vis}\) is N.

  3. 3.

    \(spine\_{vis}\) is L (resp., R), if in \(\Gamma (\pi _\mu , \sigma _\mu )\) there is a portion of the spine between s and t that is visible from the left page (resp., from the right page); \(spine\_{vis}\) is B, if in \(\Gamma (\pi _\mu , \sigma _\mu )\) there is a portion of the spine between s and t that is visible from the left page, and a portion of the spine between s and t that is visible from the right page. If \(spine\_{vis}\) is neither L, nor R, nor B, then \(spine\_{vis}\) is N.

Further, we say that a node \(\mu \) and \({{\,\textrm{pert}\,}}({\mu })\) admit embedding type (for short, admit Type) \(\langle s\_{vis}, spine\_{vis},t\_{vis}\rangle \), if \({{\,\textrm{pert}\,}}({\mu })\) admits a \(2\)UBE of Type \(\langle s\_{vis}, spine\_{vis},t\_{vis}\rangle \); in this case, we also say that the Type \(\langle s\_{vis}, spine\_{vis},t\_{vis}\rangle \) is realizable by \(\mu \) and by \({{\,\textrm{pert}\,}}({\mu })\). We have the following.

Lemma 4

Let \(\mu \) be a node of \({{\mathcal {T}}}\) and let \(\langle \pi _\mu , \sigma _\mu \rangle \) be a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\).

Then, \(\langle \pi _\mu , \sigma _\mu \rangle \) has exactly one embedding type, where the possible embedding types are the 18 depicted in Fig. 12.

Proof

The first part of the statement follows from the definition of embedding type. To see that the number of possible embedding types allowed by a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\) is at most 18, it suffices to consider the following facts. First, the number of different embedding types admitted by \({{\,\textrm{pert}\,}}({\mu })\) is at most 36. Further, some combinations are “impossible”, in the sense that not all combinations of values for \(s\_{vis}\), \(spine\_{vis}\), and \(t\_{vis}\) appear in a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\). In particular, we have that the following values for \(spine\_{vis}\) are forbidden: (a) \(spine\_{vis}\) cannot be L, if either \(s\_{vis}=R\) or \(t\_{vis}=R\); (b) \(spine\_{vis}\) cannot be R, if either \(s\_{vis}=L\) or \(t\_{vis}=L\); (c) \(spine\_{vis}\) cannot be N, if either \(s\_{vis} \ne N\) or \(t\_{vis} \ne N\). Condition a and Condition b rule out 5 combinations each, while Condition c rules out 8 more combinations (see also Table 1). This leaves us with the 18 embedding types shown in Fig. 12. \(\square \)

Fig. 12
figure 12

Illustration of the possible embedding types of a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\) for a node \(\mu \) with poles \(s_\mu \) and \(t_\mu \); the portions of the spine that are visible from the left page or from the right page are green. Embedding types that are in the same dotted box are one the vertically-mirrored copy of the other. Embedding types on the left are the horizontally-mirrored copies of the ones on the right. Embedding types and are the horizontally-mirrored and vertically-mirrored copies of themselves

Recall that, for each node \(\mu \) of \({\mathcal {T}}\), \({{\,\textrm{pert}\,}}({\mu })\) may have exponentially many planar embeddings, given by the permutations of the children of the P-nodes and by the flips of the R-nodes. Moreover, there may exist exponentially many \(2\)UBEs associated with each such planar embedding. The next lemma will be the key tool to help us control this combinatorial explosion.

Let \(\langle \pi , \sigma \rangle \) be a \(2\)UBE of G, let \(\mu \) be a node of \({\mathcal {T}}\), and let \(\langle \pi _\mu , \sigma _\mu \rangle \) be the restriction of \(\langle \pi , \sigma \rangle \) to \({{\,\textrm{pert}\,}}({\mu })\). Also, let \(\langle \pi '_\mu , \sigma '_\mu \rangle \ne \langle \pi _\mu , \sigma _\mu \rangle \) be a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\). We prove the following.

Lemma 5

If \(\langle \pi '_\mu , \sigma '_\mu \rangle \) and \(\langle \pi _\mu , \sigma _\mu \rangle \) have the same embedding type, then G admits a \(2\)UBE whose restriction to \({{\,\textrm{pert}\,}}({\mu })\) is \(\langle \pi '_\mu , \sigma '_\mu \rangle \).

Table 1 Embedding types that are not possible

Proof

Notice that if \({{\,\textrm{pert}\,}}({\mu })\) is an edge, the statement does not apply, because \({{\,\textrm{pert}\,}}({\mu })\) does not admit two distinct \(2\)UBEs of the same type. Thus we assume that \({{\,\textrm{pert}\,}}({\mu })\) has at least three vertices. We show how to construct a \(2\)UBE \(\langle \pi ', \sigma ' \rangle \) of G whose restriction to \({{\,\textrm{pert}\,}}({\mu })\) is \(\langle \pi '_\mu , \sigma '_\mu \rangle \).

For the ease of description we actually show how to construct an upward planar drawing \(\Gamma '\) of G in which each vertex v lies along the spine in the same bottom-to-top order determined by \(\pi '\) and each edge is drawn on the page assigned by \(\sigma '\). Clearly, such a drawing implies the existence of \(\langle \pi ', \sigma ' \rangle \).

Consider a drawing \(\Gamma (\pi ,\sigma )\) of G; refer to Fig. 13a. Let \(G_{{\overline{\mu }}}\) be the subgraph of G composed of the edges of G not in \({{\,\textrm{pert}\,}}({\mu })\) and of their endpoints. Consider the drawing \(\Gamma _{{\overline{\mu }}}\) of \(G_{{\overline{\mu }}}\) obtained by restricting \(\Gamma (\pi ,\sigma )\) to \(G_{{\overline{\mu }}}\). Denote by \(\pi _{{\overline{\mu }}}\) the bottom-to-top order of the vertices of \(G_{{\overline{\mu }}}\) in \(\Gamma _{{\overline{\mu }}}\). Let \(\pi _1, \pi _2, \dots , \pi _k\) be the maximal subsequences of \(\pi _{{\overline{\mu }}}\) between s and t and composed of consecutive vertices in \(\pi _{{\overline{\mu }}}\) that are also consecutive in \(\pi \) (refer to Fig. 13a). Observe that sequences \(\pi _i\), \(i=1, \dots , k\), may be formed by a single vertex or by multiple vertices. Also, the first sequence \(\pi _1\) includes \(s_\mu \) and the last sequence \(\pi _k\) includes \(t_\mu \). Further, since \({{\,\textrm{pert}\,}}({\mu })\) has at least three vertices, there exists at least a vertex of \({{\,\textrm{pert}\,}}({\mu })\) between \(s_{\mu }\) and \(t_{\mu }\) in \(\Gamma (\pi ,\sigma )\); therefore we have that \(k \ge 2\).

Fig. 13
figure 13

Illustrations for Lemma 5. The \(2\)UBEs of \({{\,\textrm{pert}\,}}({\mu })\) are of Type

Drawing \(\Gamma _{{\overline{\mu }}}\) contains a face \(f_\mu \) that is incident to the ending vertex of the sequence \(\pi _1\), to the starting vertex of the sequence \(\pi _k\), and, if \(k \ge 3\), to all the starting and ending vertices of the sequences \(\pi _i\), with \(i = 2, \dots , k-1\). Face \(f_\mu \) always contains the vertices \(s_{\mu }\) and \(t_{\mu }\). Some starting and ending vertices of the sequences \(\pi _i\) are encountered when traversing \(f_\mu \) clockwise from \(s_\mu \) to \(t_\mu \) (left vertices of \(f_\mu \)) and some of them are encountered when traversing \(f_\mu \) counter-clockwise from \(s_\mu \) to \(t_\mu \) (right vertices of \(f_\mu \)). The left (resp. right) vertices of \(f_{\mu }\) are red (resp. blue) in Fig. 13.

We show how to insert into face \(f_\mu \) the drawing \(\Gamma (\pi '_\mu ,\sigma '_\mu )\) of \({{\,\textrm{pert}\,}}({\mu })\), producing the desired drawing \(\Gamma '\) of the \(2\)UBE \(\langle \pi ', \sigma ' \rangle \) of G. First, consider the drawing \(\Gamma (\pi '_\mu ,\sigma '_\mu )\) of \({{\,\textrm{pert}\,}}({\mu })\) (see Fig. 13b) and insert it, possibly after squeezing it, into \(f_\mu \) in such a way that its spine lays entirely on the line of the spine of \(\Gamma _{{\overline{\mu }}}\) and in such a way that the vertices of \(\mu \) do not fall in between the vertices of any maximal sequence \(\pi _i\), \(i=1, \dots , k\). This is always possible, because \(k \ge 2\) and there exists a portion of the spine of \(\Gamma _{{\overline{\mu }}}\) that is in the interior of \(f_\mu \). Observe that this implies that \(s_\mu \) and \(t_\mu \) have now a double representation, since the drawing of the source \(s'_\mu \) and sink \(t'_\mu \) of \(\Gamma (\pi '_\mu ,\sigma '_\mu )\) do not coincide with the drawing of \(s_\mu \) and \(t_\mu \) in \(\Gamma _{{\overline{\mu }}}\). Denote by \(\Gamma ^*\) the resulting drawing (refer to Fig. 13c).

Suppose \(\langle \pi _\mu , \sigma _\mu \rangle \) (and, hence, also \(\langle \pi '_\mu , \sigma '_\mu \rangle \)) is of Type \(\langle x, y, z \rangle \). Observe that if \(y \in \{N, R\}\) then there are no left vertices of \(f_\mu \). Otherwise, if \(y \in \{L,B\}\), then it is possible to identify two vertices \(v_{\ell ,b}\) and \(v_{\ell ,t}\) of \(\Gamma (\pi '_\mu ,\sigma '_\mu )\) such that there exists a portion of the spine between \(v_{\ell ,b}\) and \(v_{\ell ,t}\) that is visible from left. Consider all the vertices of the sequences \(\pi _i\) whose starting and ending vertices are left vertices of \(f_\mu \), and move them between \(v_{\ell ,b}\) and \(v_{\ell ,t}\) along the spine of \(\Gamma ^*\), while preserving their relative order. Analogously, if \(y \in \{N, L\}\), there are no right vertices of \(f_\mu \). Otherwise, if \(y\in \{R, B\}\), it is possible to identify two vertices \(v_{r,b}\) and \(v_{r,t}\) of \(\Gamma (\pi '_\mu ,\sigma '_\mu )\) such that there exists a portion of the spine between \(v_{r,b}\) and \(v_{r,t}\) that is visible from right. Consider all the vertices of the sequences \(\pi _i\) whose starting and ending vertices are right vertices of \(f_\mu \), and move them between \(v_{r,b}\) and \(v_{r,t}\) along the spine of \(\Gamma ^*\), while preserving their relative order.

\(\Gamma ^*\) is an upward planar drawing of G except for the fact that there are two duplicated vertices \(s'_\mu \) and \(t'_\mu \). Thus, by identifying \(s_\mu \) with \(s'_\mu \) and \(t_\mu \) with \(t'_\mu \), we obtain the desired upward drawing \(\Gamma '\) of G in which each vertex v lies along the spine and each edge is drawn as a y-monotone curve on one of the two half-planes defined by the spine. Next we prove that \(\Gamma '\) is planar. Clearly, identifying \(s_\mu \) with \(s'_\mu \) (\(t_\mu \) with \(t'_\mu \)) does not introduce crossings when \(s_\mu \) and \(s'_\mu \) (\(t_\mu \) and \(t'_\mu \)) are consecutive along the spine in \(\Gamma ^*\) (see \(t'_\mu \) and \(t_\mu \) in Fig. 13c). In the case in which \(s_\mu \) and \(s'_\mu \) (\(t_\mu \) and \(t'_\mu \)) are not consecutive along the spine in \(\Gamma ^*\), necessarily \(x \in \{L,R\}\) (\(z \in \{L,R\}\)). Suppose \(x = L\) (\(z=L\)), the case when \(x = R\) (\(z=R\)) being analogous. There cannot exist in \(\Gamma _{{\overline{\mu }}}\) an edge \(e=(a,b)\) such that \(\pi (a)< \pi (s_\mu ) < \pi (b)\) and such that \(\sigma (e)=R\). Therefore, we can continuously move \(s'_\mu \), together with its incident edges, toward \(s_\mu \), remaining inside the region bounded by \(f_\mu \) without intersecting any edge of \(G_{{\overline{\mu }}}\) (see Fig. 13d). This concludes the proof. \(\square \)

We now describe an algorithm to decide if G admits a \(2\)UBE and its running time. The same procedure can be easily refined to actually compute a \(2\)UBE of G, with no additional cost, by decorating each node \(\mu \in {\mathcal {T}}\) with the embedding choices performed at \(\mu \), for each of its O(1) possible embedding types.

Testing Algorithm. The algorithm is based on visiting the SPQR-tree \({\mathcal {T}}\) of G and on computing, for each non-root node \(\mu \) of \({\mathcal {T}}\), the set of embedding types realizable by \(\mu \), assuming to have already computed the set of embedding types realizable by each of the children of \(\mu \). Lemma 5 is the reason why we only need to maintain a single \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\), for each embedding type realizable by \(\mu \), i.e., a constant number of \(2\)UBEs instead of an exponential number. Since, by Lemmas 4 and 5, G admits a \(2\)UBE if and only if the pertinent graph of the unique child of the root Q-node admits an embedding type of (at least) one of the 18 possible embedding types, this approach allows us to solve the 2UBE Testing problem for G.

The computation of the set of embedding types realizable by \(\mu \) is based on whether \(\mu \) is an S-, P-, Q-, or an R-node. Recall that the only possible embedding choices for G happen at P- and R-nodes. While the treatment of Q- and S-nodes does not require any modification when considering the variable and the fixed embedding settings, for P- and R-nodes we will discuss how to compute the embedding types that are realizable by \(\mu \) in both such settings separately. In particular, in the fixed embedding scenario the above characterization needs to additionally satisfy the constraints imposed by the fixed embedding on the skeletons of the P- and R-nodes in \({\mathcal {T}}\). Note that, a leaf Q-node only admits Type and Type . Also, combining \(2\)UBEs of the two children of an S-node \(\mu \) always yields a valid \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\). The next lemma shows how to compute all the embedding types realizable by \(\mu \).

Lemma 6

Let \(\mu \) be an S-node. The set of embedding types realizable by \(\mu \) can be computed in O(1) time, both in the fixed and in the variable embedding setting.

Proof

Let \(\mu \) be an S-node with poles \(s_{\mu }\) and \(t_{\mu }\). Let \(\mu '\) and \(\mu ''\) be the two children of \(\mu \) with poles \(s_{\mu '}\), \(t_{\mu '}\) and \(s_{\mu ''}\), \(t_{\mu ''}\), respectively, where \(s_{\mu '}=s_{\mu }\), \(t_{\mu '}=s_{\mu ''}\), and \(t_{\mu ''}=t_{\mu }\). Clearly, combining each pair of \(2\)UBEs of the two children of \(\mu \) always yields a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\). Let \(\langle x',y',z' \rangle \) and \(\langle x'',y'',z'' \rangle \) be any two embedding types realizable by \(\mu '\) and \(\mu ''\), respectively. The embedding type \(\langle x, y, z \rangle \) of any \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\) resulting from a series combination of \(2\)UBEs of the above types can be computed as follows. We have \(x = x'\) and \(z = z''\). As for y, we have that: (i) \(y = N\) iff \(y'=y''=N\); (ii) \(y=L\) if either \(y'=L\) and \(y'' \in \{L,N\}\) or \(y''=L\) and \(y' \in \{L,N\}\); (iii) \(y=R\) if either \(y'=R\) and \(y'' \in \{R,N\}\) or \(y''=R\) and \(y' \in \{R,N\}\); (iv) \(y=B\) if at least one of \(y'\) and \(y''\) is B or one of them is L and the other is R. Since there is a constant number of embedding types realizable by the children of \(\mu \), the statement follows. \(\square \)

Since P- and R-nodes require a more complex treatment, in the following we only state the lemmas concerning the computation time of the set of realizable embedding types for these nodes. We defer the proofs of such lemmas to the next sections. Specifically, in Subsection 6.5 we show how to efficiently compute the set of embedding types realizable by a P-node in the fixed and variable embedding setting (Subsection 6.5.1 and Subsection 6.5.2, respectively). We have the following.

Lemma 7

Let \(\mu \) be a P-node with k children. The set of embedding types realizable by \({{\,\textrm{pert}\,}}({\mu })\) can be computed in O(k) time in the fixed embedding setting.

Lemma 8

Let \(\mu \) be a P-node with k children. The set of embedding types realizable by \({{\,\textrm{pert}\,}}({\mu })\) can be computed in \(O(k^2)\) time in the variable embedding setting.

We remark that Lemmas 6 and 7 yield a counterpart, in the fixed embedding setting, of the linear-time algorithm by Di Giacomo et al. [46] to compute \(2\)UBEs of series-parallel graphs, which we formalize in the following statement.

Theorem 7

There exists an O(n)-time algorithm to decide whether an n-vertex series-parallel st-graph admits an embedding-preserving \(2\)UBE.

Finally, in  Subsection 6.4 we show how to efficiently compute the set of embedding types realizable by an R-node. In particular, we prove the following.

Lemma 9

Let \(\mu \) be an R-node with k children and whose skeleton has branchwidth \({{\,\mathrm{\beta }\,}}\). The set of embedding types realizable by \({{\,\textrm{pert}\,}}({\mu })\) can be computed in \(O(2^{O(\beta \log {\beta })}\cdot k\) time, both in the fixed and in the variable embedding setting, provided that a sphere-cut decomposition \(\langle T, \xi , \Pi \rangle \) of width \(\beta \) of \({{\,\textrm{skel}\,}}^+(\mu )\) is given.

By Lemmas 6 to 9, and since \({\mathcal {T}}\) has \(O(|G |)\) size [43, 51], we get the following.

Theorem 8

There exists an \(O(2^{O(\beta \log {\beta })}\cdot n + n^2 + g(n))\)-time algorithm to decide if an n-vertex planar st-graph (resp. plane st-graph) of branchwidth \(\beta \) admits a \(2\)UBE (resp. an embedding-preserving \(2\)UBE), where g(n) is the computation time of a sphere-cut decomposition of an n-vertex plane graph.

Since g(n) is \(O(n^3)\) by the result in [87], we get the following.

Corollary 2

There exists an \(O(2^{O(\beta \log {\beta })}\cdot n + n^3)\)-time algorithm to decide if an n-vertex planar st-graph (resp. plane st-graph) of branchwidth \(\beta \) admits a \(2\)UBE (resp. an embedding-preserving \(2\)UBE).

Furthermore, since for any n-vertex planar graph, it holds \(\beta \le 2.122\sqrt{n}\) [60], Corollary 2 implies that the 2UBE Testing problem is solvable in sub-exponential time.

Corollary 3

There exists an \(O(2^{O(\sqrt{n} \log {\sqrt{n}})} + n^3)\)-time algorithm to decide if an n-vertex planar st-graph (resp. plane st-graph) admits a \(2\)UBE (resp. an embedding-preserving \(2\)UBE).

6.4 Computing the Embedding Types when \(\mu \) is an R-node

Let \(\mu \) be an R-node with poles \(s_{\mu }\) and \(t_{\mu }\); refer to Fig. 14. We consider the graph \({{\,\textrm{skel}\,}}^+(\mu ) = {{\,\textrm{skel}\,}}(\mu ) \cup (s_\mu ,t_\mu )\), which is a triconnected planar graph. Since \({{\,\textrm{skel}\,}}^+(\mu )\) is a minor of G, its branchwidth is bounded by the branchwidth \(\beta \) of G [86, Theorem 4.1]. Let \({\mathcal {E}}_\mu \) be an embedding of \({{\,\textrm{skel}\,}}^+(\mu )\) on the sphere and let \(\langle T, \xi , \Pi \rangle \) be a sphere-cut decomposition of \({{\,\textrm{skel}\,}}^+(\mu )\) with embedding \({\mathcal {E}}_\mu \) of width smaller than or equal to \({{\,\mathrm{\beta }\,}}\); refer to Fig. 14a.

We root T at the leaf \(\rho \) of T such that \(\xi (\rho ) = (s_\mu ,t_\mu )\). Consider each arc \(a=(p_a,c_a)\) of T connecting the parent node \(p_a\) with the child node \(c_a\) in T. The noose \(O_a\) of a divides the sphere into two closed regions whose boundary is \(O_a\). We associate a with the subgraph \({{\,\textrm{skel}\,}}_a\) of \({{\,\textrm{skel}\,}}^+(\mu )\) lying in the region not containing the edge \((s_\mu ,t_\mu )\), and we refer to the face of \({{\,\textrm{skel}\,}}_a\) that contains such an edge as the outer face of \({{\,\textrm{skel}\,}}_a\). We denote by \({{\,\textrm{pert}\,}}_a\) the subgraph of \({{\,\textrm{pert}\,}}({\mu })\) obtained by replacing, in \({{\,\textrm{skel}\,}}_a\), each virtual edge e with the pertinent graph of the node corresponding to e in the SPQR-tree \({\mathcal {T}}\) of G.

Intuitively, our strategy to compute the embedding types admitted by \({{\,\textrm{pert}\,}}({\mu })\) is to visit the nodes of T in post order. When a node \(c_a\) incident to the edge \(a = (p_a,c_a)\) is visited, we compute a succinct description of size \(O({{\,\mathrm{\beta }\,}})\) of the properties of the noose \(O_a\) in a \(2\)UBE of \({{\,\textrm{pert}\,}}_a\). Note that the arc \(a^*\) incident to the root \(\rho \) is such that \({{\,\textrm{skel}\,}}_{a^*}\) (resp. \({{\,\textrm{pert}\,}}_{a^*}\)) coincides with \({{\,\textrm{skel}\,}}(\mu )\) (resp. with \({{\,\textrm{pert}\,}}({\mu })\)). When we reach \(a^*\), we use the computed properties for \(O_{a^*}\) to determine which embedding types are realizable by \({{\,\textrm{pert}\,}}({\mu })\). The fixed and the variable embedding setting are treated analogously. In the fixed embedding setting, we only consider the embedding of \({{\,\textrm{skel}\,}}^+(\mu )\) in which the embedding of \({{\,\textrm{skel}\,}}(\mu )\) is inherited by the (fixed) embedding of G. In the variable embedding setting, instead, we consider each of the two embeddings of \({{\,\textrm{skel}\,}}^+(\mu )\) obtained by flipping the embedding of \({{\,\textrm{skel}\,}}(\mu )\) at its poles.

Fig. 14
figure 14

Illustrations for the R-node case. a A partial sphere-cut decomposition of the graph \({{\,\textrm{skel}\,}}(\mu ) \cup (s_\mu ,t_\mu )\) rooted at the edge \((s_\mu ,t_\mu )\), where \(\mu \) is an R-node. The nooses are dotted curves. b Outer faces of graphs \({{\,\textrm{skel}\,}}_{a_1}\) and \({{\,\textrm{skel}\,}}_{a_2}\). c The graphs defined by the directed paths on the outer face of \({{\,\textrm{skel}\,}}_{a_1}\) and \({{\,\textrm{skel}\,}}_{a_2}\). d The auxiliary graph A for \({{\,\textrm{skel}\,}}_{a}\)

Let a be an arc of T and let \(p_0, p_1, \dots , p_k\) be the sequence of maximal (upward or downward) directed paths traversed in a clockwise visit of the outer face of \({{\,\textrm{skel}\,}}_a\). The next lemma shows that \(k \in O(\beta )\).

Lemma 10

For each arc \(a \in T\), by clockwise visiting the outer face of \({{\,\textrm{skel}\,}}_a\), we traverse at most \(O({{\,\mathrm{\beta }\,}})\) maximal (upward or downward) directed paths.

Proof

Let \(p_{u,v}\) be the path along the outer face of \({{\,\textrm{skel}\,}}_a\) connecting two vertices of \({{\,\textrm{mid}\,}}(a)\) that are clockwise consecutive in the circular ordering \(\pi _a \in \Pi \) of \({{\,\textrm{mid}\,}}(a)\). By Property 3, \({{\,\textrm{pert}\,}}({\mu })\) is an \(s_\mu t_\mu \)-graph, and thus its faces have a single source and a single sink. If \(p_{u,v}\) was composed of more than three maximal (upward or downward) directed paths, then the outer face of \({{\,\textrm{skel}\,}}_a\) would contain either two sources or two sinks belonging to \(p_{u,v}\). The statement then follows from the fact that \(|{{\,\textrm{mid}\,}}(a) |\le {{\,\mathrm{\beta }\,}}\). \(\square \)

Let u and v be two clockwise consecutive vertices along the outer face of \({{\,\textrm{skel}\,}}_a\) that are connected by an (upward or downward) directed path \(p_i\). Given a \(2\)UBE \(\langle \pi _a, \sigma _a\rangle \) of \({{\,\textrm{pert}\,}}_a\), we associate with \(p_i\) an outer-visibility triple \(t_i = \langle u\_{vis}, spine\_{vis}, v\_{vis} \rangle \) of \(p_i\) in \(\langle \pi _a, \sigma _a\rangle \), for \(i = 1, \dots , k\), which encodes the information about the visibility of the spine between u and v from the outer face of \(\Gamma (\pi _a, \sigma _a)\). In particular, we have:

\(\mathbf {u\_{vis}=true}\):

if and only if there is a portion of the spine incident to u and between u and v that is visible from the outer face of \(\Gamma (\pi _a, \sigma _a)\).

\(\mathbf {v\_{vis}=true}\):

if and only if there is a portion of the spine incident to v and between u and v that is visible from the outer face of \(\Gamma (\pi _a, \sigma _a)\).

\(\mathbf {spine\_{vis}=true}\):

if and only if there is a portion of the spine between u and v that is visible from the outer face of \(\Gamma (\pi _a, \sigma _a)\).

Observe that when \(u\_{vis} = true\) or \(v\_{vis} = true\), then necessarily \(spine\_{vis} = true\). Hence, we have five possible types for the outer-visibility triples \(\langle u\_{vis}, spine\_{vis}, v\_{vis} \rangle \).

We denote by \(X_a\) the set of all the endpoints of the paths \(p_1,\dots ,p_k\). Let \(\langle \pi _\mu , \sigma _\mu \rangle \) be a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\), let a be an arc of T, and let \(\langle \pi _a, \sigma _a\rangle \) be the restriction of \(\langle \pi _\mu , \sigma _\mu \rangle \) to \({{\,\textrm{pert}\,}}_a\). Further, let \(\langle \pi '_a, \sigma '_a\rangle \ne \langle \pi _a, \sigma _a\rangle \) be a \(2\)UBE of \({{\,\textrm{pert}\,}}_a\). The next lemma can be proved with the same strategy as in the proof of Lemma 5.

Lemma 11

Graph \({{\,\textrm{pert}\,}}({\mu })\) admits a \(2\)UBE \(\langle \pi '_\mu , \sigma '_\mu \rangle \) whose restriction to \({{\,\textrm{pert}\,}}_a\) is \(\langle \pi '_a, \sigma '_a\rangle \) if the following two conditions hold: 1.the bottom-to-top order of the vertices in \(X_a\) is the same in \(\pi _a\) as in \(\pi '_a\), and 2.for each \(i=1,\dots ,k\), the outer-visibility triple of \(p_i\) in \(\Gamma (\pi '_a, \sigma '_a)\) is the same as the outer-visibility triple of \(p_i\) in \(\Gamma (\pi _a, \sigma _a)\).

When visiting T bottom-up, we compute and store in each arc a of T those pairs \((\pi _a, \langle t_1, t_2, \dots , t_k \rangle )\), called outer-shape pairs, where \(\pi _a\) is a bottom-to-top order of the vertices in \(X_a\) and \(t_i\) is an outer-visibility triple for path \(p_i\), for \(i=1,\dots ,k\), such that there exists a \(2\)UBE \(\langle \pi , \sigma \rangle \) of \({{\,\textrm{pert}\,}}_a\) satisfying the following properties: 1. ordering \(\pi _a\) is the restriction of \(\pi \) to \(X_a\) and 2. \(t_i\) is the outer-visibility triple determined by \(\langle \pi , \sigma \rangle \) when clockwise traversing the outer face of \(\Gamma (\pi , \sigma )\) between the endpoints of \(p_i\). By Lemma 11, this information is enough to succinctly describe all the relevant properties of the \(2\)UBEs  of \({{\,\textrm{pert}\,}}_a\). Moreover, by Property 3\({{\,\textrm{skel}\,}}_{a^*}={{\,\textrm{skel}\,}}(\mu )\) is bounded by two directed paths \(p_1\) and \(p_2\) whose end-vertices are \(s_\mu \) and \(t_\mu \). Thus, when we reach the arc \(a^*\), all the embedding types that are realizable by \({{\,\textrm{pert}\,}}({\mu })\) can be computed by inspecting the outer-visibility triples \(t_1\) and \(t_2\), over all outer-shape pairs \((\pi _a, \langle t_1, t_2 \rangle )\) stored in \(a^*\).

Next, we show how to compute all outer-shape pairs \((\pi _a, \langle t_1, t_2, \dots , t_k \rangle )\), for each arc \(a \in T\).

Suppose a leads to a leaf \(\ell \) of T such that \(\xi (\ell ) = (u,v)\). Assume that \({{\,\textrm{pert}\,}}_a\) is oriented from u to v and that the clockwise boundary of \({{\,\textrm{skel}\,}}_a\) is composed by the upward path \(p_1 = u,v\) and the downward path \(p_2 = v,u\), the other case being analogous. Then, all the outer-shape pairs \((\pi _a, \langle t_1, t_2 \rangle )\) for a are such that \(\pi _a = u,v\), since \({{\,\textrm{pert}\,}}_a\) is an uv-graph. Let \(\mu _\ell \) be the child of \(\mu \) in the SPQR-tree \({\mathcal {T}}\) associated with the virtual edge (uv). We compute the outer-visibility triples \(t_1=\langle \alpha , \varphi , \gamma \rangle \) and \(t_2=\langle \alpha ', \varphi ', \gamma ' \rangle \) for \(p_1\) and \(p_2\), respectively, starting from the embedding types realizable by \(\mu _\ell \), as follows. For each embedding type \(\langle s\_{vis},spine\_{vis},t\_{vis} \rangle \) of the node \(\mu _\ell \) we define \(t_1\) and \(t_2\) as follows. If \(s\_{vis} = L\), we set \(\alpha = true\) and \(\alpha ' = false\). If \(s\_{vis} = R\) we set \(\alpha = false\) and \(\alpha ' = true\). If \(s\_{vis} = N\) we set both \(\alpha = \alpha ' = false\). Analogously, we set \(\varphi \) and \(\varphi '\) according to the value of \(t\_{vis}\). We set \(\gamma = true\) if \(spine\_{vis} = B\) or \(spine\_{vis} = L\). Otherwise, we set \(\gamma = false\). Finally, we set \(\gamma ' = true\) if \(spine\_{vis} = B\) or \(spine\_{vis} = R\). Otherwise, we set \(\gamma ' = false\).

Suppose now that a leads to a non-leaf node \(\lambda \) of T. Then, \(\lambda \) has two children \(\lambda _1\) and \(\lambda _2\), reached by two arcs \(a_1\) and \(a_2\) of T, for which we have already computed all the outer-shape pairs. We are going to use the following observation, which follows from the planarity of \({{\,\textrm{skel}\,}}(\mu )\) and from the fact that the nooses are pairwise non-crossing.

Observation 1

Let \(\langle \pi _\mu , \sigma _\mu \rangle \) be a \(2\)UBE of \({{\,\textrm{skel}\,}}(\mu )\), and let \(\langle \pi _{a_1}, \sigma _{a_1} \rangle \) and \(\langle \pi _{a_2}, \sigma _{a_2} \rangle \) be the \(2\)UBEs of \({{\,\textrm{skel}\,}}_{a_1}\) and \({{\,\textrm{skel}\,}}_{a_2}\), respectively, determined by \(\langle \pi _\mu , \sigma _\mu \rangle \). The following two properties hold: 1. the edges of \({{\,\textrm{skel}\,}}_{a_1}\) lie in the outer face of the drawing obtained by restricting \(\Gamma (\pi _\mu ,\sigma _\mu )\) to \({{\,\textrm{skel}\,}}_{a_2}\), and vice versa, and 2. the edges of \({{\,\textrm{skel}\,}}_{a_1}\) and \({{\,\textrm{skel}\,}}_{a_2}\) do not interleave around a vertex in \(\Gamma (\pi _\mu ,\sigma _\mu )\).

For \(i=1,2\), let \(A_i=(V_i,E_i)\) be the auxiliary (multi)-graph of \({{\,\textrm{pert}\,}}_{a_i}\) defined as follows. Initialize \(V_i=X_{a_i}\) and add to \(E_i\) a directed edge (uv) for each path p directed from u to v traversed when clockwise visiting the outer face of \({{\,\textrm{skel}\,}}_{a_i}\); see Fig. 14c. Then, replace each directed edge (uv) with a directed path \((u,x',x'',v)\), unless (uv) is an edge in G. Clearly, graph \(A_i\) is connected. Note that, there exists a one-to-one correspondence between the directed paths along the outer face of \({{\,\textrm{skel}\,}}_{a_i}\) (see Fig. 14b) and the directed paths along the outer face of \(A_i\) (see Fig. 14c). We have that each \(2\)UBE of \(A_i\) defines a set \(\langle t_1,\dots ,t_{k_i}\rangle \), where \(t_i\) is an outer-visibility triple describing the visibility of each directed path along the outer face of \(A_i\) in the \(2\)UBE. We define a new graph A as the union of \(A_1\) and \(A_2\); see Fig. 14d. The purpose of graph A is that of representing the visibility of the spine on the outer face of \({{\,\textrm{pert}\,}}_a\) between pairs of vertices in \(X_a\) in a \(2\)UBE of \({{\,\textrm{pert}\,}}_a\). In particular, by assigning to the faces of the book embedding the three edges that replace each directed path \(p_i\) along the outer face of \({{\,\textrm{pert}\,}}_a\), we are able to model the outer-visibility triples of paths \(p_1, \dots , p_k\). We compute all outer-shape pairs \(\langle \pi _a, \langle t_1,\dots ,t_k \rangle \rangle \) for a using Algorithm 1.

figure f

Procedure to compute the outer-shape pairs of an arc \(a \in T\).

We now prove Lemma 9, which we restate for the reader’s convenience.

Lemma 9 Let \(\mu \) be an R-node with k children and whose skeleton has branchwidth \({{\,\mathrm{\beta }\,}}\). The set of embedding types realizable by \({{\,\textrm{pert}\,}}({\mu })\) can be computed in \(2^{O({{\,\mathrm{\beta }\,}}\log {{{\,\mathrm{\beta }\,}}})}\cdot k\) time, both in the fixed and in the variable embedding setting, provided that a sphere-cut decomposition \(\langle T, \xi , \Pi \rangle \) of width \(\beta \) of \({{\,\textrm{skel}\,}}^+(\mu )\) is given.

Proof

We exploit Algorithm 1 on the arcs of T to compute their outer-shape pairs. As already observed, this allows us to compute the embedding types realizable by \({{\,\textrm{pert}\,}}({\mu })\) from the outer-shape pairs of the arc \(a^*\) incident to the root \(\rho \) of T. The correctness of Algorithm 1 descends from Lemma 4, Lemma 11 and Observation 1.

We argue about the running time of Algorithm 1 for a given arc a of \(T_\mu \). Note that the auxiliary graph A corresponding to a contains \(O(\beta )\) vertices, by Lemma 10, and \(O(\beta )\) edges, since it is planar. First, the running time of Step 1 is bounded by the number of possible \(2\)UBEs  of A. By enumerating all the \(|V(A) |! \in O(\beta !) \in 2^{O(\beta \log {\beta })}\) linear orders of V(A) and all the \(2^{|E(A) |} \in 2^{O(\beta )}\) edge assignments for E(A), we may construct \(2^{O(\beta \log {\beta })}\) \(2\)UBEs of A. Step 2 is also bounded by the numbers of \(2\)UBEs of A, as testing whether the conditions of Observation 1 are satisfied by each such a \(2\)UBE can be performed in time linear in the size of A, i.e., \(O(\beta )\) time. Clearly, for each of the \(2\)UBEs of A considered at Step 3, the remaining steps of Algorithm 1 can also be performed in \(O(\beta )\) time. Thus, Algorithm 1 runs in \(2^{O(\beta \log {\beta })}\) time. The overall running time for computing the embedding types of an R-node \(\mu \) follows from the fact that tree T contains O(k) nodes and arcs, since it is a binary tree whose leaves are the k virtual edges of \({{\,\textrm{skel}\,}}(\mu )\), and from the time spent to compute the outer-shape pairs for each arc of T, i.e., the running time of Algorithm 1. \(\square \)

6.5 Computing the Embedding Types when \(\mu \) is a P-node

We show how to efficiently compute the set of embedding types realizable by the pertinent graph of a P-node. The fixed and variable embedding settings are treated in Subsection 6.5.1 and Subsection 6.5.2, respectively.

6.5.1 P-nodes: Fixed Embedding

Let \(\mu \) be a P-node with poles \(s_\mu \) and \(t_\mu \) and let \(\mu _1,\mu _2,\dots ,\mu _k\) be the children of \(\mu \) in the left-to-right order defined by the given embedding of G.

Let \({{\,\textrm{skel}\,}}^i(\mu )\) and \({{\,\textrm{pert}\,}}^i(\mu )\) be the subgraphs of \({{\,\textrm{skel}\,}}(\mu )\) and of \({{\,\textrm{pert}\,}}({\mu })\), respectively, determined by the children \(\mu _1,\mu _2,\dots ,\mu _i\) of \(\mu \) (\(1 \le i \le k\)). Since \({{\,\textrm{pert}\,}}^1(\mu )={{\,\textrm{pert}\,}}({\mu _1})\), the set \(X_1\) of embedding types that are realizable by \({{\,\textrm{pert}\,}}^1(\mu )\) are those that are realizable by \({{\,\textrm{pert}\,}}({\mu _1})\). For \(i=2,\dots ,k\), we can compute the set \(X_i\) of embedding types that are realizable by \({{\,\textrm{pert}\,}}^i(\mu )\) as follows. We consider each embedding type \(\langle x,y,z \rangle \in X_{i-1}\) and each embedding type \(\langle a,b,c\rangle \) that is realizable by \({{\,\textrm{pert}\,}}({\mu _i})\), and we either reject the pair, if no embedding type can be obtained by composing \(\langle x,y,z \rangle \) and \(\langle a,b,c\rangle \), or compute an embedding type \(\langle p,q,w\rangle \) for \({{\,\textrm{pert}\,}}^i(\mu )\), which we add to \(X_i\). The sequence of the two tests is described below.

Fig. 15
figure 15

Solid lines represent rejection cases when \(x \in \{N,L\}\) and \(a \in \{N,R\}\)

Rejection:

  • If \(x \in \{N,L\}\) and \(a \in \{N,R\}\), we reject the pair (refer to Fig. 15).

  • If \(z \in \{N,L\}\) and \(c \in \{N,R\}\), we reject the pair.

  • If \(y \in \{N,L\}\), we reject the pair unless \(\mu _i\) is a Q-node (which admits Type ). In fact, if \(\mu _i\) is not a Q-node, \({{\,\textrm{pert}\,}}({\mu _i})\) contains at least a vertex different from \(s_\mu \) and from \(t_\mu \) that has to be placed on the spine to the right of \({{\,\textrm{pert}\,}}^{i-1}(\mu )\) and between \(s_\mu \) and \(t_\mu \). However, in a \(2\)UBE of \({{\,\textrm{pert}\,}}^{i-1}(\mu )\) of Type \(\langle x,y,z \rangle \) with \(y \in \{L,N\}\), there exists no portion of the spine between \(s_\mu \) and \(t_\mu \) that is visible from the right page.

  • If \(b \in \{N,R\}\), by a similar argument as in the previous case, we reject the pair unless \(i=2\) and \(\mu _1\) is a Q-node (which admits Type ).

Observe that after the above rejections either \(\mu _i\) or \({{\,\textrm{pert}\,}}^{i-1}(\mu )\) are single edges, or all the conditions below hold:

  • \(x = R\) or \(a = L\) (refer to Fig. 15).

  • \(z = R\) or \(c = L\).

  • \(y \notin \{N,L\}\).

  • \(b \notin \{N,R\}\).

Embedding Types for \({{\,\textrm{pert}\,}}^i(\mu )\):

Regarding p: If \(x=a\) (i.e., both are L or both are R) then \(p=x\), otherwise (either \(x=N\), or \(a=N\), or \(x=R\) and \(a=L\)) \(p=N\).

Regarding w: If \(z=c\) (i.e., both are L or both are R) then \(w=z\), otherwise (either \(z=N\), or \(c=N\), or \(z=R\) and \(c=L\)) \(w=N\).

Regarding q:

  • If \(y \in \{N,L\}\) (and, thus, \(\mu _i\) is a Q-node) then \(q=y\).

  • If \(y=R\) and \(b=L\) then \(q=N\). If \(y=R\) and \(b=B\) then \(q=R\). If \(y=R\) and \(b=R\) (\(i=2\) and \(\mu _1\) is a Q-node, which admits Type ) then \(q=R\).

  • If \(y=B\) (observe that, since \({{\,\textrm{pert}\,}}^{i-1}(\mu )\) is not a single edge, \(b \in \{L,B\}\)) then \(q=b\).

Since the set of rules above defines the set \(X_k\) of embedding types realizable by \({{\,\textrm{pert}\,}}^k(\mu ) = {{\,\textrm{pert}\,}}({\mu })\) and since the above computations can easily be performed in time linear in the number of children of \(\mu \), we obtain Lemma 7.

6.5.2 P-nodes: Variable Embedding

Let \(\mu \) be a P-node with poles \(s_\mu \) and \(t_\mu \), and with children \(\mu _1, \dots , \mu _k\). A \(2\)UBE \(\gamma \) of \({{\,\textrm{pert}\,}}({\mu })\) is obtained by choosing a permutation for the children of \(\mu \), a \(2\)UBE \(\gamma _i\) for each child \(\mu _i\) \((i = 1, \dots , k)\), and a bottom-to-top order of the vertices of \({{\,\textrm{pert}\,}}({\mu })\) whose restriction to each \(\mu _i\) corresponds to the bottom-to-top order of the vertices in \(\gamma _i\); the embedding types that are realizable for \(\mu \) depend on the embedding types that are realizable for its children. Our approach to compute the realizable types of \({{\,\textrm{pert}\,}}({\mu })\) consists of considering one type at a time for \(\mu \). For each embedding type, we check whether the children of \(\mu \), together with their realizable embedding types, can be arranged in a finite number of families of permutations (which we prove to be a constant number) so to yield a \(2\)UBE of the considered embedding type. In order to ease the following description, consider that the arrangements of the children for obtaining some embedding types can be easily derived from the arrangements to obtain the horizontally-mirrored ones by (i) reversing the left-to-right sequence of the children in the construction and (ii) by taking, for each child, the horizontally-mirrored embedding type; for instance, the arrangements to construct a \(2\)UBE of Type can be obtained from the ones to construct a \(2\)UBE of Type , and vice versa. Moreover, two embedding types, namely Type and Type , are (horizontally) self-symmetric. As a consequence, in order to consider all the embedding types that are realizable by \({{\,\textrm{pert}\,}}({\mu })\) we describe how to obtain only ten “relevant” embedding types (enclosed by a solid polygon in Fig. 12): , ,,, , , , , , and .

In this section, we give necessary and sufficient conditions under which the pertinent graph of a P-node admits Type . Then, we show how to test these conditions efficiently by exploiting a suitably defined flow network. The conditions for the remaining relevant embedding types, which can be tested similarly to Type , are reported in Appendix A.

Fig. 16
figure 16

a-b Cases NRR.1 and NRR.2 of Lemma 12 for a P-node \(\mu \) that admits Type . The spine is colored either green, blue, or black. The green part is the portion of the spine that is visible from the right, the black parts correspond to the bottom-to-top sequences of the vertices of \({{\,\textrm{pert}\,}}({\mu })\) inherited from the \(2\)UBEs of the children of \(\mu \) (restricted to the vertices different from \(s_\mu \) and from \(t_{\mu }\)), the blue parts join sequences inherited from different children. c Capacitated flow network \({\mathcal {N}}\) with edge demands corresponding to illustration b

Conditions for Type. Let \(\mu \) be a P-node. We define the following two cases based on the existence of a child of \(\mu \) that admits Type :

NRR.1 The children of \(\mu \) can be partitioned into two sets: The first set consists of a (possibly missing) Q-node child and a child that admits Type . The second set consists of any number (possibly zero) of children that admit Type .

NRR.2 The children of \(\mu \) can be partitioned into three sets: The first set consists either of a Q-node child, or of a non-Q-node child that admits Type , or both. The second set consists of any number (possibly zero) of children that admit Type . The third set consists of any positive number of children that admit Type or Type , with at most one admitting only Type .

Lemma 12

A P-node \(\mu \) admits Type in the variable embedding setting if and only if Case NRR.1 or Case NRR.2 holds.

Proof

Let \(\mu _1, \dots , \mu _k\) be the children of \(\mu \). About the necessity, suppose that \(\mu \) admits a \(2\)UBE \(\gamma \) of Type and denote by \(\gamma _i\) the restriction of \(\gamma \) to \(\mu _i\). At most one \(\gamma _i\) can be of Type \(\langle N ,\cdot , \cdot \rangle \) and all of them must be of Type \(\langle \cdot ,\cdot , R \rangle \). Therefore, all of the \(\gamma _i\) must be of Type \(\langle R ,R, R \rangle \), or \(\langle N ,R, R \rangle \) or \(\langle \cdot ,B, R \rangle \). It follows that either one of the \(\gamma _i\) has Type (Case NRR.1) or one has Type , or none of the two (Case NRR.2). In Case NRR.1, there is nothing else to be proved for the necessity. In Case NRR.2, one of \(\gamma _i\) corresponds to a Q-node and has Type , or it corresponds to a non-Q-node and has Type , or both because otherwise \(\gamma \) would be of Type \(\langle \cdot ,B, R \rangle \); further one of the \(\gamma _i\) must have Type or , because otherwise \(\gamma \) would be of Type \(\langle R ,\cdot , R \rangle \).

For the sufficiency, we consider the two cases separately. In Case NRR.1 we order the children of \(\mu \) so that from left to right we have the possible Q-node child, if any, followed by the unique child that admits Type , followed by the children that admit Type in any order; see Fig. 16a. In Case NRR.2 we order the children of \(\mu \) so that from left to right we have the possible Q-node child, if any, followed by the possible non-Q-node child that admits Type , followed by the children that admit Type in any order, followed by the possible child that admits only Type , if any, followed by the children that admit Type in any order, if any; see Fig. 16b.

Assume that \(\mu _1,\mu _2,\dots ,\mu _k\) are ordered as defined above, according to the two cases NRR.1 and NRR.2. We show that such an ordering of the children of \(\mu \) can be used to construct a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\) of Type . For each \(\mu _i\) let \(\langle {\overline{\pi }}_i,\sigma _i \rangle \) be a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu _i})\) of the type of interest (i.e. the one considered in the description of the ordering); if \(\mu _1\) is a Q-node, then we consider \(\langle {\overline{\pi }}_1,\sigma _1 \rangle \) of Type , i.e., \(\sigma _1 \big ((s_\mu , t_\mu )\big )=L\). We denote by \(\pi _i\) the restriction of \({\overline{\pi }}_i\) to the vertices of \({{\,\textrm{pert}\,}}({\mu })\) different from \(s_\mu \) and from \(t_\mu \). We now describe how to construct a \(2\)UBE \(\langle \pi ,\sigma \rangle \) of \({{\,\textrm{pert}\,}}({\mu })\). In both cases NRR.1 and NRR.2, the assignment \(\sigma \) of the edges of \({{\,\textrm{pert}\,}}({\mu })\) to the two pages is the one determined by the assignments \(\sigma _i\), that is, \(\sigma (e)=\sigma _i(e)\) if \(e \in {{\,\textrm{pert}\,}}({\mu _i})\). The bottom-to-top ordering \(\pi \) of the vertices of \({{\,\textrm{pert}\,}}({\mu })\) is constructed in a different way in the two cases NRR.1 (see Fig. 16a) and NRR.2 (see Fig. 16b).

In Case NRR.1, \(\pi \) is constructed as \(s_\mu , \pi _1, \pi _2,\dots ,\pi _k, t_\mu \). In Case NRR.2, the children of \(\mu \) whose \(2\)UBEs have Type or Type are consecutive in the left-to-right sequence of the children of \(\mu \). Let \(\mu _p, \dots , \mu _q\) be the subsequence formed by these children, with \(2 \le p \le q \le k\). For each child \(\mu _i\), \(i=p,\dots , q\), by the definition of Type and Type , there exist two consecutive vertices \(v'\) and \(v''\) in \(\pi _i\) such that the portion of the spine between them is visible from the left. Therefore, we can split \(\pi _i\) into two subsequences \(\pi '_i\) and \(\pi ''_i\) where \(v' \in \pi '_i\) and \(v'' \in \pi ''_i\). Let \(\mu ^*\) be the possible child of \(\mu \) whose \(2\)UBE has Type . Ordering \(\pi \) is constructed as \(s_\mu , \pi '_p, \pi '_{p+1}, \dots , \pi '_q, \pi ^*, \pi ''_q, \pi ''_{q-1}, \dots , \pi ''_p, \pi _{q+1}, \dots \pi _k, t_\mu \), where \(\pi ^* = \emptyset \) if \(\mu ^*\) does not exist. In both Case NRR.1 and Case NRR.2, \(\langle \pi ,\sigma \rangle \) is of a \(2\)UBE of \({{\,\textrm{pert}\,}}({\mu })\) of Type . \(\square \)

To test whether \({{\,\textrm{pert}\,}}({\mu })\) admits a \(2\)UBE of Type , we show that deciding if one of Case NRR.1 or Case NRR.2 of Lemma 12 applies can be reduced to a flow problem on a network \({\mathcal {N}}\) with edge demands.

We describe the construction of \({\mathcal {N}}\) for Case NRR.2 (refer to Figs. 16b and 16c); the construction for Case NRR.1 is similar. Network \({\mathcal {N}}\) is a capacitated flow network where each arc e has a label [lu], where l and u are the lower and upper capacity of arc e. In particular, \({\mathcal {N}}\) contains a source s; a sink t; a node \(\mu _i\) for each child \(\mu _i\) of \(\mu \); a node , representing each embedding type used in constructing the sequence of Case NRR.2; and two special nodes \(\nu _1\) and \(\nu _2\). Network \({\mathcal {N}}\) contains the following arcs: \((s,\mu _i)\) with label [1, 1], for \(i = 1, \dots , k\); an arc \((\mu _i,\tau )\) with label [0, 1], for each type \(\tau \) for which \({{\,\textrm{pert}\,}}({\mu _i})\) admits a \(2\)UBE of Type \(\tau \); an arc with label [0, 1]; an arc with label [0, 1]; an arc \((\nu _1,t)\) with label [1, 2]; an arc with label \([0,\infty ]\); an arc with label [0, 1]; an arc with label \([0,\infty ]\); and an arc \((\nu _2,t)\) with label \([1,\infty ]\). The size of \({\mathcal {N}}\) is linear in the number k of children of \(\mu \), because the outdegree of nodes \(\mu _i\) is bounded by the number of embedding types, s has outdegree k, and the remaining nodes have outdegree at most 1.

Clearly, a sequence corresponding to Case NRR.2 exists if and only if \({\mathcal {N}}\) admits a feasible flow, which has value k. Testing the existence of a feasible flow can be reduced in linear time to a max-flow problem [74]. We solve this problem by applying the standard max-flow algorithm by Ford-Fulkerson, which runs in \(O(|E({\mathcal {N}}) |\times f)\), where f is the value of the maximum flow. Since \(|E({\mathcal {N}}) |\in O(k)\) and \(f=k\), deciding the existence of a \(2\)UBE of Type of \({{\,\textrm{pert}\,}}({\mu })\) takes \(O(k^2)\), which proves Lemma 8 for the case .

7 Conclusion and Open Problems

Our results provide significant advances on the complexity of the k UBE Testing problem, i.e., deciding whether a directed graph admits a k-page book embedding. For \(k \ge 3\) we showed that the problem is NP-hard; for \(k=2\) we described polynomial-time and FPT algorithms for notable families of planar st-graphs. We conclude with some open problems.

  1. OP1.

    The digraphs in our NP-completeness proof are not upward planar. Since there are upward planar digraphs that do not admit a 3UBE [72], one can ask whether the k UBE Testing problem remains NP-complete for \(k\ge 3\) and upward planar digraphs. Observe that this question has been solved for \(k=2\), as it is known that 2UBE Testing is NP-complete for planar st-graphs, which are upward planar [42].

  2. OP2.

    A natural extension of our work is to investigate other families of planar digraphs for which a \(2\)UBE always exists or for which polynomial-time testing algorithms can be devised.

  3. OP3.

    The complexity of our algorithm to test the existence of a \(2\)UBE for graphs with bounded branchwidth is dominated by the time complexity of computing a sphere-cut decomposition. This motivates the research of more efficient algorithms to compute a sphere-cut decomposition.