An FPT algorithm for the embeddability of graphs into two-dimensional simplicial complexes

We consider the embeddability problem of a graph G into a two-dimensional simplicial complex C: Given G and C, decide whether G admits a topological embedding into C. The problem is NP-hard, even in the restricted case where C is homeomorphic to a surface. We prove that the problem is fixed-parameter tractable in the size of the two-dimensional complex, by providing an O(2^{poly(c)}.n^2)-time algorithm. Moreover, we show that several known problems reduce to this one, such as the crossing number and the planarity number problems, and, under some additional conditions, the embedding extension problem. Our approach is to reduce to the case where G has bounded branchwidth via an irrelevant vertex method, and to apply dynamic programming. We do not rely on any component of the existing linear-time algorithms for embedding graphs on a fixed surface, but only on algorithms from graph minor theory.


Introduction
An embedding of a graph G into a host topological space X is a crossing-free topological drawing of G into X.The use and computation of graph embeddings is central in the communities of computational topology, topological graph theory, and graph drawing.A landmark result is the algorithm of Hopcroft and Tarjan [19], which allows to decide whether a given graph is planar (has an embedding into the plane) in linear time.Related results include more planarity testing algorithms [31], algorithms for embedding graphs on surfaces [20,28] and for computing book embeddings [25], Hanani-Tutte theorems [37], and the theory of crossing numbers and planarization [7].
In this paper, we describe an algorithm for deciding the embeddability of graphs into topological spaces that are, in a sense, as general as possible: two-dimensional simplicial complexes (or 2-complexes for brevity), which are made from vertices, edges, and triangles glued together.(We remark that every graph is embeddable in R 3 and thus in a 3-simplex, so considering higher-dimensional simplicial complexes is irrelevant.)In a previous article, jointly written with Mohar [13], we proved that, given a graph G and a 2-complex C , one can decide whether G embeds into C in polynomial time for fixed C ; but the algorithm has running time f (c) • n O(c) , where n and c are the respective sizes of G and C .Using a very different strategy, we prove in this paper that it is actually fixed-parameter tractable (FPT) in the complexity of the input complex, by providing an algorithm that is quadratic in n and exponential in a polynomial in c.Theorem 1.1.One can solve the embeddability problem of graphs into 2-dimensional simplicial complexes in 2 poly(c) •n 2 , where c is the number of simplices of the input 2-complex and n is the total number of vertices and edges of the input graph.
An additional motivation is that some other known problems related to graph drawing and planarity can be recast (and generalized) as deciding whether the graph embeds on a certain 2-complex.This includes the crossing number problem (whether a graph can be drawn in the plane with at most k crossings) [21] and the planarity number problem (whether a graph with a given set of U vertices can be embedded in the plane in such a way that U is covered by at most k faces) [4].These problems are NP-hard in general, and we solve them in quadratic time if k is fixed, in a unified way (and sometimes faster than previously known).We can also solve embedding extension problems, namely, embedding problems in which part of the graph is pre-embedded [3,28].We present these results in detail, with their proofs, in Section 10.
Every surface is homeomorphic to a 2-complex, but 2-complexes are much more general than surfaces, and tools that are suitable for studying embeddability of graphs on surfaces do not generalize.For example, the set of graphs embeddable on a given 2-complex is not closed under minor, which makes many tools for dealing with graphs on surfaces unsuitable for 2-complexes.Moreover, the complexity of some topological problems increase drastically when we consider 2-complexes instead of surfaces, e.g., deciding homeomorphism (solvable in linear time for surfaces, equivalent to graph isomorphism for 2complexes [30]), or deciding the contractibility of curves (solvable in linear time for surfaces [15,18,23], undecidable for 2-complexes [6,38]).See our previous paper with Mohar [13,Introduction] for more motivations.
Comparison with previous works on surfaces.The embeddability problem has been largely considered in the special case where the input 2-complex is (homeomorphic to) a surface.This problem is already NP-hard [39], and the existing algorithms that are fixed-parameter tractable in the genus are notoriously complicated; we review them now.
Mohar [28] has given an algorithm for embedding graphs on a fixed surface that takes linear time in the input graph, for every fixed surface.This algorithm is very technical and relies on several other articles.The dependence on the genus is not made explicit, but seems to be doubly exponential [20].
Kawarabayashi, Mohar, and Reed, in an extended abstract [20], have given a simpler linear-time algorithm for this problem, with a singly-exponential dependence in the genus, but not all details are presented, which makes the approach hard to check [22, p. 3657, footnote].
General graph minor theory provides an algorithm for the same purpose.The graph minor theorem by Robertson and Seymour [35] implies that, for every fixed surface S , there is a finite list of graphs O S such that a graph G can be embedded on S if and only if G does not contain any graph in O S as a minor.Moreover, there is an algorithm that given any surface S (specified by its genus and orientability) outputs the list O S [2], and there is an algorithm to decide whether a graph M is a minor of another graph G running, for fixed M , in time cubic in the size of G [34] [14,Theorem 6.12].These considerations thus lead to an algorithm to decide embeddability of a graph on a surface that runs, if the input surface is fixed, in cubic time in the size of the input graph.
Finally, in the same vein, Kociumaka and Ma.Pilipczuk [22] have studied the following more general problem than the embeddability problem of graphs on surfaces: Given a surface S , a graph G, and an integer k ≥ 0, is it possible to remove a set W of at most k vertices from G so that G − W is embeddable on S ?They provide an algorithm that is fixed-parameter tractable in k and the genus of S , where the dependence on the genus is unspecified.In particular, as a special case, they decide the embeddability of a graph on a surface; however, they use one of the previous algorithms [20,28] as a subroutine.The problem that we study, the embeddability of graphs on 2-complexes, is independent from the problem studied by Kociumaka and Pilipczuk, in the sense that there is, a priori, no obvious reduction from one problem to the other.However, we will reuse some ingredients from that paper.
Our algorithm, restricted to the case where we want to embed graphs on surfaces, is not as efficient as the existing algorithms mentioned above, because it runs in quadratic time for fixed genus.However, we stress that it is independent from the existing algorithms for embedding graphs on surfaces; we mostly rely on algorithms from graph minor theory (see in particular Lemma 8.2) and on graph planarity testing.
Overview and structure of the paper.We use a standard strategy in graph algorithms and parameterized complexity (see, e.g., the book by Cygan, Fomin, Kowalik, Lokshtanov, Marx, Pilipczuk, Pilipczuk, and Saurabh [14,Chapter 7]): we show by dynamic programming that the problem can be solved efficiently for graphs of bounded branchwidth, and then, using an irrelevant vertex method, we prove that one can assume without loss of generality that the input graph G has branchwidth bounded by a polynomial in the size of the input 2-complex.In the context of surface-embedded graphs, this paradigm has been used in the extended abstract by Kawarabayashi, Mohar, and Reed [20] and in the article by Kociumaka and Pilipczuk [22]; our algorithm takes inspiration from the former one, for the idea of the dynamic programming algorithm, and from the latter, for some arguments in the irrelevant vertex method.However, handling 2-complexes requires significantly more effort.More precisely, Theorem 1.1 follows immediately from the following two theorems.
Theorem 1.2 (algorithm for bounded branchwidth).We can solve the embeddability problem of graphs into two-dimensional simplicial complexes in time (c + w) O(c+w) • n time, where c is the number of simplices of the input 2-complex, n is the total number of vertices and edges of the input graph, and w is its branchwidth.
Theorem 1.3 (algorithm to reduce branchwidth).Given a 2-complex C with c simplices, and a graph G with n vertices and edges in total, we can, in 2 poly(c) • n 2 time, do one of the following: • correctly report that G is not embeddable on C , • or compute a subgraph G ′ of G, of branchwidth polynomial in c, such that G embeds on C if and only if G ′ does.
Moreover, if G embeds into C , then under mild conditions one can compute an embedding; see Section 9.
We now present the structure of the paper, indicating which techniques are used.We also emphasize which components would be simpler if we were just aiming for an algorithm for embedding graphs on surfaces.
We introduce some standard notions in Section 2. Sections 3 to 7 contain the proof of Theorem 1.2.In Section 3, we show that we can make some simplifying assumptions on the input, and present data structures for representing 2-complexes and graphs embedded on them.If we restrict ourselves to the case where the input 2-complex is homeomorphic to a surface, we essentially consider combinatorial maps of graphs on surfaces, except that the graphs need not be cellularly embedded (such a data structure is called an extended combinatorial map [12,Section 2.2]).The case of 2-complexes is largely more involved.
In Section 4, we show that if our input graph G has an embedding into our input 2-complex C , then there exists an embedding of G on C that is sparse with respect to a branch decomposition of G.This means that each subgraph of G induced by the leaves of any subtree of the branch decomposition can be separated from the rest of G using a graph embedded on C , called partitioning graph, of small complexity.We find that this new structural result, even in the surface case, is interesting and can prove useful in other contexts.If the target space were a surface, we could assume that G is 3-connected and has no loop or multiple edge, which would imply (still with some work) that any embedding of G would be sparse, but again the fact that we consider 2-complexes requires additional work.
In Section 5, we present the dynamic programming algorithm, which either determines the existence of an embedding of G on C , or shows that no sparse embedding of G on C exists (and thus no embedding at all, by the previous paragraph).The idea is to use bottom-up dynamic programming and to consider all regions of the 2-complex in which the subgraph of G (induced by a subtree of the branch decomposition) can be embedded.The complexity depends exponentially on the branchwidth of G.
The previous arguments, most notably in Section 4, implicitly assumed that, if G has an embedding into C , it has a proper and cellular embedding, in particular, in which the faces are homeomorphic to disks.In Section 6, we show that we can assume this property.Essentially, we build all 2-complexes "smaller" than C , such that G embeds on C if and only if it embeds into (at least) one of these 2complexes, and moreover if it is the case, it has an embedding into (at least) one of these 2-complexes that is proper and cellular.If C were an orientable surface, we would just consider the surfaces of lower genus; but here a more sophisticated approach is needed.
The above ingredients allow to prove Theorem 1.2 (Section 7).There remains to prove that one can assume that G has polynomial branchwidth (Theorem 1.3); the proof, almost independent from the above, is contained in Section 8.It uses an irrelevant vertex method: in a nutshell, if G has large branchwidth, we can compute a subdivision of a large wall, and then (unless G has large genus and is not embeddable on C ) compute a large planar part of G containing a large wall; the central vertex of this wall is irrelevant, in the sense that its removal does not affect the embeddability or non-embeddability of the graph into C ; iterating, we obtain a graph of branchwidth polynomial in the size of C .
In Section 9, we explain how to compute an embedding of G into C , if one exists, under mild conditions.
Finally, we prove the promised applications in Section 10.

Graphs and branch decompositions
In this paper, graphs may have loops and multiple edges unless noted otherwise.Let G be a graph; as usual, we denote by V (G) and E(G) the sets of vertices and edges of G. Dissolving a degree-two vertex v means replacing v and its incident edges vw 1 and vw 2 with a new edge between w 1 and w 2 .A (rooted) branch decomposition of G is a rooted tree B in which: • every node has degree either one (it is a leaf ) or three (it is an internal node), • the root is a leaf, • each non-root leaf is labelled with an edge of G, and this labelling induces a bijection, • the two children of each non-leaf node are ordered.
The vertices and edges of B are called nodes and arcs, respectively.Clearly, the number of nodes of B is linear in the number of edges of G.
Each arc α of B splits the tree B into two subtrees B 1 and B 2 ; if, for i = 1, 2, we denote by E i the set of labels appearing in B i , we see that α naturally induces a partition (E 1 , E 2 ) of the set of edges of G (if α is the arc incident to the root, then one part of the partition is empty).The middle set mid(α) associated with α is the set of vertices of G which are the endpoints of at least one edge in E 1 and at least one edge in E 2 .
The width of B is the maximum size of a middle set associated to an arc of B. The branchwidth of G is the minimum width of its (rooted) branch decompositions.
The usual definition of a branch decomposition is identical, except that the tree is unrooted (thus the leaves are in bijection with the edges of G) and children are unordered.Our definition turns out to be more convenient to use in the dynamic program.The difference is cosmetic: From any usual branch decomposition, one can trivially obtain a rooted branch decomposition of the same width, by subdividing an arbitrary arc with a new node ν and then connecting ν to a new leaf node ρ, which will serve as the root; the converse operation obviously transforms any rooted branch decomposition into a usual branch decomposition.Since each usual branch decomposition corresponds to a rooted branch decomposition, and both have the same width, we henceforth only work with rooted branch decompositions.

Surfaces
We will assume some familiarity with surface topology; see, e.g., [11,29,38] for suitable introductions under various viewpoints.We recall some basic definitions and properties.A surface (without boundary) S is a compact, connected Hausdorff topological space in which every point has an open neighborhood homeomorphic to the open disk.Up to homeomorphism, every surface S is obtained from a sphere by: An embedding of a graph G into a surface S is cellular if each face of the embedding is homeomorphic to an open disk.If G is cellularly embedded on a surface with genus g and b boundary components, such that the embedding has v vertices, e edges, and f faces, then Euler's formula stipulates that v − e + f = 2 − g − b (these quantities are referred to as the Euler characteristic of the surface).

2-complexes
A 2-complex (or two-dimensional simplicial complex) is an abstract simplicial complex of dimension at most two: a finite set of 0-simplices called vertices, 1-simplices called edges, and 2-simplices called triangles.Each edge is a pair of vertices, and each triangle is a triple of vertices; moreover, each subset of size two in a triangle must be an edge.(We slightly depart from the standard definition in the sense that, for us, a 2-complex is a simplicial complex in which each simplex has dimension at most two; there needs not be a simplex of dimension exactly two.)Each 2-complex C corresponds naturally to a topological space, obtained as follows: Start with one point per vertex in C ; connect them by segments as indicated by the edges in C ; similarly, for every triangle in C , create a triangle whose boundary is made of the three edges contained in that triangle.By abuse of language, we identify C with that topological space.

Graph embeddings
Each graph has a natural associated topological space (for graphs without loops or multiple edges, this is a specialization of the definition for 2-complexes).An embedding Γ of a graph G into a 2-complex C is an injective continuous map from (the topological space associated to) G to (the topological space associated to) C .A face of Γ is a connected component of the complement of the image of Γ in C .

Some preprocessing
A 3-book is a topological space obtained from three triangles by considering one side per triangle and identifying these three sides together into a single edge.We say that a 2-complex C contains a 3-book if C contains three distinct triangles that share a common edge.Proposition 3.1.To decide the embeddability of a graph G on a 2-complex C , we can without loss of generality, after a linear-time preprocessing, assume the following properties on the input: • C has no 3-book and no connected component that is reduced to a single vertex; • G has no connected component reduced to a single vertex, and at most one connected component that is a path.Proof.It is known that every graph can be embedded into a 3-book [13, Proposition 3.1].So we can without loss of generality assume that C contains no 3-book.We remove all the isolated vertices of C , and remove the same number of isolated vertices of G (to the extent possible); this does not affect whether G embeds into C .We then replace each isolated vertex of G with an isolated edge; since C has no more isolated vertex, this does not affect embeddability of G into C .Finally, for the same reason, if G contains at least two connected components that are paths, we replace all these components with a single edge.
In the rest of this article, without loss of generality, we implicitly assume that C and G satisfy the properties stated in Proposition 3.1.

Structure of 2-complexes without 3-book or isolated vertex
Let C be a 2-complex without 3-book or isolated vertex, and let p be a vertex of C .Following [13, Section 2.2], we describe the possible neighborhoods of p in C .A cone at p is a cyclic sequence of triangles t 1 , . . ., t k , t 1 (k ≥ 3), all incident to p, such that, for each i = 1, . . ., k, the triangles t i and t i+1 (where t k+1 = t 1 ) share an edge incident with p, and any other pair of triangles have only p in common.A corner at p is a sequence of distinct triangles t 1 , . . ., t k , all incident to p, such that, for each i = 1, . . ., k − 1, the triangles t i and t i+1 share an edge incident with p, any other pair of these triangles have only p in common, and no other triangle in C shares an edge incident with p and belonging to one of t 1 , . . ., t k .An isolated edge at p is an edge incident to p but not incident to any triangle.The cones, corners, and isolated edges at p form the link components at p.
The set of edges and triangles incident with a given vertex p of C are uniquely partitioned into cones, corners, and isolated edges.We say that p is a regular vertex if all the edges and triangles incident to p form a single cone or corner; in that case, p has an open neighborhood homeomorphic to a disk or a closed half-disk.Otherwise, p is a singular vertex .See Figure 3.1, left, for an illustration.
Detaching a singular vertex v in C consists of the following operation: replace v with new vertices, one for each cone, corner, and isolated edge at v. Detaching all singular vertices of a 2-complex (without 3-book) yields a disjoint union of (1) isolated edges and (2) a surface, possibly disconnected, possibly with boundary, called the detached surface (see Figure 3.1, right).The trace of the singular vertices on the detached surface are the marked vertices.Conversely, C can be obtained from a surface (possibly disconnected, possibly with boundary) and a finite set of segments by choosing finitely many subsets of points and identifying the points in each subset together.
The boundary of C is the closure of the set of points of C that have an open neighborhood homeomorphic to a closed half-plane.Equivalently, it is the union of the edges of C incident with a single triangle.

Topological data structure for 2-complexes
We now describe a topological data structure for 2-complexes without 3-book or isolated vertex that is more appropriate for our purposes.It records only the 2-complex up to homeomorphism, not the combinatorial information given by its simplices.Such a 2-complex C is obtained from a surface S (possibly disconnected, possibly with boundary) and a finite set S of segments by identifying together finitely many finite subsets of points.Our data structure stores separately the detached surface S , the set S of isolated edges, and the singular vertices, and two-way pointers representing incidences between them.In more detail: • we store the list of the connected components of the detached surface S , and for each such component S ′ we store (1) whether it is orientable or not; (2) its genus; (3) a list of pointers to the singular vertices in the interior of S ′ ; (4) for each boundary component of S ′ , a cyclically ordered list of pointers to the singular vertices appearing on that boundary component (if S ′ is orientable, the boundary components must be traversed in an order consistent with an arbitrarily chosen orientation of S ′ ); • we store the list S of isolated edges, and for each of them, two pointers to the singular vertices at its endpoints; • conversely, to each singular vertex is attached a list of pointers to the occurrences of that singular vertex on the detached surface or as an endpoint of an isolated edge.
The size of a 2-complex (without 3-book or isolated vertex) is the sum of the number of isolated edges, the number of connected components of the detached surface, the total genus of the detached surface, the total number of boundary components of the detached surface, and the total number of marked vertices of the detached surface (the occurrences of the singular vertices).This is, up to a constant factor, the size of the topological data structure indicated above, if the genus is stored in unary.
Given a 2-complex C without 3-book or isolated vertex, described by vertices, edges, and triangles and their incidence relations, we can easily compute a representation of C in that data structure, in polynomial time: Indeed, by ignoring the incidences created by vertices, we easily build a triangulation of the surface S (possibly disconnected, possibly with boundary) and a list of segments S; we then compute the topology of S ; finally, we mark the singular vertices, which are the vertices with several occurrences on S and/or on S. We remark that the size of the resulting data structure is at most linear in the number of vertices, edges, and triangles of the 2-complex C , because, by Euler's formula, any triangulated surface (possibly with boundary) with k simplices has genus O(k) and a number of boundary components that is O(k).Thus, in the rest of this article, without loss of generality, we implicitly assume that C is given in the form of the above topological data structure.(Conversely, it is not hard to see that every 2-complex is homeomorphic to a 2-complex whose number of simplices that is linear in its size, but we will not need this fact.) We will need the following lemma.Proof.(We remark that this essentially follows from more general results [30]; the running time of our algorithm might be improvable, but this suffices for our purposes.)As a preprocessing, in the topological data structures of C and C ′ , we do the following: whenever a singular vertex is incident to exactly two isolated edges and is not incident to the detached surface, we dissolve that singular vertex, removing it and replacing the two incident edges with a single one.Clearly, this does not affect whether C and C ′ are homeomorphic.After this preprocessing, C and C ′ are homeomorphic if and only if their topological data structures are isomorphic.By this, we mean that there is a bijective correspondence φ from the isolated edges, the connected components of the detached surface, and the boundary components of each connected component of the detached surface of C to those of C ′ that preserves the genus, the orientability, the incidences, and the cyclic ordering of the singular vertices on each boundary component.More precisely, for the latter point: for each connected component C of the detached surface of C , if C is orientable, then the lists of singular vertices appearing on each boundary component of C and φ(C) are identical up to global reversal of all these cyclic orderings simultaneously, corresponding to a change of the orientation of the connected component; if C is non-orientable, then the lists of singular vertices appearing on each boundary component of C and φ(C) are identical up to the possible individual reversal of some of these cyclic orderings.The proof is tedious but straightforward, and the existence of an isomorphism can obviously be tested in the indicated time.

Proper and cellular graph embeddings on 2-complexes
Let C be a 2-complex with size c, G a graph, and Γ an embedding of G on C .The embedding Γ is proper if: • the image of Γ meets the boundary of C only on singular vertices; • the vertices of Γ cover the singular vertices of C .
The embedding Γ is cellular if each face of Γ is an open disk plus possibly some part of the boundary of C .We emphasize that this definition slightly departs from the standard one.Moreover, we will only consider cellular embeddings that are proper.
Traditional data structures for graphs on surfaces handle graphs embedded cellularly; rotation systems [29] constitute one example of such a data structure.In order to have efficient algorithms, refined data structures, e.g., with graph-encoded maps [24] (see also [16,Section 2]), are needed.The basic element in the graph-encoded map is the flag, an incidence between a vertex, an edge, and a face of the graph.Three involutions allow to move from each flag to a nearby flag.Each flag contains a pointer to the underlying vertex, edge, and face.
One can easily extend such data structures to possibly non-cellular embeddings on surfaces [12, Section 2.2].In this framework, one must store the topology of each face, which is not necessarily homeomorphic to a disk.Also, a face may have several boundary components; two-way pointers connect each face to one flag of each boundary component (or to an isolated vertex of the graph, if that boundary component is a single vertex); if a face is orientable and has several boundary components, then these pointers must induce a consistent orientation of these boundary cycles.It is important to remark that this data structure also allows to recover the topology of the underlying surface.
Let Γ be a proper graph embedding of a graph G on a 2-complex C (under the assumptions of Proposition 3.1).Let S be the detached surface of C .Because Γ is proper, it naturally induces an embedding Γ ′ , of another graph G ′ , on S ; each vertex of G located on a singular vertex of C appears as many times in G ′ as there are cones and corners at that singular vertex; the vertices of G located in the relative interior of isolated edges are absent from G ′ .Our data structure, called combinatorial map, for storing the graph embedding Γ and the 2-complex C consists of storing (1) the graph embedding Γ ′ on S , as indicated in the previous paragraph, (2) the isolated edges of C , together with, for each such isolated edge, an ordered list alternating vertices and edges of Γ (or, instead of an edge, a mark indicating the absence of such an edge in the region of the isolated edge between the incident vertices), (3) the identifications of vertices of Γ ′ that are needed to recover Γ (and thus implicitly C ).
Isomorphisms between combinatorial maps are defined in the obvious way, similar to the concept of isomorphism between topological data structures: Two combinatorial maps are isomorphic if there is an isomorphism between the combinatorial maps restricted to the detached surfaces, isomorphisms between the maps on each isolated edges, and such that incidences are preserved on the singular vertices.We can easily test isomorphism between two combinatorial maps of size k and k ′ , respectively, in (k + k ′ ) O(k+k ′ ) time.
We will need an algorithm to enumerate all proper embeddings of small graphs on a given 2-complex.This is achieved in the following lemma.Lemma 3.3.Let C be a 2-complex of size c and k an integer.We can enumerate the (c + k) O(c+k) combinatorial maps of graphs with at most k vertices and at most k edges properly embedded on C in Proof.The strategy is the following.In a first step, we enumerate a set of proper graph embeddings on some 2-complexes, which necessarily contains all the desired combinatorial maps.In a second step, we prune this set to keep only the desired combinatorial maps, by eliminating those that contains too many vertices or edges, or that correspond to an embedding on a 2-complex not homeomorphic to C .We first enumerate, in a possibly redundant way, the set M 1 of combinatorial maps of cellular graph embeddings with at most k + c vertices and k edges on a possibly disconnected surface without boundary.There are (c + k) O(c+k) such combinatorial maps, which can be enumerated in (c + k) O(c+k) time, for example using rotation systems.Some vertices may be isolated, if the corresponding connected component of S is a sphere.
By simplifying the surface, every graph embedding can be transformed into a cellular graph embedding: remove each face and paste a disk to each cycle of the graph that was a boundary component of a face.Conversely, every (possibly non-cellular) graph is obtained from some cellular one by (1) connecting some faces together (creating a face of genus zero with several boundary components) and ( 2) adding some genus and non-orientability to some faces.So, for each map in M 1 , we perform all these operations in all possible ways, by putting genus at most c in each face.For each such map in M 1 , there are (c+k) O(c+k) possibilities.We thus obtain, in (c+k) O(c+k) time, a set M 2 of (c+k) O(c+k) combinatorial maps on surfaces, and the set M 2 contains all combinatorial maps of (possibly non-cellular) graph embeddings on surfaces of genus at most c.
Finally, we add at most c isolated edges, choose how endpoints of these isolated edges and vertices of the embedding on the detached surface are identified, and decide how each isolated edge is covered by the embedding.There are (c + k) O(c+k) ways to do this.We thus have computed, in (c + k) O(c+k) time, a set M of (c + k) O(c+k) combinatorial maps of graphs on 2-complexes, which contains all the combinatorial maps indicated in the statement of the lemma.
Second step.First, we easily discard the combinatorial maps in M containing more than k vertices or k edges.Then, we discard the maps in M corresponding to a 2-complex different from C .For this purpose, for each map m in M , we iteratively remove the edges of the graph embedding, preserving the underlying 2-complex.When removing an edge from the detached surface, the topology of the incident face(s) change; we preserve this information.Finally, we remove every isolated vertex that does not lie on a singular vertex of the 2-complex.The data structure that we have now is essentially the one that is described in Section 3.3; we can thus easily decide whether that 2-complex is homeomorphic to C (Lemma 3.2), and discard m if and only if it is not the case.
Finally, and although this is not strictly needed, we can easily remove the duplicates in the combinatorial maps, by testing pairwise isomorphism between these maps.

Graphs embeddable on a fixed 2-complex have bounded genus
Lemma 3.4.Let C be a 2-complex without 3-book.Let c be either the size of C or its number of simplices.Every graph embeddable on C is embeddable on a surface of (Euler) genus at most 10c.
Proof.The strategy is to construct a surface S of genus at most 10c such that every graph embeddable on C is also embeddable on S .The surface S is obtained by replacing every isolated edge of C with a cylinder, and modifying the structure of the 2-complex in the neighborhood of each singular vertex to make it surface-like; see Figure 3  In more detail, we can obviously assume that C has no isolated vertex.First, we replace every isolated edge of C with a cylinder.Then, for every singular vertex v, we do the following.We remove a small neighborhood of v.We create a sphere with k boundary components, where k is the number of link components at v. Finally, we attach a link component to each of the k boundary components of the sphere: • for each link component that was a cone, a small neighborhood of v was removed, with boundary a circle; we attach that circle bijectively to a boundary component of the sphere; • for each link component that was a corner, a small neighborhood of v was removed, with boundary a segment; we attach that segment to a part of a boundary component of the sphere; • for each link component that was an isolated edge, the isolated edge was replaced with a cylinder; we attach the corresponding boundary component of that cylinder bijectively to a boundary component of the sphere.
(We remark that there are several ways to perform these operations, depending on the orientation of the gluings; any choice will do.)The resulting surface S , which is possibly non-connected and possibly with boundary, has genus at most 10c.Indeed, if c is the size of C , this follows from Euler's formula (intuitively, the number of "handles" created is at most the number of link components).If c is the number of simplices of C , it follows from the fact that the total genus of the detached surface is at most c, again by Euler's formula, and from the fact that each isolated edge or triangle contributes to an increase of at most six for the genus in the construction above.
Consider an embedding of a graph G on C .It is not hard to transform that embedding into an embedding of G on S : Each cylinder replacing an isolated edge is used only along a single path connecting its two boundary components; if a singular vertex v is used by the embedding of G on C , we can locally modify the embedding to accommodate the local change from C to S at v (see again Figure 3.2).Of course, if G is embeddable on S , it is embeddable on some connected surface of genus at most 10c.
As a side remark, it follows from the above lemma and from Euler's formula that, if G is simple and embeds on C , then its number v of vertices and e of edges satisfy e ≤ 3v + 30c.We will actually not use this fact, in particular because we do not assume G to be simple, and because, for simplicity, we chose to express all our results in terms of n, the total number of vertices and edges of G, and not in terms of the number of vertices only.

Partitioning graphs
Let C be a 2-complex and G a graph, which satisfy the properties of Proposition 3.1.In this section, we lay the structural foundations of the dynamic programming algorithm, described in the next section (Proposition 5.1).The goal, in this section and the following one, is to obtain an algorithm that takes as input C and G and, in time FPT in the size of C and the branchwidth of G, reports correctly one of the following two statements: • G has no proper cellular embedding on C , • G has an embedding on C , This algorithm uses dynamic programming on a rooted branch decomposition of G.When processing a node of the rooted branch decomposition, it considers embeddings of the subgraph of G induced by the edges in the leaves of the subtree rooted at that node in a region of C .This region will be delimited by a partitioning graph embedded on C .Our dynamic program will roughly guess the partitioning graph at each node of the rooted branch decomposition.For this purpose, we need that, if G has a proper cellular embedding on C , it has such an embedding that is sparse: at each node of the rooted branch decomposition of G, the partitioning graph corresponding to the embedding of the induced subgraph is small (its size is upper-bounded by a function of the branchwidth of G and of the size of C ).The goal of this section is to prove that this is indeed the case.
Let (E 1 , . . ., E k ) be a partition of the edge set E(G) of G. (We will only use the cases k = 2 and k = 3.)The middle set mid(E 1 , . . ., E k ) of (E 1 , . . ., E k ) is the set of vertices of G whose incident edges belong to at least two sets E i .
Let Γ be a proper cellular embedding of G on C .Since Γ is cellular, every boundary of C is incident to at least one vertex of Γ.The partitioning graph Π(Γ, E 1 , . . ., E k ) (or more concisely Π) associated to Γ and (E 1 , . . ., E k ) is a graph properly embedded on C (but possibly non-cellularly), with labels on its faces, defined as follows: • The vertex set of Π is the union of the singular vertices of C and of (the images under Γ of) mid(E 1 , . . ., E k ).Each vertex of Π is labelled v ∈ mid(E 1 , . . ., E k ) if it is mapped, on C , to the same location as v under Γ; the other vertices of Π are unlabelled.
• The relative interiors of the edges of Π are disjoint from the edges of Γ and from the isolated edges of C .Let f be a face of Γ; because Γ is cellular, f is homeomorphic to an open disk plus possibly some points of the boundary of C .Let us describe the edges of Π inside f .
If, for some i ∈ {1, . . ., k}, the boundary of f is comprised only of edges of Γ that lie in a single set E i (together with their endpoints), then Π contains no edge inside f .Similarly, if the boundary of f is entirely included in the boundary of C , then Π contains no edge inside f .
Otherwise, the boundary of f is a succession of edges of E 1 , E 2 , . . ., E k , and of pieces of the boundary of C (possibly including singular vertices).The edges of Π inside f run along the boundary of f ; for each i ∈ {1, . . ., k}, for each (maximal) group of consecutive edges in E i along the boundary of f , there is an edge of Π that runs along this group, with endpoints the corresponding vertices on the boundary of f (see Figures 4.1 and 4.2).These vertices either are in mid(E 1 , . . ., E k ), or lie on the boundary of C (and thus on singular vertices of C , because Γ is proper).It follows from the construction that Γ and Π intersect only at common vertices.
• Each face of Π is labelled by an integer in {0, . . ., k} as follows: faces of Π containing an edge in E i are labelled i, and the other ones are labelled 0. Since Π contains the singular vertices of C and mid(E 1 , . . ., E k ), and by the construction of the edges of Π, this labelling is well defined.We remark that this definition is valid also for faces of Π that are parts of an isolated edge of C .
Henceforth, we fix a rooted branch decomposition B of G. Every arc α of B naturally partitions E(G) into two parts E 1 and E 2 ; this partition is the edge partition associated to α.Although this will play a role only in the next section, we choose E 1 and E 2 so that E 1 is on the side of the  root of the branch decomposition B. Recall that Γ is a proper and cellular embedding of G on C ; we let Π(Γ, α) be Π(Γ, E 1 , E 2 ).Similarly, every internal node ν of B naturally partitions E(G) into three parts E 1 , E 2 , and E 3 , in which E 1 is on the side of the edge incident with ν that is the closest to the root, E 2 corresponds to the edges of G that are leaves of the subtree rooted at the first child of ν, and E 3 corresponds to the edges of G that are leaves of the subtree rooted at the second child of ν.This partition is the edge partition associated to ν; we let Π(Γ, ν) be Π(Γ, E 1 , E 2 , E 3 ).
We say that Γ is sparse (with respect to B) if the following conditions hold, letting c be the size of C and w the width of B: • For each arc α of B, the graph Π(Γ, α) has at most 75c + 27w edges; • similarly, for each internal node ν of B, the graph Π(Γ, ν) has at most 3(75c + 27w)/2 edges.The result of this section is the following.Then it has a proper cellular embedding Γ on C that is sparse (with respect to B).

Monogons and bigons
A monogon of a graph Π embedded on a 2-complex C is a face of Π that is an open disk whose boundary is a single edge of Π (a loop).Similarly, a bigon of Π is a face of Π that is an open disk whose boundary is the concatenation of two edges of Π (possibly the same edge appearing twice).The following general lemma on graphs embedded on surfaces without monogons or bigons will be used below, and also in Section 8; some particular cases have been used before [8, Lemma 2.1].Lemma 4.2.Let S be a surface of genus g without boundary.Let Π be a graph embedded on S , not necessarily cellularly.Assume that Π has no monogon or bigon.Then Proof.We begin by adding edges to Π as long as it is possible to do so, without introducing any new vertex, monogon, or bigon.Let Π ′ be the resulting embedded graph.We claim that every face of Π ′ is a triangle (a disk incident with three edges), except in the following cases: 1. Π ′ is the empty graph; 2. S is a sphere, and Π ′ has two vertices and no edge; 3. S is a sphere, and Π ′ has a single vertex and no edge; 4. S is a projective plane, and Π ′ has a single vertex and no edge.Indeed, let f be a face of Π ′ .If f has no boundary component, then since S is connected, we are in Case 1 (an isolated vertex would account for a boundary component).Assume that f has at least two boundary components.We add an edge in f connecting vertices on these two boundary components.This cannot create any monogon or bigon, except if the two boundary components are both reduced to a single vertex and S is a sphere (Case 2).So we can assume that f has a single boundary component.If f is orientable and has genus zero, then either we are in Case 3, or S is a disk of degree at least four, in which case we can add an edge to split it into smaller disks without creating any monogon or bigon.If f is orientable and has Euler genus at least two (i.e., orientable genus at least one), we can add an edge that forms a non-separating arc (relatively to the boundary) in f ; it does not form any monogon or bigon.If f is non-orientable and has (non-orientable) genus at least two, we can add an edge that forms a separating arc in f , cutting that surface into two non-orientable surfaces of genus at least one; it does not form any monogon or bigon.Finally, if f is non-orientable and has (non-orientable) genus one, either the boundary component is reduced to a single vertex, so we are in Case 4, or this face has degree at least one; then it is a Möbius band with at least one vertex and one edge on its boundary, and we can add a loop that is a non-contractible arc (relatively to the boundary) in f , without forming any monogon or bigon.The only remaining possibility is that f is a triangle.
It is clear that the statement of the lemma holds whenever we are in one of the four above cases.So we can assume without loss of generality that each face of Π ′ is a triangle.Since V (Π) = V (Π ′ ) and |E(Π)| ≤ |E(Π ′ )|, it suffices to prove the result for Π ′ instead of Π. Double-counting the incidences between edges and faces implies that the number of triangles

Vertex simplifications
The proof of Proposition 4.1 starts with any proper cellular embedding of Γ, and iteratively changes the ordering of edges around vertices in a specific way.Let (E 1 , E 2 ) be a partition of E(G), let v be a vertex of G, and let C be a link component at v (if the image of v under Γ is a singular vertex, there may be several such link components).We restrict our attention to the edges of Γ incident to v and belonging to C, ordered cyclically or linearly as follows.If, in C, vertex v is not incident to a boundary of C , we consider these edges in cyclic ordering around v. Otherwise, vertex v is incident to a single boundary of C , and we break this cyclic ordering at the boundary to obtain a linear ordering.
For i = 1, 2, an interval (at v, relatively to (E 1 , E 2 )) is a maximal contiguous subsequence of edges in this (cyclic or linear) ordering that all belong to E i ; the interval is labelled i.This interval is exterior if the ordering is linear (because v is incident to a boundary of C ) and it is the first one or the last one in this linear order; otherwise, the interval is interior .Simplifying v (with respect to (E 1 , E 2 )) means changing the (cyclic or linear) ordering of the edges of Γ incident to v in C by one of the two following operations (Figure 4.3): 1. either exchanging two consecutive interior intervals in that ordering, in such a way that the ordering of the edges in each interval is preserved; this operation is allowed only if v is incident to at least four intervals; 2. or performing the previous operation twice, on two disjoint pairs of consecutive interior intervals in that ordering; this is allowed only if v is incident to at least six intervals.
We will rely on the following lemma.
Lemma 4.3.Let Γ be a proper cellular embedding of G on C , and let (E 1 , E 2 ) be a partition of E(G).Let Γ ′ be another proper cellular embedding of G, obtained from Γ by simplifying one or two vertices with respect to (E 1 , E 2 ), while keeping the orderings of the other vertices unchanged.Then: 2. for each partition ( Ẽ1 , Ẽ2 ) of E(G) such that Ẽi ⊆ E j for some i, j ∈ {1, 2}, we have Proof.We first observe that the number of half-edges of Π(Γ, E 1 , E 2 ) at v in the link component C equals twice the number of intervals associated to (E 1 , E 2 ) at v in C. (This fact will be reused later.)Also, we observe that a simplification at v decreases the number of intervals at v (actually, by at least two), because the (cyclic or linear) number of alternations between E 1 and E 2 decreases.This implies the first point of the lemma.
For the second point, let us consider, in the (cyclic or linear) ordering around v in C, a maximal contiguous sequence of edges in Ẽi .Since Ẽi ⊆ E j , when simplifying with respect to (E 1 , E 2 ), this sequence is still contiguous in the new embedding Γ ′ .If the ordering is cyclic (no boundary incident to v at C), it follows that the number of intervals associated to ( Ẽ1 , Ẽ2 ) does not increase when replacing Γ with Γ ′ .If the ordering is linear, this fact is still true, because the first and last edges in this ordering are unaffected (since only interior intervals are exchanged).This concludes the proof.

Rearranging Γ with respect to an edge partition
We can now prove the following lemma: Lemma 4.4.Let Γ be a proper cellular embedding of G on C , and let (E 1 , E 2 ) be a partition of E(G).There exists a proper cellular embedding Γ ′ of G such that: Proof.
Here is an overview of the proof.Let Π := Π(Γ, E 1 , E 2 ).We will assume that Π has "many monogons or bigons" (in a sense made precise below) and show that there is another cellular embedding Γ ′ of G such that: • for each partition ( Ẽ1 , Ẽ2 ) of E(G) such that Ẽi ⊆ E j for some i, j ∈ {1, 2}, we have By repeatedly iterating this argument, and up to replacing Γ with Γ ′ , this implies that we can assume without loss of generality that Π has "not too many monogons or bigons".We will then show that this latter property implies that Π has at most 75c + 27w edges, which concludes.First, let v be a vertex of Π, and let C be a link component of C at v in Π.By construction of Π, no monogon of Π is labelled 0. Let us assume that v has at least 8 incident half-edges of Π in C (and thus at least four intervals), and that Π has, at v in C, a monogon enclosing an interior interval.In particular, a non-empty subgraph of Γ lies inside the monogon, attached to the rest of Γ only by v, and corresponds to an interior interval s of Γ at v in C. We move the part of Γ that lies inside the monogon on the other side of the edges comprising an adjacent interior interval s ′ (which exists because Π has at least four intervals at v in C); see Figure 4.4.This simplifies v by swapping s with s ′ , because Γ has at least four intervals at v in C. Note that there is no singular vertex in the interior of the monogon, because there would be a vertex of Π located on the singular vertex.The resulting graph embedding Γ ′ is still proper and cellular, and satisfies the desired properties, by Lemma 4.3.Now, let us assume that Π contains a sequence of bigons B 1 , . . ., B 8 such that B i and B i+1 share an edge for each i.So without loss of generality, we can assume that B 1 and B 5 are labelled 1, B 3 and B 7 are labelled 2, and the other bigons are labelled 0. We modify Γ by exchanging the parts of Γ inside B 3 and B 5 ; see Figure 4.5.The resulting embedding Γ ′ is also proper and cellular.This operation simplifies the endpoints u and v of these bigons.(If u = v, this is Case 2 from the definition of a simplification.) We can iterate the above procedures, but only finitely many times because |E(Π(Γ, E 1 , E 2 ))| strictly decreases at each step (Lemma 4.3).We have proved that, up to changing our initial embedding Γ, we can assume without loss of generality the following: (i) Let v be a vertex of Π that is incident, in a link component C, to a monogon of Π corresponding to an interior interval; then v is incident to at most 7 half-edges in C; (ii) Π has no sequence of 8 consecutive bigons as above.To conclude, it suffices to prove that any graph Π satisfying these conditions has at most 75c + 27w edges.We modify Π by iteratively removing all edges that are monogons, and then by iteratively replacing each bigon with a single edge, when the edges bounding the bigon are distinct.The removal of monogons does not create any sequence of 8 consecutive bigons, because monogons are attached to vertices of degree at most 7 in their link component or correspond to exterior intervals.So in the first step, for each vertex v and each link component C of v, at most three monogons in C attached to v are removed; the number of such monogons is at most 3w (for the vertices of Π not on a singular vertex of C ) plus 3c (for the vertices of Π on singular vertices of C ).In the second step, the number of edges is divided by at most 8. Thus, if Π ′ denotes the new embedding, we have: We now bound the number of edges of Π ′ .For this purpose, let S be the detached surface of C , and let Π ′′ be the graph naturally corresponding to Π ′ on S (see Section 3.4).Any bigon of Π ′′ whose boundary consists of the same edge repeated twice is itself a connected component of S : either a sphere, in which case the corresponding connected component of Π ′′ is made of two vertices and a single edge, or a projective plane, in which case the corresponding connected component of Π ′′ is made of a single vertex and a single edge.Thus, in these connected components, the number of edges of Π ′′ is at most the number of vertices.Let S 0 be obtained from S by removing these connected components, and Π ′′ 0 the restriction of Π ′′ to S 0 .Π ′′ 0 has no monogon or bigon.Let S0 be obtained from S 0 by attaching a handle to each boundary component; it has a natural cellular graph embedding with at most 2c edges, and thus genus at most 2c by Euler's formula; the graph Π ′′ 0 corresponds to an embedding of a graph Π′′ 0 on S0 , with no monogon or bigon.

Proof of Proposition 4.1
Proof of Proposition 4.1.Let B be a rooted branch decomposition of G, and let Γ be a proper cellular embedding of G on C .We consider each arc α of the rooted branch decomposition in turn, in an arbitrary order.For each such arc, we modify Γ by applying Lemma 4.4.We first claim that after these iterations, for each arc α of B, we have |E(Π(Γ, α))| ≤ 75c + 27w.
First, immediately after applying the above procedure to an arc α of B, corresponding to the partition ( Ẽ1 , Ẽ2 ) of E(G), we have |E(Π(Γ, Ẽ1 , Ẽ2 ))| ≤ 75c + 27w.We now prove that subsequent applications of Lemma 4.4 to other arcs of the rooted branch decomposition do not increase this number of edges.Indeed, let α be another arc, corresponding to the partition (E 1 , E 2 ) of E(G), to which we apply Lemma 4.4.The arc α partitions the nodes of the tree B into two sets N 1 and N 2 , and similarly α partitions the nodes of the tree B into two sets Ñ1 and Ñ2 .Because B is a tree, we have Ñi ⊆ N j for some i, j ∈ {1, 2}.This implies that Ẽi ⊆ E j for some i, j ∈ {1, 2}; so the second item of Lemma 4.4 implies that the number of edges of Π(Γ, Ẽ1 , Ẽ2 ) does not increase when processing arc α.This proves the claim.
Finally, there remains to prove that, for each internal node ν of B, the graph Π(Γ, ν) has at most 3(75c + 27w)/2 edges.Let (E 1 , E 2 , E 3 ) be the edge partition associated with ν.By the claim we have just proved, it suffices to prove that the number of edges of this graph is at most half the sum of the numbers of edges of Π(Γ, Let v and C be as above.Any half-edge of Π(Γ, ν) incident with v and on C arises, in cyclic order around v, (1) either between two half-edges of Γ, or (2) between a half-edge of Γ and a boundary part of C incident with v on C. We consider each of these cases in turn below.
Between two half-edges of Γ, there are either zero or two half-edges in Π(Γ, ν).In the latter case, this means that these two consecutive half-edges of Γ are in two different sets E i and E j .Thus, between these two consecutive half-edges of Γ, necessarily two half-edges appear in exactly two of Between a half-edge and a boundary part, there is a single half-edge in Π(Γ, ν), and also in This concludes the proof of the proposition.

Dynamic programming algorithm
The result of this section is the following proposition.
Proposition 5.1.Let C be a 2-complex and G a graph, which satisfy the properties of Proposition 3.1.
Let c be the size of C and n the number of vertices and edges of G. Let B be a rooted branch decomposition of G of width w.In (c + w) O(c+w) n time, one can report one of the following statements, which is true: • G has no sparse proper cellular embedding into C ; • G has an embedding into C .
(Proposition 4.1 implies that we can remove the adjective "sparse" in the above proposition.)

Bounding graphs
Let B be a rooted branch decomposition of G of width w.Recall (see Section 2.1) that the root of B is a leaf associated to no edge of G. Our algorithm will use dynamic programming in the rooted branch decomposition.In the following, we fix an arc α of B, and we let G α be the subgraph of G induced by the edges of G corresponding to the leaves of the subtree of B rooted at α.The general idea is that we compute all possible relevant embeddings of G α in subregions of C .Such subregions will be delimited by a graph embedded on C of small complexity.For the dynamic program to work, we also need to keep track of the location of the vertices in the middle set of α.More precisely, we define bounding graphs below; partitioning graphs are, in particular, bounding graphs.A bounding graph for G α is a proper labelled graph embedding Π on C (but possibly non-cellular), such that: • some vertices of Π are labelled; these labels are exactly mid(α), and each label appears exactly once; • each unlabelled vertex of Π is mapped to a singular vertex of C ; • each face of Π is labelled 0, 1, or 2; • G α has an embedding Γ α that respects Π: each vertex of Π labelled v is mapped, under Π, to the image of v in Γ α ; moreover, the relative interior of each edge of Γ α lies in the interior of a face of Π labelled 2.
(It may seem strange to have three labels for the faces of a bounding graph, but it simplifies the argumentation, although two would suffice.)A bounding graph for G α is sparse if it has at most 75c + 27w edges.Remark that, if Γ is a sparse proper cellular embedding of G on C (as defined in Section 4), then Π(Γ, α) is a sparse bounding graph for the restriction of Γ to G α .
Henceforth, we regard two (labelled) proper graph embeddings as equal if and only if their (labelled) combinatorial maps are isomorphic.This convenient abuse of language is legitimate because whenever two proper graph embeddings have the same combinatorial map, there is an ambient selfhomeomorphism of C that maps one into the other.
A list L α of sparse bounding graphs for G α is exhaustive if the following condition holds: If G has a sparse proper cellular embedding on C , then for each such embedding Γ, the (combinatorial map of the) graph Π(Γ, α) is in L α .
The induction step for the dynamic programming algorithm is the following.
Proposition 5.2.There is a universal constant K > 0 such that the following holds.Let ν be a non-root node of B and α be the arc of B incident to ν that is the closest to the root ρ.Assume that, for each arc β ̸ = α of B incident to ν, we are given an exhaustive list of at most (c + w) K(c+w) sparse bounding graphs for G β .Then we can, in (c + w) O(c+w) time, compute an exhaustive list of at most (c + w) K(c+w) sparse bounding graphs for G α .
Assuming Proposition 5.2, the proof of which is deferred to the next subsection, it is easy to prove Proposition 5.1: Proof of Proposition 5.1, assuming Proposition 5.2.We apply the algorithm of Proposition 5.2 in a bottom-up manner in the rooted branch decomposition B. Note that, as stated, Proposition 5.2 handles the base case of the recursion, namely, the case where ν is a leaf.So let α be the arc of B incident with the root node ρ.We end up with an exhaustive list of at most (c + w) K(c+w) sparse bounding graphs for G α = G.By definition of a bounding graph, if this list is non-empty, then G has an embedding on C .On the other hand, by definition of an exhaustive list, if this list is empty, then G has no sparse proper cellular embedding on C .
There are O(n) recursive calls, each of which takes (c + w) O(c+w) time.

The induction step: Proof of Proposition 5.2
Proof of Proposition 5.2.By Lemma 3.3, let K > 0 be such that the number of combinatorial maps of proper embeddings of graphs with at most 75c + 27w vertices and at most at most 75c + 27w edges on C is at most (c + w) K(c+w) .First case.Let us first assume that ν is a (non-root) leaf of B; thus, G α is a single edge uv.We will compute the labelled combinatorial maps of all sparse bounding graphs for G α .It is clear that this will be an exhaustive list.Indeed, assume that G has a sparse proper cellular embedding Γ on C ; by sparsity, Π(Γ, α) has at most 75c + 27w edges; thus, one of the labelled combinatorial maps computed will be equal to that of Π(Γ, α).
So let us describe how to enumerate all the labelled combinatorial maps of bounding graphs for G α .Using Lemma 3.3, we enumerate all possible labelled (combinatorial maps of) proper graph embeddings Π on C such that: • two vertices of Π are labelled u and v (or a single vertex of Π, if u = v); the other vertices are unlabelled; the singular vertices of C are covered by the vertices of Π; conversely, every vertex of Π, except perhaps u and/or v, is mapped to a singular vertex of C ; • Π has at most 75c + 27w edges; • each face of Π is labelled 0, 1, or 2; • Π has a face labelled 2 whose boundary contains both vertices u and v.
It is clear that these labelled combinatorial maps represent all the sparse bounding graphs for G α .
Second case.Let us now assume that ν is an internal node of B. As above, let α be the arc of B incident to ν that is the closest to the root ρ.Let β and γ be the arcs different from α incident to ν.Let L β and L γ be exhaustive lists of bounding graphs for G β and G γ , respectively.Intuitively, every pair of bounding graphs in L β and L γ that are compatible, in the sense that the regions labelled 2 in each of these two graphs are disjoint, will lead to a bounding graph in L α .This is the motivating idea to our approach.More precisely, we will enumerate labelled combinatorial maps Π, each of which can be "restricted" to two compatible graphs, which are possible bounding graphs for G β and G γ .If these two restrictions lie in L β and L γ , this leads to a bounding graph that is added to L α .Even more precisely, we observe that, given a sparse, proper, cellular embedding Γ of G and a node ν of B, from Π(Γ, ν) we can compute Π(Γ, δ) for each incident arc δ. (See Figures 4.1 and 4.2; we describe this in detail below.)So, from Π, we compute its "restrictions" to compatible potential bounding graphs for G β and G γ , with the property that if Π is actually of the form Π(Γ, ν), we indeed compute Π(Γ, β) and Π(Γ, γ).
We first introduce some terminology.Let Π be a graph properly embedded on C (possibly noncellularly), with faces labelled 0, 1, 2, or 3, and with labels on some vertices.We denote by Π − the map obtained from Π by replacing each label 3 on a face by a 2. Let i, j, k be integers such that {i, j, k} = {1, 2, 3}.We will define a graph embedding Π i,j obtained from Π by somehow replacing jlabels with i-labels and "merging" the resulting faces.First, for an illustration, refer back to Figures 4.1 Formally, Π i,j is defined as follows.First, let us replace all face labels j by i.Now, for each face f of Π that is homeomorphic to an open disk, possibly with additional points on the boundary of C , and labelled 0, we do the following.The boundary of f is made of edges of Π, possibly with additional points on the boundary of C ; for the sake of the discussion, let us temporarily label each such edge by the label of the face on the other side of f .If the boundary of f is entirely made of edges labelled i (without boundary points of C ), then we remove all these edges, and f becomes part of a larger face labelled i.Otherwise, for each maximal subsequence e 1 , . . ., e ℓ of edges along the boundary of f that are all labelled i, we remove each of e 1 , . . ., e ℓ , and replace them with an edge inside f from the source of e 1 to the target of e ℓ .Finally, we remove all isolated vertices that do not coincide with singular vertices of C , and all vertices in the relative interior of an isolated edge that are incident to two faces with the same label.
The easy but key properties of this construction are the following: (i) Assume that Π 1,3 is a bounding graph for G β and (Π 1,2 ) − is a bounding graph for G γ .Then Π 2,3 is a bounding graph for G α .
(ii) The node ν naturally partitions the edge set of G into three parts, which we denote by E 1 (on the side of α), E 2 (on the side of β), and E 3 (on the side of γ).Assume that G has a sparse proper cellular embedding Γ on C and that Π is the partitioning graph Π(Γ, E 1 , E 2 , E 3 ).Then: ).As shown above, the corresponding partitioning graphs are respectively Π 2,3 , Π 1,3 , and Π − 1,2 .We compute our exhaustive list L α of sparse bounding graphs for G α as follows.Initially, let this list be empty.Using Lemma 3.3, we enumerate all combinatorial maps Π of graphs with at most c + 3w vertices and 3(75c + 27w)/2 edges properly embedded on C (possibly non-cellularly), with faces labelled 0, 1, 2, or 3, and such that the labels appearing on the vertices are exactly the vertices of the middle set of α, β, or γ (and each label appears exactly once).This takes Finally, we need a postprocessing step to control the size of L α .First, we remove the graphs that are not sparse or contain vertices that bear a label not in mid(α).Second, we eliminate duplicates by testing pairwise isomorphism between the labelled combinatorial maps in L α .This ensures that L α has size at most (c + w) K(c+w) .Now, L α contains only sparse bounding graphs for G α , by (i) above.Moreover, let Γ be a sparse proper cellular graph embedding of G on C .One of the graphs Π enumerated in the previous paragraph is Π(Γ, ν), by sparsity and because Π(Γ, ν) has at most c + 3w vertices.By definition of L β and L γ , we have that Π(Γ, β) ∈ L β and Π(Γ, γ) ∈ L γ , so by (ii) above, Π(Γ, α) ∈ L α , which implies that L α is exhaustive.

Reduction to proper cellular embeddings
This section is devoted to proving the following result: There are two main ideas in the proof: (1) To make an embedding into C proper, it suffices to subdivide its edges and to move the embedding slightly; (2) to make a proper embedding into C cellular, it suffices to simplify C , by detaching some link components, removing some isolated edges, and simplifying the topology of the surface parts; there are c O(c) ways to achieve this, so we can try all possibilities.
We start with auxiliary results.Let S be a surface (possibly disconnected, possibly with boundary).A cutting operation on S consists of cutting it along a simple closed curve, and attaching a disk to the resulting boundary component(s).A cutting operation is essential if the simple closed curve is non-contractible.
The following result is not hard and essentially folklore (a related but slightly weaker result is provided by Matoušek, Sedgwick, Tancer, and Wagner [26,Lemma 3.1]), but we could not find a precise reference.Lemma 6.2.Let S be a (connected) surface with genus g.The number of possibly disconnected surfaces, up to homeomorphism, that can be obtained from S by a cutting operation is at most g + 3, and we can compute them in linear time.Moreover, this cutting operation leads either to a single surface with genus strictly smaller than g, or to two surfaces, the sum of the genera of which equals g, and the size of the surface (sum of the number of connected components, total genus, and number of boundary components) increases by at most one.
Proof.This basically follows from the classification of surfaces together with Euler's formula.A cutting operation of S along a closed curve γ falls into exactly one of the following three categories: 1. Case where γ is separating.The cutting operation on S results in two surfaces S 1 and S 2 , in which their respective genera g 1 and g 2 satisfy g = g 1 + g 2 .Moreover, if S is non-orientable, then at least one of S 1 or S 2 is non-orientable.Finally, all pairs of surfaces (S 1 , S 2 ) satisfying these constraints can be obtained as the result of a cutting operation on S .

2.
Case where γ is non-separating but two-sided.This is only possible if g ≥ 2. The cutting operation on S results in a single surface S ′ with genus g − 2. If S is orientable, then so is S ′ ; otherwise, S ′ is either orientable or non-orientable (unless of course g = 2, in which case it is necessarily orientable, or g is odd, in which case it is necessarily non-orientable).All surfaces S ′ satisfying these constraints can be obtained.

3.
Case where γ is one-sided.This is only possible if S is non-orientable and g ≥ 1.The cutting operation on S results in a single surface S ′ with genus g − 1, orientable or not (unless of course g = 1, in which case it is orientable, or g is even, in which case it is non-orientable).All surfaces S ′ satisfying these constraints can be obtained.Proof.It is useful to organize the set of all surfaces (possibly disconnected, possibly with boundary) arising by essential cutting operations in a tree with root S , in which the children of a node result from a single essential cutting operation.We prove that (1) the depth of the tree is O(g + b) and that (2) each node of the tree has O((k + 1)(g + 1)(b + 1)) children, which concludes (because by Lemma 6.2, the size of a surface increases by at most one by a cutting operation).Let S ′ be a (possibly disconnected, possibly with boundary) surface resulting from a sequence of essential cutting operations on S .By Lemma 6.2, the total genus of S ′ is at most g.Moreover, since we consider only essential cutting operations, each connected component of S ′ either has positive genus or contains at least one boundary component, unless it was itself a connected component of S ; so the number of connected components of S ′ is at most k + g + b.
Let φ(S ′ ) be equal to twice the total genus of S ′ minus its number of connected components.By Lemma 6.2, this potential function strictly decreases at each cutting operation.Moreover, we have φ(S ) = 2g − k, and by the previous paragraph φ(S ′ ) is at least −(k + g + b).This proves (1).
By Lemma 6.2, for any surface of genus g without boundary, there are at most g + 3 ways of performing a cutting operation up to homeomorphism.After a sequence of essential cutting operations, we have a surface S ′ with at most k + g + b connected components, with total genus at most g, and with b boundary components.The number of surfaces that can be obtained from S ′ by a cutting operation is at most k(g + 3)(b + 1), since we first choose which connected component to cut along, the way to cut it ignoring the boundary components, and the number of boundary components in each connected component (if the cut is separating).
We can now conclude the proof of this section.
Proof of Proposition 6.1.First, if the detached surface of C is non-empty (equivalently, if C has at least one triangle), then we test the planarity of each connected component of G [19] in O(n) time, and remove every connected component of G that is planar; obviously, this does not affect the embeddability of G on C .
In a second step, we split each isolated edge of C into five isolated edges.Then, for each subset S of the isolated edges, we build a new 2-complex obtained from C by removing S. We obtain 2 O(c) 2-complexes, each of size O(c).The input graph G embeds on C if and only if it embeds into one of these 2-complexes; moreover, if G embeds on C , it embeds into one of the 2-complexes in such a way that every isolated edge is covered by the embedding.(Indeed, remember that G has at most one connected component that is a path.) We now iteratively dissolve every degree-two vertex of G, and then subdivide 5c times each edge of G.This new graph G ′ has at most 5cn vertices and edges, and branchwidth at most w.Clearly, G embeds on C if and only if G ′ embeds in one of the 2-complexes defined in the previous paragraph; moreover, if G embeds on C , then G ′ has an embedding on one of these 2-complexes in which the relative interior of every edge of G ′ contains no singular vertices of C (and, as above, such that every isolated edge is covered by the embedding).
Each singular vertex v of each of these 2-complexes is incident to at least two link components.For each such singular vertex v and for each partition of the link components at v, we replace v with new vertices, one for each element in the partition; two link components at v stay adjacent via one of these new vertices if and only if these link components are in the same part.We obtain c O(c) 2-complexes, each of size O(c).The input graph G embeds on C if and only if G ′ embeds in one of these 2-complexes; moreover, if G embeds on C , then G ′ has an embedding into one of these 2-complexes in which every link component of each singular vertex v is used by an edge of G connected to v in that link component (and, as above, such that every isolated edge is covered by the embedding, and such that the relative interior of every edge is distinct from any singular vertex).
Every embedding of a graph into a 2-complex can be perturbed so that it avoids the boundary of the 2-complex, except possibly at singular vertices.This means that, if G embeds on C , then G ′ has a proper cellular embedding into one of the 2-complexes built in the previous paragraph, except that the faces of G ′ may fail to be disks, but are more general (connected) surfaces with boundary.
To dispense ourselves from this latter exception, we need to build more 2-complexes.This case occurs only if the detached surface is non-empty, so by our earlier preprocessing, we can assume that G ′ contains no planar connected component, and so has O(c) connected components (because, by Lemma 3.4, in order for G ′ to be embeddable on a 2-complex of size O(c), it must have genus O(c)).
The detached surface S is a surface (possibly disconnected, possibly with boundary); the trace of the set of singular vertices on S corresponds to marked vertices, some in the interior of S , some on the boundary.Henceforth, we regard the former ones as small boundary components.For each 2-complex obtained above, we consider, up to homeomorphism, all 2-complexes arising from zero, one, or several essential cutting operations on S , and then by removing an arbitrary subset of the connected components of the resulting surface.Up to homeomorphism, by Lemma 6.3, there are c O(c) ways of cutting S ; since we consider all 2-complexes obtained up to homeomorphism, we need to consider each boundary component of the detached surface S as labelled (which is not the case in Lemma 6.3); however, this only adds a factor of c O(c) .In total, we obtain, in c O(c) time, c O(c) 2-complexes, each of size O(c).Then, for each such 2-complex, we consider all possible ways of removing an arbitrary subset of connected components of the 2-complex; the number of the resulting 2-complexes is still c O(c) .By construction, the input graph G embeds on C if and only if G ′ embeds in one of these 2-complexes.Moreover, assume that it is the case; as shown above, G ′ has a proper embedding into one of the 2complexes in the previous paragraph, except that faces of G ′ are (connected) surfaces, not necessarily disks.Whenever a face has non-empty boundary and is not homeomorphic to a disk, we perform an essential cutting operation of that face along a closed curve inside that face; the closed curve along which we cut is non-contractible in S , because otherwise it would bound a disk in S , which would itself contain a planar connected component of G ′ , and we have shown above that we may assume that no such component exists.After iterating this operation as much as possible, every face of G ′ in the resulting 2-complex is either is a disk or has empty boundary; in the latter case, G ′ avoids the corresponding connected component, so we can simply remove it.Eventually, after a number of essential cutting operations of S and removing some connected components of the 2-complex, the embedding of G ′ is cellular in one of the c O(c) 2-complexes of size O(c) enumerated above.
By construction, each C i and G ′ satisfy the properties of Proposition 3.1.
7 Algorithm for bounded branchwidth: Proof of Theorem 1.2 We can now combine the ingredients of the previous sections to describe our algorithm for bounded branchwidth.
Proof of Theorem 1.2.By Proposition 3.1, we can assume that C has no 3-book and no connected component that is reduced to a single vertex, and that G has no connected component reduced to a single vertex and at most one connected component that is a path.If necessary, we convert the combinatorial description of C into the topological data structure (Section 3.3).We apply Proposition 6.1.In c O(c) + O(cn) time, we obtain a graph G ′ and a set of c O(c) 2complexes C i such that: 1. each C i and G ′ satisfy the properties of Proposition 3.1; 2. G ′ has at most 5cn vertices and 5cn edges, and branchwidth at most w; 3. each C i has size at most c; 4. if, for some i, G ′ embeds into C i , then G embeds into C ; 5. if G embeds into C , then for some i, G ′ has a proper cellular embedding into C i .
We then run the algorithm from Proposition 5.1 in each of the instances (C i , G ′ ), in total time (c + w) O(c+w) n.This algorithm correctly reports either that G ′ has no sparse proper cellular embedding into C i or that G ′ has an embedding into C .If for at least one of these instances, the algorithm reports that G ′ embeds into C i , then we report that G embeds into C .Otherwise, we report that G does not embed into C .
There remains to prove that the algorithm is correct.If our algorithm reports that G embeds into C , then it is obviously indeed the case (Property (4) above).Conversely, let us assume that G has an embedding into C .Thus, by Property (5) above, let i be such that G ′ has a proper cellular embedding into C i .By Proposition 4.1, G ′ also has such an embedding into C i that is sparse.Thus, the algorithm in Proposition 5.1 (correctly) reports that G ′ has an embedding into C i , and finally our overall algorithm reports that G has an embedding into C .
8 Reduction to bounded branchwidth: Proof of Theorem 1.3 This section is devoted to the proof of Theorem 1.3.The proof technique is based on an irrelevant vertex method; we borrow ingredients to Kociumaka and Pilipczuk [22, Section 5] and to graph minor algorithms, but some new arguments are needed, in particular in the beginning of the proof of Proposition 8.1, and because we need to take singular vertices into account.

Finding a large planar part
A wall of size k × k is a subgraph of the (k × k)-grid obtained by removing alternately the vertical edges of even (resp.odd) x-coordinate in each even (resp.odd) line, and then the degree-one vertices; see Figure 8.1.
As an intermediate goal towards the proof of Theorem 1.3, we will prove in this subsection: Proposition 8.1.Let G be a graph with n vertices and edges and g ≥ 2 be an integer.In 2 poly(g) n time, we can do one of the following: 1. compute a rooted branch decomposition of G of width g O(1) ; 2. correctly report that G has genus at least g; 3. or compute a cycle γ of G such that one connected component of G − γ is planar and contains a subdivision of the (g × g)-wall, which is also computed.
We will use the following lemma, whose proof relies on some advanced results related to treewidth and tree decompositions.Lemma 8.2.Let G be a graph with n vertices and edges, and k ≥ 2.Then, one can compute either a rooted branch decomposition of G of width polynomial in k or a (k × k)-grid minor of G, in time 2 poly(k) • n.
In the proof below, the polynomial in k is shown to be O(k 9+ε ), for any ε > 0.
Proof.In the same way as the branchwidth of a graph H is the minimum width of a branch decomposition of H, the treewidth of H is the minimum width of a tree decomposition of H.We do not define tree decompositions here, but it suffices to know that one can, in linear time, convert a branch decomposition of G of width w into a tree decomposition of G of width at most w + 1; and similarly in linear time we can convert a tree decomposition of G of width w into a branch decomposition of G with width at most 3w/2 − 1 [33, Theorem 5.1].
By a result by Chekuri and Chuzhoy [9], we know that for some d large enough, if G has treewidth at least k d , then it has a (k × k)-grid minor.One can take d = 9 + ε, by a result by Chuzhoy and Tan [10].
We will use an algorithm to approximate the treewidth by Bodlaender, Drange, Dregi, Fomin, Lokshtanov, Ma.Pilipczuk [5]: Given a graph G with n vertices and edges, and an integer t, in O(2 poly(t) n) time, we either correctly report that the treewidth of G is at least t, or compute a tree decomposition of width at most 6t.In a first step, we apply it with t = k d .If we get a tree decomposition of width at most 6k d , we immediately obtain, and return, a (rooted) branch decomposition of width at most 9k d , as desired.The rest of the proof focuses on the former case, in which the treewidth of G is at least k d .
We will also use a result by Perkovic and Reed [32] (see also Sau, Stamoulis, and Thilikos [36, Proposition 28]), which implies the following: Given an input graph H with n vertices, we can compute in O(n) time a minor H ′ of H with |V (H ′ )| ≤ 15  16 |V (H)| such that the treewidth of H ′ is at least half the treewidth of H. (This is because contracting a matching of a graph divides its treewidth by at most two.) We alternately apply the algorithm by Bodlaender et al. with t = 2k d , and the algorithm by Perkovic and Reed, until Bodlaender's algorithm computes a tree decomposition of width at most 12k d .This must happen at some point because the algorithm of Perkovic and Reed decreases the number of vertices geometrically.The step before this happens, the treewidth was at least 2k d , so at the end it is also at least k d .We thus computed, in O(2 poly(k) n) time, a minor G ′ of G whose treewidth is between k d and 12k d , together with a tree decomposition of G ′ of width at most 12k d .
By the choice of d, the graph G ′ has a (k × k)-grid minor, which we can compute in O(2 poly(k) n) time because we have a tree decomposition of width at most 12k d , using an algorithm by Adler, Dorn, Fomin, Sau, and Thilikos [1, Theorem 1] (the theorem is stated as a decision problem, but in Section 5 of the same paper it is explained how to explicitly find a minor).
Alternatively, with fewer and more standard tools, one could achieve this with a worse running time of f (k)n 2 , for some computable function f .Indeed, we can first approximate the treewidth of G, e.g., by the algorithm by Bodlaender et al. [5]: Provided d is large enough, in time 2 poly(k) n, we either compute a tree decomposition of width at most 9dk d , and thus immediately obtain a (rooted) branch decomposition of width at most 6dk d [33, Theorem 5.1], or correctly report that the treewidth of G is at least dk d , which by the result by Chekuri and Chuzhoy [9] implies the existence of a (k × k)-grid minor, which we can compute in f (k)n 2 time, for some computable function f [33,Algorithm 4.4 of W , and the corresponding subdivisions Ẇ1 , . . ., Ẇg that are subgraphs of Ẇ , in such a way that W − W i is connected for each i.For each i, we consider the subgraph G i of G induced by the vertices v of G such that: (1) there exists a path from v to Ẇi ; (2) every path from v to Ẇj , for some j ̸ = i, uses at least one vertex from Ẇi .The graphs G i are pairwise disjoint, and we can compute each of them easily in O(n) time using suitable traversals of G.We test the planarity of each of them in linear time [19].If all of them are non-planar, we correctly report that G has genus at least g (Case 2).So without loss of generality, one of these graphs, say G 1 , is planar, and our algorithm computes it.By 3-connectivity, W 1 , and thus also Ẇ1 , has a unique combinatorial embedding in the plane, up to symmetry and up to the choice of the outer (infinite) face; we consider the natural embedding of W 1 in which the outer face has the largest degree.An inner vertex of W 1 is one that is at distance at least 6 from the outer face in the natural embedding of W 1 .Remark that each vertex of W 1 is a vertex of Ẇ1 .We say that a vertex u of W 1 is connected to the outside if there is, in G, a path whose vertices are, in this order, u, possibly some vertices of Ẇ1 but not of W 1 , possibly some vertices of G − Ẇ1 , and finally one vertex in Ẇ − Ẇ1 .
We claim the following: If at least 1000g inner vertices of W 1 are connected to the outside, then G has genus at least g.The strategy is similar to the argument in Kociumaka and Pilipczuk [22,Lemma 5.3]; we summarize the proof.If at least 1000g inner vertices of W 1 are connected to the outside, then a set U of g inner vertices of W 1 are connected to the outside, and at pairwise distance at least 16 in W 1 .This implies that G contains, as a minor, the graph J g obtained from g copies of K 5 The wall W 1 (left), and a schematic view of the J p minor (right), illustrated with g = 6.Let K − 5 be the graph K 5 with one edge removed.If W 1 has many vertices connected to the outside, then a set U of at least g vertices connected to the outside (represented as big disks on the left) are pairwise distant.In the neighborhood of these vertices, we build a K − 5 minor for each vertex in U , in which the vertex of U is the "central" vertex (the thick paths need to be contracted to obtain copies of K − 5 ).Using the fact that the neighborhoods are far apart, we build a J g -minor of G (right), in which the apex results from the contraction of the subdivided wall Ẇ1 minus the union of the K − 5 minors, and each path connecting u ∈ U to Ẇ − Ẇ1 (which is connected by assumption) is contracted, except its first edge, to connect u to the apex.by subdividing an edge from each copy with a degree-two vertex and identifying these g new vertices into a single vertex, the apex of J g ; see Figure 8.2.This graph has genus at least g, by the main result of an article by Miller [27,Theorem 1].This proves the claim.
In O(g 3 n) time, we can compute the inner vertices of W 1 connected to the outside, using suitable traversals of G starting from Ẇ − Ẇ1 .If there are at least 1000g of these, we report that G has genus at least g (Case 2), which is correct by the above claim.Otherwise, from the (50g⌈ √ g⌉×50g⌈ √ g⌉)-wall W 1 , we can compute a cycle γ in W 1 , enclosing a (g × g)-wall W ′ 1 in W 1 (in the natural embedding of W 1 ) such that no vertex of W 1 inside γ (in the natural embedding of W 1 ) is connected to the outside.Let γ be the cycle of Ẇ1 corresponding to γ, and let H be the connected component of G− γ containing the vertices of this (g × g)-wall.There remains to prove that H is planar, and since G 1 is planar, it suffices to prove that H is a subgraph of G 1 .If it were not the case, H would contain a vertex of Ẇj for some j ̸ = 1; but that would imply that a vertex of W ′ 1 is connected to the outside, which is not the case.We can thus correctly report γ (Case 3).

Finding an irrelevant vertex
The following proposition will imply that if the third possibility in the statement of Proposition 8.1 holds (for some g large enough), then one has an irrelevant vertex for the embedding instance.The proof is inspired from an article by Kociumaka and Pilipczuk [22,Section 5.3], but we provide a slightly different argument, also because we need to handle a 2-complex, not a surface.We use more concepts of topology, in particular homotopy; see, e.g., Stillwell [38].
Lemma 8.4.On a surface of genus g, a set of disjoint, simple closed curves belong to at most 3g + 2 (free) homotopy classes (here we regard a closed curve and its reversal to be in the same homotopy class).
Proof.Let C be a set of disjoint, simple closed curves on a surface S of genus g.Assume that in C there is no contractible curve, and there are no two distinct curves in the same homotopy class.We prove below that |C| ≤ 3g + 1, which proves the lemma.
We first turn C, by homotopy, into a set of loops L pairwise disjoint except at a common basepoint b.
To this end, we first draw a tree T on S that touches each closed curve in C exactly once.(For this, one could start with a tree that is a spanning tree of the "dual" of the closed curves in C and visits all faces of C, and then extend it if necessary to touch all curves in C.) We then contract T on S .
L cannot contain a monogon, because otherwise the corresponding closed curve in C would be contractible.L cannot contain a bigon whose boundary involves two different loops, because otherwise the corresponding closed curves in C would be homotopic.If L contains a bigon whose boundary involves the same loop appearing twice, then |L| = 1, so the lemma holds.By Lemma 4.2, |L| ≤ max{0, 3g − 3}.
Proof of Proposition 8.3.We need some preparations.A circular wall W [22, Figure 8] of height h and circumference ℓ is a 3-regular graph that, in some embedding of W in the plane, is represented as the union of h vertex-disjoint cycles, called circles, organized in a concentric way, such that any two consecutive circles are connected by ℓ radial edges; in any two successive layers, the radial edges are interleaved.
Let H be the connected component of G − γ that is planar and contains a subdivision of the (200g × 200g)-wall.In the following, we denote by φ the plane embedding of H such that v is the central vertex of this wall.Then H contains a subdivision Ẇ of a circular wall W of height 20c + 5 and circumference 2c + 1, so that v is located inside the inner circle of this circular wall in φ; see Kociumaka and Pilipczuk [22, Figures 8 and 9].
If G is embeddable on C , then obviously G − v is also embeddable on C ; the hard part is the reverse direction.So let us consider an embedding ψ of G − v on C .This induces embeddings of Ẇ and W on C .At most c vertices or edges of W are mapped, under ψ, to a singular vertex of C , and the isolated edges of C intersect the images of at most c edges of W . Thus, we obtain a subdivision Ẇ ′ of a circular wall W ′ of height 18c + 5 and circumference one that does not intersect any singular vertex or isolated edge of C .Now, let S be the detached surface of C , and let Ŝ be the surface obtained by attaching a handle to every boundary component of S and to each point of S not on its boundary that corresponds, in C , to a singular vertex.At most 2c handles were attached, so Ŝ has a natural cellular graph embedding with at most 3c edges, and thus has genus at most 3c.Moreover, ψ naturally corresponds to an embedding of Ẇ ′ and W ′ on Ŝ , which we still denote by ψ.
By Lemma 8.4, since Ŝ has genus at most 3c, and W ′ has height 2(3 * 3c + 2) + 1, there are three pairwise distinct circles of the subdivision Ẇ ′ of the circular wall W ′ that are homotopic under ψ.They are two-sided, because any two one-sided homotopic closed curves cross.Let C i , C, and C o be these three circles, in this order, starting from the innermost circle in φ (thus C i is inside, and C o outside).
A bridge (of Ẇ ) is either (1) a connected component of G − {v} − Ẇ , together with the edges joining it to Ẇ , or (2) an edge of G − {v} − Ẇ whose endpoints are on Ẇ .For a bridge of Ẇ , the vertices of Ẇ that are endpoints of edges in the bridge are the attachment points of the bridge.We partition the vertices and edges of G − v as follows: We now claim that in ψ, the edges of O that have an endpoint on C leave C all on the same side of C. For this, we distinguish two cases.
• Assume that ψ(C) is contractible on S ; it bounds a disk in S , and thus also in C .Since O is connected, it is mapped, by ψ, either completely inside that disk, or completely outside, hence the claim holds.We consider the restriction ψ ′ of ψ to C ∪O ∪R.We extend ψ ′ to an embedding ψ ′′ of C ∪O ∪R∪B, by embedding B on the same side of C as O, close to C, as in φ.In ψ ′′ , all the edges incident to C leave C all on the same side of C. Finally, we extend ψ ′′ to all of G, by embedding the remaining part, I ∪ {v}, in a small neighborhood of C, on the side of C not used by O, in the same way as C ∪ I ∪ {v} is planarly embedded in φ.

Proof of Theorem 1.3
Proof of Theorem 1.3.We first apply Proposition 3.1: without loss of generality, C has no 3-book and no connected component that is reduced to a single vertex, and G has no connected component reduced to a single vertex, and at most one connected component that is a path.Let n be the number of vertices and edges of the input graph G, and c be the number of simplices of C .We apply Proposition 8.1 to the graph G, letting g = 200c.In 2 poly(c) • n time, we obtain one of the following outcomes: 1. a rooted branch decomposition of G of width O(g) O(1) ; 2. that G has genus at least g, and is thus not embeddable on C (Lemma 3.4); 3. a cycle γ of G such that one connected component of G − γ is planar and contains a subdivision of the (g × g)-wall.
In the first two cases, we are done.In the third case, by applying Proposition 8.3, we obtain a vertex v such that G embeds on C if and only if G − v does.By iterating the same procedure a number of times that is at most the number of vertices of G, we necessarily reach case (1) or (2), which concludes.
We remark that the proof goes through if the input 2-complex is given in the form of the topological data structure, and c denotes its size, instead of the number of simplices of C .
As mentioned above, the proof of Theorem 1.1 follows immediately from Theorems 1.2 and 1.3.

Computing an embedding
In this section, we enhance Theorems 1.1 and 1.2 to show that, under some mild conditions and in a sense made precise below, if the input graph G has an embedding into the input complex C , then we can actually compute such an embedding without overhead in the asymptotic running time: Theorem 9.1.In Theorems 1.1 and 1.2, if C has no 3-book and no isolated vertex, and G embeds into C , then one can, without overhead in the asymptotic running time, compute an embedding of a graph H on C where: • H is obtained from G by augmenting it with at most 2c vertices and at most 3c + 2k edges, and performing at most c edge subdivisions, where k is the number of connected components of G; • the images of the vertices of H cover the singular points of C ; • the restriction of H to the detached surface S is specified by (1) a cellular embedding of a graph H ′ , represented by its (standard) combinatorial map, such that E(H ′ ) ⊆ E(H), (2) a map from V (H ′ ) to V (H) describing how the vertices of H ′ are identified when attaching the points of S to recover the singular points of C , and (3) a map from the images of the singular points of C on S to V (H ′ ), to specify which vertex of H ′ occupies that point.Moreover, we have • each isolated edge e of C contains vertices of H, edges of H, and "holes" (parts of e not in the image of H), which we can represent by listing the corresponding sequence in order along e.
We remark that it is not a severe restriction to assume that C has no 3-book, since any graph embeds on a 3-book (Proposition 3.1) and no isolated vertex, since only isolated vertices of G can be embedded on such isolated vertices.Also, we remark that the graph H is needed because we may need to add edges to make the embedding cellular on the detached surface, and we may need to subdivide edges in order to avoid any edge to go through a singular vertex.
We say that a graph G ′ is an i-homeomorph of another graph G if G ′ is obtained from G by the following steps: (i) iteratively dissolve every degree-two vertex of G, (2) subdivide each edge of the resulting graph at most i times.
We will use the following intermediate lemmas.
Lemma 9.2.In Theorem 1.2, if C has no 3-book and no isolated vertex, G has no isolatex vertex and at most one connected component that is a path, and G embeds into C , then one can compute a proper embedding of a 5c-homeomorph of G, augmented with at most c isolated vertices (using the data structure of Section 3.4), without overhead in the asymptotic running time.
Proof.We go through the proof of Theorem 1. 1.In the first step (Proposition 6.1), from (G, C ), we compute a graph G ′ and complexes C i , such that any embedding of G ′ into C i yields an embedding of G into C .
2. In the second step, we run the dynamic program (Proposition 5.2) on (G ′ , C i ), for each complex C i .
We now consider these two steps in reverse order.
2. Since G embeds on C , for some complex C i , we have computed a sparse bounding graph for G ′ on C i at the root of the rooted branch decomposition.We can use backtracking: at each node α of the rooted branch decomposition, we store the embedding of the union of G α and of its bounding graph, which is a proper embedding.Eventually, the embedding of G ′ at the root of the recursion is not necessarily proper, but it becomes proper if we add isolated vertices mapped to singular points that are not covered by the embedding of G ′ .Thus, from (G ′ , C i ), we can return a proper embedding of the graph G ′ , augmented with at most c isolated vertices, into C i .
1.An easy inspection of its proof reveals that: • G ′ is obtained from G by removing planar connected components, but only if C has at least one triangle, and then by dissolving iteratively all degree-two vertices and subdividing every edge 5c times; • C i is obtained from C by removing part of its isolated edges, splitting singular vertices, performing essential cutting operations, and removing some connected components.
Given a proper embedding of G ′ , augmented with at most c isolated vertices, into C i , we can embed the remaining planar components of G in (a small portion of a triangle) of C i , revert the pieces of the isolated edges of C , merge back the singular vertices (if necessary, adding a vertex to the graph on that singular vertex to maintain the fact that we have a proper embedding), and reverse the essential cutting operations on the complex.We obtain a proper embedding of a 5c-homeomorph of G, augmented with at most c isolated vertices, into C .
Moreover, at every step, there is no overhead in the asymptotic running time.
We have the same constructive result for our Theorem 1.1: Lemma 9.3.In Theorem 1.1, if C has no 3-book and no isolated vertex, G has no isolatex vertex and at most one connected component that is a path, then one can compute a proper embedding of a 5c-homeomorph of G, augmented with at most c isolated vertices, into C (using the data structure of Section 3.4), without overhead in the asymptotic running time.
Proof.The decision algorithm iteratively removes vertices to G, getting a smaller equivalent instance.
For the algorithm that actually computes an embedding, we now need recursion.The base case is given by Lemma 9.2.We assume that for some vertex v of G, we have a proper embedding of a 5chomeomorph of G −v, augmented with at most c isolated vertices, into C .We need to recover a proper embedding of a 5c-homeomorph of G, augmented with at most c isolated vertices, into C .We note that v is the central vertex of a (200c We now apply the following transformations.First, for each connected component of the detached surface S that is not used by the embedding, we add a vertex of the graph and map it to that connected component.Then, on each connected component of S , we make the embedding connected by adding at most 2c + k edges in total; this is because, on S , the image of the number of connected components of G ′ is at most 2c + k.In a third step, we make the embedding on S cellular by adding edges; by Euler's formula, the number of edges that are needed is at most the Euler genus of S , which is at most c.
We now have a proper embedding of a 5c-homeomorph of G ′ , augmented with at most 2c vertices and at most 3c+k edges, into C , satisfying the property that this embedding, restricted to the detached surface S , is cellular.If necessary, we subdivide further the edges to obtain a proper embedding of the graph G ′ , in which each edge is subdivided at most 5c times, and then augmented with at most 2c vertices and at most 3c + k edges.We dissolve degree-two vertices that are not part of G and not on singular points.There remains, if necessary, to subdivide the edge of G ′ corresponding to the path component of G at most 2k times, so that it now contains all the path components and isolated vertices of G, in order to obtain the desired embedding; this adds at most k edges that are not part of G.
Eventually, we have a graph H obtained from G by augmenting it with at most 2c vertices and at most 3c + 2k edges, and performing at most c edge subdivisions (the corresponding vertices being on singular points of C ).Moreover, the images of the vertices of H cover the singular points of C .Also, H corresponds to a cellular embedding on the detached surface S , so it can be encoded by a combinatorial map as claimed, and similarly one can encode the embedding H restricted to the isolated edges of C .

Solving other problems
In this short section, we prove (or reprove) results that are easy consequences of our main result.We focus on decision problems; in the case of positive instances, explicit constructions can be done using Theorem 9.1.

Crossing number problem
Recall that the crossing number problem is to decide, given a graph G with at most n vertices and edges and an integer k, whether there is a (topological) drawing of G in general position in the plane with at most k crossings.(General position means that the only crossings involve exactly the relative interiors of two edges.) The problem is known to be NP-hard, and Kawarabayashi and Reed, in an extended abstract [21], provided a linear-time algorithm if k is fixed.Our result immediately implies a weaker, quadratic-time algorithm: Proposition 10.1.We can solve the crossing number problem in 2 poly(k) n 2 time.
Proof.The reduction is known [13,Introduction] but we include it here for completeness.Consider the topological space that is a disk minus k open disks with disjoint closures.To the boundary of each of these k smaller disks, attach two edges whose endpoints are interleaved along the boundary.This topological space is homeomorphic to a two-dimensional simplicial complex C with O(k) simplices.
It is clear that any graph G embedded in C has crossing number exactly k.Conversely, consider a graph drawn in the plane in general position with at most k crossings; by removing small disks around the crossings, we see that the graph is embedded on a topological space homeomorphic to C .Theorem 1.1 concludes the proof.
Actually, using Theorem 1.2, we obtain an algorithm that in (k+w) O(k+w) n time solves the crossing number problem when restricted to graphs of branchwidth at most w.
Let us point out that we can handle more general situations.For example, using the same technique, we immediately obtain an algorithm to decide whether an input graph has a drawing on a given surface of genus g with at most k crossings, in 2 poly(g+k) n 2 time.

Embedding extension problem
An embedding extension problem takes as input a 2-complex C of size c, a graph G with at most n vertices and edges, a subset U ⊆ V (G) of k vertices of G, and an embedding of U into C .The question is to determine whether there is an embedding of G into C extending the given embedding of U .We provide below an algorithm in a special case.
We remark that, in general embedding extension problems, not only a set of vertices is preembedded, but also possibly a set of edges.In particular, Mohar [28] used embedding extension problems on surfaces as a subroutine to his linear time algorithm to embed graphs on a fixed surface; in the planar case, Angelini, Di Battista, Frati, Jelínek, Kratochvíl, Patrignani, and Rutter [3] solve such embedding extension problems in linear time.However, in our case, we can easily force the location of the edges as follows: Given a set of pre-embedded edges, this amounts to cutting the 2-complex along their images and to solving the embedding extension problem for pre-embedded vertices (the set of pre-embedded vertices includes the endpoints of the pre-embedded edges).
We provide an algorithm for the embedding extension problem on complexes with no 3-book and with no isolated edge: Proposition 10.2.We can solve the embedding extension problem for complexes where each edge of the complex is incident to either one or two triangles in 2 poly(c+k) n 2 time.
Proof.Without loss of generality, we can assume that the input complex C has no isolated vertex (see the proof of Proposition 3.1).
Let U = {u 1 , . . ., u k }, and let p 1 , . . ., p k be the distinct points of C such that u i must be embedded at location p i .
We augment C into a larger complex C ′ as follows.For each i, let S i be the orientable surface of Euler genus 10c + 2i.We attach S i to C by connecting an arbitrary point q i of S i with the point p i of C with a new segment s i .
We augment G into a larger graph G ′ as follows.For each i, let H i be a 2-connected graph with O(c + i) vertices and edges that is embeddable on S i but not on any surface (orientable or not) surface of smaller Euler genus.(It suffices to build graphs embedded on the surface with the prescribed genus with triangular faces, such that any non-contractible cycle has length at least four, by a result of Thomassen [40], and this is easy; see Figure 10 A graph embedded on an orientable surface of Euler genus six, but not embeddable on a surface of lower genus.Indeed, it is a triangulated graph in which all cycles of length at most three are contractible.
We claim that the instance of the embedding extension problem is positive if and only if G ′ is embeddable in C ′ , which concludes.Clearly, if the embedding extension problem is positive, then G ′ is embeddable in C ′ : Indeed, we embed G into C as given by the solution of the embedding extension problem, we embed each graph H i to S i mapping h i to q i , and we embed each edge e i to the segment s i .
Conversely, assume that G ′ is embeddable in C .By induction on i = k, k − 1, . . ., 1, by definition of H i , by Lemma 3.4 and because C has no 3-book, we have that H i is embedded entirely into S i .Moreover, each face of H i in S i is homeomorphic to a disk, because otherwise H i would be embeddable on a surface of lower genus.
Assume first that u i lies in C .Because h i lies in S i , edge h i u i goes through p i .Because C has no isolated edge, we can pull u i to p i , putting the other edges incident with u i in a neighborhood of the original edge h i u i .
Assume now that u i lies in S i ∪ s i \ {p i }.We consider the connected component G i of G containing u i .The part of G i inside S i ∪ s i lies in the union of a face of H i and of segment s i , and is thus planar.If any other part of G intersects S i ∪ s i , it is also planar and can be pulled out of S i ∪ s i .Then, the part of G i inside S i can be pushed to a neighborhood of p i , with u i on p i .
Finally, we have an embedding of G ′ in which each u i lies on p i ; its restriction to G satisfies the desired properties.
With a bit more work, it should be possible to modify the dynamic program and the irrelevant vertex method to develop a direct solution to the embedding extension problem even in the presence of isolated edges.However, handling 3-books looks substantially more complicated, and we leave it as an open problem.

Planarity number problem
Recall that the planarity number problem is, given a graph G with at most n vertices and edges, a subset U of vertices of G, and an integer k, to decide whether there exists a planar embedding of G in which a set of at most k faces cover all the vertices in U .
Bienstock and Monma [4] proved that this problem is strongly NP-hard, and provided a linear-time algorithm for fixed k.Our result immediately implies a weaker, quadratic-time algorithm: Proposition 10.3.We can solve the planarity number problem in 2 poly(c) n 2 time.
Proof.Let T be the topological space obtained from the sphere by identifying k points into into a single point, the apex.Let G ′ be the graph G augmented with a single vertex b, connected to all the vertices in U .It is straightforward to check that (G, U ) has planarity number at most k if and only if G ′ has an embedding in T in which b is mapped to the apex.Proposition 10.2 concludes.
As above, we can trivially generalize this result by replacing, in the definition of the planarity number problem, the plane with any fixed surface.

Figure 3 . 1 :
Figure3.1:On the left: A 2-complex with 5 singular vertices, numbered from 1 to 5, and 2 isolated edges (one between 3 and 4 and one between 1 and 2) where, at singular vertices, the cones are in green and the corners in yellow.On the right: the corresponding detached surface.

Lemma 3 . 2 .
Given two 2-complexes C and C ′ , given in the topological representation above, of sizes c and c ′ respectively, we can decide whether C and C ′ are homeomorphic in time (c + c ′ ) O(c+c ′ ) .

First
step.Let Γ be a proper embedding of a graph with at most k vertices and k edges on C .Let S be the detached surface associated to C ; this surface is possibly disconnected and has genus at most c.The image of Γ on S is a graph with at most k + c vertices and k edges. .2.

Figure 3 . 2 :
Figure 3.2: On the left: The same 2-complex as Figure 3.1.On the right: the corresponding surface constructed in Lemma 3.4.

Figure 4 . 1 :
Figure 4.1: Construction of the partitioning graph Π = Π(Γ, E 1 , E 2 ), for three choices of the partition (E 1 , E 2 ) of the same embedding Γ.Only a part of the 2-complex C is shown, with a boundary at the upper part, and without singular vertex.Left: The graph embeddings Γ (in thick lines) and Π (in thin lines).Right: The sole graph Π, together with the labelling of its faces.

Proposition 4 . 1 .
Let C be a 2-complex and G a graph, which satisfy the properties of Proposition 3.1.Let B be a rooted branch decomposition of G. Assume that G has a proper cellular embedding on C .

E 1 E 2 Figure 4 . 3 :
Figure 4.3: A simplification.Left: A vertex of an embedding Γ of G, on the boundary of C , incident with eight intervals.The exterior intervals are drawn in thick lines.Right: The result of the simplification that exchanges the intervals marked with an arrow.The number of intervals strictly decreases.

and 4 . 2 :
If Π is the graph embedding depicted on the right of Figure 4.2, then the configurations shown on the right of Figure 4.1 correspond, from top to bottom, to Π 2,3 , Π 1,3 , and (Π 1,2 ) − .

Proposition 6 . 1 .
Let C be a 2-complex with at most c simplices, and G a graph with at most n vertices and edges and branchwidth at most w.Assume that G and C satisfy the properties of Proposition 3.1.In c O(c) + O(cn) time, one can compute a graph G ′ , and c O(c) 2-complexes C i , such that:1.each C i and G ′ satisfy the properties of Proposition 3.1; 2. G ′ has at most 5cn vertices and 5cn edges, and branchwidth at most w;3.each C i has size at most c; 4. if, for some i, G ′ embeds into C i , then G embeds into C ; 5. if G embeds into C , then for some i, G ′ has a proper cellular embedding into C i .

Lemma 6 . 3 .
Let S be a surface with k connected components, total genus g, and with b boundary components in total.In (k+g+b) O(g+b) time, we can enumerate all (k+g+b) O(g+b) possibly disconnected surfaces with boundary, up to homeomorphism, arising from S by one or several successive essential cutting operations.These surfaces have O(k + g + b) connected components and size O(k + g + b).

Figure 8 . 2 :
Figure 8.2: Illustration of the proof of the claim in Proposition 8.1.The wall W 1 (left), and a schematic view of the J p minor (right), illustrated with g = 6.Let K − 5 be the graph K 5 with one edge removed.If W 1 has many vertices connected to the outside, then a set U of at least g vertices connected to the outside (represented as big disks on the left) are pairwise distant.In the neighborhood of these vertices, we build a K − 5 minor for each vertex in U , in which the vertex of U is the "central" vertex (the thick paths need to be contracted to obtain copies of K − 5 ).Using the fact that the neighborhoods are far apart, we build a J g -minor of G (right), in which the apex results from the contraction of the subdivided wall Ẇ1 minus the union of the K − 5 minors, and each path connecting u ∈ U to Ẇ − Ẇ1 (which is connected by assumption) is contracted, except its first edge, to connect u to the apex.

Proposition 8 . 3 .
Let C be a 2-complex with c ≥ 1 simplices.Let G be a graph and γ be a cycle in G such that one connected component of G − γ is planar and contains a subdivision of the (200c × 200c)wall.Let v be the central vertex of this wall.Then G is embeddable on C if and only if G − v is.

( 1 )
the cycle C; (2) the part I of G − v that lies inside C in φ; (3) the union B of the bridges (of Ẇ ) that are mapped outside C by φ, have at least one attachment point, but all of them lie on C; (4) the part O of G − v that lies in the same connected component of G − v as C, but is disjoint from C, I, and B; (5) the union R of the other connected components of G − v.We remark that O is connected and contains C o , because the circumference of W is at least one.
2 and express what can be computed for a positive instance (G, C ) of the embeddability problem.Let us first recapitulate the algorithm, omitting the step of Proposition 3.1 because of the assumptions on C and G.
Figure 10.1:A graph embedded on an orientable surface of Euler genus six, but not embeddable on a surface of lower genus.Indeed, it is a triangulated graph in which all cycles of length at most three are contractible.
• either removing g/2 open disks and attaching a handle (a torus with an open disk removed) to each resulting boundary component, where g is an even, nonnegative integer called the (Euler) genus of S ; in this case, S is orientable; • or removing g open disks and attaching a Möbius band to each resulting boundary component, for a positive number g called the (Euler) genus of S ; in this case, S is non-orientable.A possibly disconnected surface is a disjoint union of surfaces.A surface with boundary is obtained from a surface (without boundary) by removing a finite set of interiors of disjoint closed disks.The boundary of each disk forms a boundary component of S .The genus of S is defined as the genus of the original surface without boundary.Equivalently, a surface with boundary is a compact, connected Hausdorff topological space in which every point has an open neighborhood homeomorphic to the open disk or the closed half ].
Assume that, under ψ, the annulus bounded by C and C i does not contain C o .Since O is connected, contains C o , and is disjoint from C and C i , it cannot enter the annulus bounded by C and C i .So indeed the claim holds.-Otherwise, under ψ, the circle C o lies in an annulus bounded by C and C i .Since O is connected, contains C o , and is disjoint from C and C i , it must lie in the annulus bounded by C and C o .So the claim also holds.
• Otherwise, the three circles ψ(C i ), ψ(C), and ψ(C o ) are homotopic but non-contractible.So any two of these closed curves bound an annulus in S [17, Lemma 2.4], and thus also in C .There are two subcases:- × 200c)-wall contained in one planar connected component of G − γ, for some cycle γ of G (Proposition 8.3); the cycle γ and the wall are also computed.With the notations of the proof of Proposition 8.3, there exists a two-sided circle C of the subdivided circular wall Ẇ such that the edges of O that have an endpoint of C leave C all on the same of C.Moreover, clearly, we can compute such a circle C in linear time.Once this is done, as in the proof of Proposition 8.3, from the proper embedding of a 5c-homeomorph of G, augmented with at most c isolated vertices, we can compute, in linear time, a proper embedding of a 5c-homeomorph of G, augmented with at most c isolated vertices, into C .Proof of Theorem 9.1.Let G ′ be obtained from G by merging its isolated vertices and path components into a single path component, as in the proof of Proposition 3.1.We apply Lemma 9.2 or 9.3, obtaining a proper embedding of a 5c-homeomorph of G ′ , augmented with at most c isolated vertices, into C (using the data structure of Section 3.4).