# Counting Triangulations and Other Crossing-Free Structures via Onion Layers

## Abstract

Let \(P\) be a set of \(n\) points in the plane. A crossing-free structure on \(P\) is a straight-edge plane graph with vertex set \(P\). Examples of crossing-free structures include triangulations and spanning cycles, also known as polygonalizations. In recent years, there has been a large amount of research trying to bound the number of such structures; in particular, bounding the number of (crossing-free) triangulations spanned by \(P\) has received considerable attention. It is currently known that *every* set of \(n\) points has at most O\((30^{n})\) and at least \(\Omega (2.43^{n})\) triangulations. However, much less is known about the algorithmic problem of counting crossing-free structures of a given set \(P\). In this paper, we develop a general technique for computing the number of crossing-free structures of an input set \(P\). We apply the technique to obtain algorithms for computing the number of triangulations, matchings, and spanning cycles of \(P\). The running time of our algorithms is upper-bounded by \(n^{\mathrm{O}(k)}\), where \(k\) is the number of *onion layers* of \(P\). In particular, for \(k = \hbox {O}(1)\) our algorithms run in polynomial time. Additionally, we show that our algorithm for counting triangulations in the worst case over all \(k\) takes time O\(^{*}(3.1414^{n})\). [In the notations \(\Omega ^{*}(\cdot ), \hbox {O}^{*}(\cdot )\), and \(\Theta ^{*}(\cdot )\), we neglect polynomial terms and we just present the dominating exponential term.] Given that there are several well-studied configurations of points with at least \(\Omega (3.47^{n})\) triangulations, and some even with \(\Omega (8.65^{n})\) triangulations, our algorithm asymptotically outperforms any enumeration algorithm for such instances. We also show that our techniques are general enough to solve the Restricted-Triangulation-Counting-Problem, which we prove to be \(W[2]\)-hard in the parameter \(k\). This implies that in order to be fixed-parameter tractable, our general algorithm must rely on additional properties that are specific to the considered class of crossing-free structures.

### Keywords

Triangulations Crossing-free structures Algorithmic geometry Counting algorithms Matchings Spanning cycles Spanning trees## 1 Introduction

Let \(P\subset \mathbb {R}^{2}\) be a finite set of \(n\) points in general position. A crossing-free structure on \(P\) is a straight-line plane graph whose vertex set is precisely \(P\). Typical examples of crossing-free structures are (crossing-free) triangulations, (crossing-free) spanning cycles, (crossing-free) matchings, and (crossing-free) spanning trees. Throughout the paper, we only consider crossing-free structures; therefore, when referring to triangulations, matchings, spanning cycles, etc., we always assume them to be crossing-free.

*each*class \(\mathcal {F}\) of crossing-free structures can be upper-bounded by a number of type \(c^{n}\), where \(c = c(\mathcal {F}) \in \mathbb {R}^{+}\) depends on the particular class \(\mathcal {F}\). Since then, research has been focused on tightening upper and lower bounds on \(c\) for many different classes of crossing-free structures. Table 1 gives the currently best asymptotic bounds on the number of triangulations, spanning cycles, perfect matchings, and spanning trees, which are among the most popular and hence most studied crossing-free structures. The symbols \(\le \) and \(\ge \) should be understood as upper bound and lower bound, respectively.

Asymptotic bounds for various classes of crossing-free structures on \(P\) (a set of \(n\) points in the plane)

It is interesting to point out that the number of spanning cycles, perfect matchings, and spanning trees has been proven to be minimum when \(P\) is in convex position, that is, the selected (gray) lower bounds in Table 1 are tight. The interested reader is referred to the work of Aichholzer et al. [5] for a list of other classes of crossing-free structures on \(P\) whose cardinality is minimized when \(P\) is in convex position, and to the work of Dumitrescu et al. and Sheffer [19, 34] for up-to-date lists of asymptotic bounds for other crossing-free structures.

The second question on crossing-free structures mentioned above is of algorithmic flavor: We consider the problem of *computing* the number of crossing-free structures of a *particular* class, say triangulations, for a *given* input set of points \(P\). This problem is closely related to the problem of sampling crossing-free structures of a particular class uniformly at random. A first approach to the counting problem would be to produce *all* elements of the class, using well-known methods for enumeration [4, 14, 15, 26], and then to simply output the number of enumerated elements. This has the obvious disadvantage that the total time spent will be, at best, linear in the number of elements counted. This number, however, is in general exponential in \(n\) (the size of the input \(P\)). Thus, the following question arises naturally: Can we count crossing-free structures of a given class in time sub-linear in the number of elements counted? This question has in general been much less studied. Until very recently (year 2012), it was only known that this is always possible for the class of *all* plane graphs [28], while for triangulations it was only known to be *sometimes* possible [10]. Empirically, there were other algorithms to count triangulations that are observed to count faster than enumeration algorithms [1, 27], but, until now, have no theoretical runtime guarantees. For spanning trees, matchings, and spanning cycles, no efficient counting algorithm was known. However, for some non-trivial classes of spanning cycles (monotone), it was known that exact counting can be done in polynomial time in \(n\) [36].

So far we have discussed the literature on counting crossing-free structures at the time when the preliminary version of this paper appeared [8]. We believe it is important to first list our contributions (Sect. 2) before we elaborate on the newest developments (Sect. 3), which happened during a very short period of time, and in particular, while this paper was under review.

## 2 Our Contributions

**Definition 1**

(*Onion layers*) Let \(P\) be a set of \(n\) points in the plane and let \(\text {CH}(P)\) denote its convex hull. We define the *onion layers* of \(P\) as follows: The first onion layer \(P^{(1)}\) of \(P\) is \(\text {CH}(P)\). For \(i > 1\), the \(i\)th onion layer \(P^{(i)}\) of \(P\) is defined inductively as \(\text {CH}(P\setminus \bigcup _{j = 1}^{i-1} P^{(j)})\). By “number of onion layers of \(P\)” we mean the number of *non-empty* onion layers of \(P\).

Observe that the number of onion layers of any non-degenerate set of \(n\) points is at most \(\small {\lceil \frac{n}{3}\rceil }\). Let us now denote by \(\mathcal {F}_{T}(P), \mathcal {F}_{M}(P)\), and \(\mathcal {F}_{C}(P)\) the classes of all triangulations, matchings, and spanning cycles of \(P\), respectively. Our first contribution is the following:

**Theorem 1**

Let \(P\) be a set of \(n\) points in the plane, and let \(k\) be its number of onion layers. Then the exact value of \(|\mathcal {F}_{T}(P)|\) can be computed in time \(\mathrm{O}^*(f(\frac{n}{k})^{k})\), where \(f(x) = \frac{x^{3} + 3x^{2} + 2x + 2}{2}\). Since \(k~\le ~\small {\lceil \frac{n}{3}\rceil }\), this bound never exceeds \(\mathrm{O}^{*}(3.1414^{n})\). This running time can alternatively be bounded by \(n^{\mathrm{O}(k)}\), which is polynomial for constant \(k\).

We remark that (1) the algorithm of Theorem 1 has a better worst-case guarantee than the previously best algorithm for counting triangulations [10], which runs in time \(\hbox {O}^{*}\left( 9^{n}\right) \). (2) It is the first algorithm that can compute the exact value of \(|\mathcal {F}_{T}(P)|\) in *polynomial time* restricted to a non-trivial subset of all instances (constant number of onion layers). (3) As stated before, for *every* set \(P\) of \(n\) points in the plane, the cardinality of \(\mathcal {F}_{T}(P)\) is at least \(\Omega (2.43^{n})\), but it has been conjectured that this bound can be improved to \(\Omega (\sqrt{12}^{n})\approx \Omega (3.47^{n})\) [2, 3, 29]. If this stronger bound is true, then our algorithm counts triangulations in time \(\hbox {O}^{*}(3.1414^{n}) = o(|\mathcal {F}_{T}(P)|)\), i.e., faster than by using enumeration algorithms, which was not known to be possible up to year 2012, see also Sect. 3.

**Theorem 2**

Let \(P\) be a set of \(n\) points in the plane and let \(k\) be its number of onion layers. Then the exact values of \(|\mathcal {F}_{M}(P)|\) and \(|\mathcal {F}_{C}(P)|\) can be computed in \(n^{\mathrm{O}(k)}\) time.

Again, the algorithms of Theorem 2 compute the exact number of matchings and spanning cycles in polynomial time if the number of onion layers is \(k = \hbox {O}(1)\). This gives a partial answer to Problem 16 of The Open Problems Project, which asks whether \(|\mathcal {F}_{C}(P)|\) can be computed in polynomial time [18]. However, in Theorem 2 we are not able to prove a running time guarantee of the form \(c^{n}\) for large \(k\), as in Theorem 1.

The general layout of the algorithms of Theorems 1 and 2 is similar to the one by Anagnostou et al. [12], where these ideas have been used for optimization problems.

Observe that the running times of Theorems 1 and 2 can be stated as \(n^{f(k)}\) for some function \(f\) that does not depend on \(n\). With regard to parameterized complexity, it is natural to ask whether these running times can be improved to \(g(k)\cdot n^{\mathrm{O}(1)}\) for some function \(g\) that does not depend on \(n\), thus proving that our problems belong to the complexity class FPT, which is the class of fixed-parameter tractable problems. However, the techniques involved in the algorithms of Theorems 1 and 2 are general enough to solve more general problems, such as the following: Restricted-Triangulation-Counting-Problem: Given a set of points \(P\) and a subset of edges \(E\) over \(P\), count the triangulations of \(P\) whose set of edges is a subset of \(E\). We prove the following.

**Theorem 3**

The Restricted-Triangulation-Counting-Problem is W[2]-hard if the parameter is the number of onion layers of \(P\). This result even holds for the problem of just deciding the *existence* of a restricted triangulation.

The book by Flum and Grohe [21] is a standard reference for parameterized complexity theory, where the classes FPT and W[2] are defined. The separation FPT \(\ne \) W[2] is widely believed. Thus, an algorithm with a running time of the form \(g(k)\cdot n^{\mathrm{O}(1)}\) for the Restricted-Triangulation-Counting-Problem is unlikely to exist. This indicates that we have to exploit the particular structure of the problems in order to obtain fixed-parameter tractable algorithms for counting crossing-free structures in the general non-restricted case.

The rest of the paper is structured as follows: In Sect. 3 we briefly elaborate on the developments that occurred while this paper was under review. We prove Theorems 1 and 2 in Sects. 4 and 5, respectively. The proof of Theorem 3 is not contained in this extended abstract but can be found in the ArXiv version of this paper [9], where we also present experiments comparing our algorithm for counting triangulations (Theorem 1) with the empirically fast algorithm of Ray et al. [27]. We conclude our paper in Sect. 6.

## 3 Subsequent Developments on Algorithmic Counting (2013–2014)

While this paper was under review, many important developments occurred regarding the problem of counting crossing-free structures algorithmically. We briefly list these developments in this section.

In 2013 a new, and rather simple, algorithm for counting triangulations was presented [7]. This algorithm has a worst-case running time of \(\hbox {O}^{*}(2^{n})\)—setting finally in the positive the question whether enumeration algorithms for triangulations can always be beaten, as *every* set of \(n\) points in the plane has at least \(\Omega (2.43^{n})\) triangulations. However, the new algorithm does not seem to have polynomial time instances, unlike the algorithm for counting triangulations presented in this paper, which runs in polynomial time when the input set \(P\) has a fixed number of onion layers. In fact, experiments [7] show that when the number of onion layers of \(P\) is small, the algorithm presented in this paper greatly outperforms the algorithm by Alvarez et al. [7].

Regarding other classes of crossing-free structures, many strong algorithms were presented in 2014 [35]. These algorithms build upon the ideas by Alvarez et al. [7]. Among other results, it was shown that the number of *all* crossing-free structures can be computed in time \(\hbox {O}^{*}(2.839^{n})\), improving over previous results [28], and it was shown that perfect matchings can be counted in time \(\hbox {O}^{*}(2^{n})\). These algorithms show again that enumeration can, at least in these cases, *always* be beaten. It is, however, still open whether for spanning trees and spanning cycles the same can be proven. Preliminary results in this direction can also be found in [35]. As before, these new algorithms seem not to have polynomial time instance, unlike the algorithms presented in this paper for counting matchings and spanning cycles.

We now proceed to the description of our algorithms and the proofs of Theorems 1 and 2.

## 4 Counting Triangulations Using Onion Layers

In this section we present our algorithm for counting triangulations, which we call *sn-path algorithm*. Its main ingredient are geometric separators, which are derived from the onion layers of the given set of points \(P\).

For any point \(p\in P\), let \(\ell (p)\) denote the index of the onion layer to which \(p\) belongs. Let us label the points \(p\in P\) with distinct labels in \(\{1,\ldots ,n\}\) such that if \(\ell (p) < \ell (q)\), then \(p\) also receives a label smaller than \(q\). This is clearly possible. Figure 1 shows the onion layers of a set of \(17\) points and the labels assigned to them. From now on we refer to the points of \(P\) by their labels, i.e., we think of \(P\) as the set \(\{1,\ldots ,n\}\) and when we say “\(p\in P\)”, we mean the point with label \(p\).

A *descending path* is a sequence of points \(\rho = (p_1,\ldots ,p_k)\) with \(\ell (p_{i+1}) < \ell (p_i)\) for all \(1 \le i < k\). Consider any crossing-free set of straight-line edges \(T\) on \(P\); think of \(T\) as a (partial) triangulation. A descending path \(\rho \) is *maximal w.r.t.* \(T\) if the edges of \(\rho \) are contained in \(T\) and \(\rho \) cannot be extended by edges in \(T\). For any \(p \in P\), we construct a unique maximal descending path w.r.t. \(T\) starting in \(p\), which we call *sn-path*: For any \(q \in P\), if all neighbors \(q'\) of \(q\) in \(T\) have \(\ell (q') \ge \ell (q)\), then set \(\text {sn}_T(q) = \perp \). Otherwise let \(\text {sn}_T(q)\) be the neighbor of \(q\) in \(T\) with smallest label; in this case \(\ell (\text {sn}_T(q)) < \ell (q)\). Then the (unique) descending path \(\rho = (p_1,\ldots ,p_k)\) with (1) \(p_1 = p\), (2) \(p_{i+1} = \text {sn}_T(p_i)\) for all \(1 \le i < k\), and (3) \(\text {sn}_T(p_k) = \perp \) is the sn-path of \(p\) w.r.t. \(T\). Note that every sn-path consists of at most one point from each onion layer. Also note that for \(T' \subseteq T\) if \(\rho \) is an sn-path w.r.t. \(T\), then it is also an sn-path w.r.t. \(T'\). Any descending path satisfying (1) and (2) but not necessarily (3) is called a *partial sn-path* of \(p\) w.r.t. \(T\).

*legal*if (1) \(U\) is crossing-free, (2) \(\rho \) and \(\sigma \) are sn-paths w.r.t. \(U\), and (3) \(\rho \) and \(\sigma \) end in \(P^{(1)}\). In this case \(\rho ,\sigma \) induce a region \(R = R(\rho ,\sigma )\) whose boundary is the union of \(U\) and the part of \(\text {CH}(P)\) from \(p'\) to \(q'\) in clockwise order, see Fig. 2. We call \(R\) the

*sn-region*of \((\rho ,\sigma )\). A

*triangulation of*\(R\) is a maximal set of triangles with vertices in \(P\) partitioning \(R\) such that no triangle contains a point of \(P\) in its interior. Given any \(\text {sn}\)-region \(R\), we refer to the number of triangles in any triangulation of \(R\) as the

*size*of \(R\). This is well defined since the number of triangles is the same regardless of the specific triangulation.

### 4.1 The sn-Path Algorithm

Our algorithm recursively solves the following problem. Given legal descending paths \((\rho ,\sigma )\), count the number of triangulations \(T\) of \(R(\rho ,\sigma )\) satisfying the following *sn-constraint*: \(\rho \) and \(\sigma \) are sn-paths w.r.t. \(T\). We denote the result of instance \((\rho ,\sigma )\) by \(\#(\rho ,\sigma )\).

Initially, we pick vertices \(p,q\) of \(\text {CH}(P)\) that are consecutive in clockwise order. Set \(\rho =(p)\), \(\sigma = (q)\). Note that \(\rho ,\sigma \) are the sn-paths of \(p,q\) w.r.t. any set of edges \(T\), as no point \(v\) has \(\ell (v)\) smaller than \(\ell (p)\) or \(\ell (q)\). Thus, the sn-constraint of \((\rho ,\sigma )\) is trivially satisfied. Moreover, the boundary of \(R(\rho ,\sigma )\) is the whole convex hull of \(P\). Hence, \(\#(\rho ,\sigma )\) is simply the total number of triangulations of \(P\), as desired.

In order to recursively solve an instance \((\rho ,\sigma )\), we enumerate all descending paths \(\delta \) such that \((\rho ,\delta ,\sigma )\) is legal. We return \(\sum _{\delta } \#(\rho ,\delta ) \cdot \#(\delta ,\sigma )\), where the sum ranges over all enumerated \(\delta \).

Note that both sn-regions \(R(\rho ,\delta )\) and \(R(\delta ,\sigma )\) have size smaller than \(R(\rho ,\sigma )\), i.e., fewer triangles in any triangulation. The recursion ends when the size is 0, in which case we know that there is exactly one triangulation, or when there is no \(\delta \) that makes \((\rho ,\delta ,\sigma )\) legal, in which case the result is 0.

### 4.2 Correctness

Consider an instance \((\rho ,\sigma )\) with sn-region \(R = R(\rho ,\sigma )\). We show that (1) every object counted by our algorithm corresponds to a unique triangulation of \(R\) satisfying the sn-constraint, and (2) every triangulation of \(R\) satisfying the sn-constraint is counted at least once.

For (1), fix some enumerated \(\tilde{\delta }=\delta (\rho ,\sigma )\) for a given instance \((\rho ,\sigma )\). In both recursive sub-problems \((\rho ,\tilde{\delta })\) and \((\tilde{\delta },\sigma )\), fix some enumerated descending paths \(\delta (\rho ,\tilde{\delta }), \delta (\tilde{\delta },\sigma )\) as well. Iteratively fix in each recursive sub-problem \((\rho ',\sigma ')\) some third path \(\delta (\rho ',\sigma ')\). Consider the union \(S\) over all recursive sub-problems \((\rho ',\sigma ')\) (arising from all the sn-paths that we iteratively fixed) of the set \(\{\rho ',\sigma ',\delta (\rho ',\sigma '), \Delta (\rho ',\delta (\rho ',\sigma '),\sigma ')\}\). Note that our algorithm counts all objects \(S\). Consider the union \(T\) of all edges of all descending paths and all triangles in such a counted set \(S\). Note that \(T\) is crossing-free, since at the start of each recursive call \((\rho ',\sigma ')\) we have not picked any edges in the interior of the current region \(R' \subseteq R\) yet, and every new descending path \(\delta '\) and triangle \(\Delta (\rho ',\delta ',\sigma ')\) that we construct do not cross the boundary of \(R'\). Moreover, \(T\) is a triangulation of \(R\), since we repeatedly add triangles, and the only base case of the recursion in which we return a non-zero number is when the size of the current region \(R'\) is 0, in which case it is already triangulated.

We show that \(T\) satisfies the sn-constraint, i.e., \(\rho \) and \(\sigma \) are sn-paths w.r.t. \(T\). Assume for contradiction that the sn-path condition of \(\rho \) is not satisfied in \(T\) for some point \(a\) of \(\rho \). Let \(b\) be the successor of \(a\) on \(\rho \). Consider the first recursive sub-problem \((\rho ',\sigma ')\), with third path \(\delta '\), where we violate the sn-path condition of \(\rho \) at \(a\), i.e., \(\delta '\) or \(\Delta (\rho ',\delta ',\sigma ')\) contains an edge \((a,c)\) with \(c < b\). Since \(a\) appears on the boundary of \(R\) and the edge \((a,c)\) is contained in the current region \(R' \subseteq R\), the point \(a\) also appears on the boundary of \(R'\), i.e., \(a\) is contained in \(\rho '\) or \(\sigma '\), say in \(\rho '\). Its successor on \(\rho '\) has label at least \(b\), since \((a,c)\) is the first edge that we add with \(c<b\). Thus, the edge \((a,c)\) violates the sn-path condition not only of \(\rho \), but also of \(\rho '\), since \(c < b\). However, we explicitly check that \((\rho ',\delta ',\sigma ')\) is legal, so we check that \(\rho '\) is an sn-path w.r.t. a set \(U(\rho ',\delta ',\sigma ')\) that contains the added edge \((a,c)\). This is a contradiction, which implies that the sn-path property is preserved at every point \(a\) of \(\rho \). A symmetric statement holds for edges on \(\sigma \). Hence, each counted object corresponds to a triangulation of \(R\) satisfying the sn-constraint.

To see that there is no overcounting, let \(S_1,S_2\) be two counted objects and consider any recursive sub-problem \((\rho ',\sigma ')\) where they diverge, i.e., where we choose different \(\delta _1\) and \(\delta _2\) when constructing \(S_1\) and \(S_2\). If \(\Delta (\rho ',\delta _1,\sigma ') \ne \Delta (\rho ',\delta _2,\sigma ')\), then these triangles are intersecting, so that the triangulations corresponding to \(S_1\) and \(S_2\) are different. Otherwise, \(\delta _1\) and \(\delta _2\) have the same starting point \(z\). Observe that all further choices produce triangulations in which \(\delta _1\) (or \(\delta _2\), respectively) is the sn-path of \(z\). Since sn-paths are unique and \(\delta \ne \delta '\), the triangulations corresponding to \(S_1\) and \(S_2\) are different.

For (2), consider any triangulation \(T\) of \(R\) satisfying the sn-constraint. Let \(p,q\) be the starting points of \(\rho ,\sigma \). Recall that \((p,q)\) is an edge of the boundary of \(R\). If \((p,q)\) is also an edge of \(\rho \), then \(\rho \) is \((p,q)\) followed by \(\sigma \), because two merged sn-paths cannot split again. Thus \(R\) has size \(0\) and we return 1. If \((q,p)\) is an edge of \(\sigma \) we have a symmetric case. Otherwise, in \(T\) the points \(p,q\) form a triangle with a third point \(z\). Let \(\delta \) be the sn-path of \(z\) w.r.t. \(T\). Observe that \((\rho ,\delta ,\sigma )\) is legal. Thus, recursively we construct \(T\) as a union of sn-paths and triangles, and \(T\) is counted in the product \(\#(\rho ,\delta ) \cdot \#(\delta ,\sigma )\).

### 4.3 Running Time

We add one important ingredient for efficiency: Memoization. Whenever we have computed the answer to a recursive sub-problem, we store it in a dictionary data structure, such as a hash table. This way, we can bound the total running time of the algorithm by summing the time it takes to enumerate \(\delta \) over all legal descending paths \((\rho ,\sigma )\). Since all checks take polynomial time, the total running time can be bounded, up to polynomial factors, by the number \(M\) of triples \((\rho ,\sigma ,\hat{\delta })\), where \((\rho ,\sigma )\) are legal descending paths and \(\hat{\delta }\) is any intermediate path constructed during the enumeration of all possible \(\delta \). Observe that for enumerating \(\delta \), we can build a descending path step by step, making sure that at all points in time \(\hat{\delta }\) is a partial sn-path (w.r.t. \(U(\rho ,\hat{\delta },\sigma )\)), and that \(\rho \) and \(\sigma \) stay as sn-paths (w.r.t. \(U(\rho ,\hat{\delta },\sigma )\)). For any such triple \((\rho ,\sigma ,\hat{\delta })\) counted by \(M\), let \(\sigma '\) be the portion of \(\sigma \) that does not have any points in common with \(\rho \), and let \(\delta '\) be the portion of \(\hat{\delta }\) that does not have any points in common with \(\rho \) or \(\sigma \). The descending paths \(\rho ,\sigma ',\delta '\) are crossing-free and vertex-disjoint. Moreover, we can reconstruct \(\sigma \) from \((\rho ,\sigma ')\) if we know whether \(\sigma \) has a point in common with \(\rho \) and what is the first such point. This is because once two sn-paths merge their remaining portions are equal, as subpaths of sn-paths are also sn-paths and thus unique. Thus, we need \(\hbox {O}(\log n)\) bits to reconstruct \(\sigma \) from \((\rho ,\sigma ')\). Similarly, we can reconstruct the partial sn-path \(\hat{\delta }\) from \((\rho , \sigma , \delta ')\) if we know its length and whether and where it merges with \(\rho \) or \(\sigma \), which can be encoded using \(\hbox {O}(\log n)\) bits. Hence, we can bound \(M \le 2^{\mathrm{O}(\log n)} N = \hbox {O}^*(N)\), where \(N\) is the number of crossing-free vertex-disjoint triples of descending paths.

The number of triples of non-crossing vertex-disjoint descending paths is therefore \(N \le \prod _{i=1}^{k}f(n_i)\). Since each \(n_i\) is a positive integer, and the function \(f(\cdot )\) is log-concave^{1} for \(x\ge 1\), the above product is maximized when each \(n_i\) is equal to \(\frac{n}{k}\). This gives an upper bound of \(f(\frac{n}{k})^k \le ( \frac{n}{k} )^{\mathrm{O}(k)}\). Alternatively, we can bound the running time by \(g(\frac{n}{k})^n\), where \(g(x)~=~f(x)^{\frac{1}{x}}\) is a decreasing function for \(x\ge 1\). Since each onion layer except the \(k\)th one must have at least three points, we have \(N=\hbox {O}\left( g(3)^n\right) \). The fact that the \(k\)th onion layer may have fewer than three points makes only a difference of a constant factor. Therefore, the running time of the algorithm presented in this section is \(\hbox {O}^*(g(3)^n) = \hbox {O}^{*}(\root 3 \of {31}^{n}) = \hbox {O}^{*}(3.1414^n)\). This concludes the proof of Theorem 1.

We want to point out that often the number of onion layers can be much smaller than the maximum possible \(\lceil \frac{n}{3}\rceil \). For example, Dalal [17] has shown that if \(n\) points are chosen uniformly at random from a disk, then the expected number of onion layers of the resulting point set is \(k = \Theta (n^{2/3})\). Using Markov’s inequality, this implies that with high probability,^{2} we have \(N \le 2^{n^{2/3 + o(1)}}\). Hence, with high probability, our algorithm runs in sub-exponential time for points randomly distributed on a disk.

## 5 Counting Other Crossing-Free Structures

In this section, we show how the ideas of the sn-path algorithm can be augmented in order to develop a general framework for counting many classes of crossing-free structures. We use this framework to count matchings and spanning cycles.

The overall idea can be roughly described as follows: Suppose we want to count the elements of a particular class \(\mathcal {F}\) of crossing-free structures on \(P\). A set \(S\) of non-crossing edges on \(P\) is called a *separator* if the union of the edges in \(S\) splits (the interior of) \(\text {CH}(P)\) into at least two regions, say regions \(R^S_1\), \(R^S_2\), ..., \(R^S_t\). Now assume that there exists a set \(\mathcal {S}\) of separators with the following properties: (1) Every element of \(\mathcal {F}\) contains a *unique* separator \(S\in \mathcal {S}\); (2) choosing an element of \(\mathcal {F}\) with separator \(S\) can be done *independently* in the regions \(R^S_i\); and (3) we can quickly enumerate the members of \(\mathcal {S}\). With such a set of separators \(\mathcal {S}\), the elements of \(\mathcal {F}\) can be counted as follows: Recursively compute the number \(n^{S}_{i}\) of elements of \(\mathcal {F}\) of each region \(R^S_i\). The number of elements of \(\mathcal {F}\) containing \(S\) is then \(N^S=\prod _{i=1}^{t} n^{S}_{i}\). Thus, the total number of elements of \(\mathcal {F}\) is simply \(\sum _{S \in \mathcal {S}} N^S\). Of course, in the recursion, a set of separators is required in each \(R^S_i\). We fill in the details of this approach in the following sections.

### 5.1 Annotations

Assume we want to count all matchings spanned by \(P\). We have to ensure that each vertex that is contained in the separator \(S\) is matched consistently in all of its incident regions. In any matching \(M\) that fits to a separator \(S\), each vertex in \(S\) is unmatched, or matched to a vertex strictly within some region \(R^{S}_{i}\), or matched to another vertex in \(S\). We can *annotate* each separator \(S\) with this information. When counting, for each \(S\in \mathcal {S}\), we iterate over all annotations of \(S\), and ensure consistency with the current annotation in all recursive calls.

In general, the choice of the annotation scheme heavily depends on the class of crossing-free structures. We present annotations for matchings and spanning cycles in this paper, whereas an annotation scheme for spanning trees was designed by Alvarez et al. [11].

### 5.2 Embedding Crossing-Free Structures into Triangulations

Again assume that we want to count matchings. Property (1) above states that each matching should have a unique separator \(S\). This seems hard to achieve directly, especially since a matching can contain very few edges, leaving much freedom to choose a separator. However, we have seen that unique separators exist for triangulations, specifically sn-paths. Hence, we do not count matchings directly, but we count *matchings embedded in a triangulation*. In order not to overcount matchings, we choose a *unique* triangulation \(T^M\) containing the matching \(M\) and count all pairs \((M,T^M)\). Given a suitable family \(\mathcal {S}\) of separators for the triangulations of \(P\), such as sn-paths, we count \((M,T^M)\) and thus \(M\) for exactly one \(S \in \mathcal {S}\). Specifically, we choose the unique triangulation \(T^M\) to be the constrained Delaunay triangulation (CDT) \(\triangle ^M \supset M\), which we briefly describe next.

#### 5.2.1 Constrained Delaunay Triangulation

The constrained Delaunay triangulation (CDT) \(\triangle ^{S}\) of a point set \(P\) and a set of (crossing-free straight-line) edges \(S\) on \(P\) was first introduced by Chew [16]. Formally, it is the triangulation \(T\) of \(P\) containing \(S\) such that no edge \(e\) in \(T\setminus S\) is flippable in the following sense: Let \(\triangle _{1}\) and \(\triangle _{2}\) be triangles of \(P\) sharing \(e\). The edge \(e\) is flippable if and only if \(\square = \triangle _{1}\cup \triangle _{2}\) is convex, and replacing \(e\) with the other diagonal of \(\square \) increases the smallest angle of the triangulation of \(\square \). One of the most important properties of constrained Delaunay triangulations is its *uniqueness* if no four points of \(P\) are cocircular. Thus, under standard non-degeneracy assumptions, there is a unique CDT for any given set of mandatory edges. For a good study on constrained Delaunay triangulations we suggest the book by Hjelle and Dæhlen [23].

From now on we will assume that no four points of \(P\) are cocircular. We can now go back to our simple algorithm for counting matchings and revise it as follows: After picking a separator \(S\), in each recursive sub-problem we only count matchings \(M\) such that \(S \subseteq \triangle ^M\), where \(S\in \mathcal {S}\) is a separator. If this last condition can be checked locally in each recursive call, i.e., choices in one sub-problem do not depend on choices in others, we are done. Since not every set of separators \(\mathcal {S}\) admits such a locality condition, we construct a new family of separators in the next section.

### 5.3 Triangular Paths

We assume again that \(P\) has \(k\) onion layers. For every point \(p \in P\) (on layer \(P^{(i)}\) which is not the first layer), we fix in advance a ray \(\tau _p\) which emanates from \(p\), avoids other points of \(P\), and does not intersect the interior of \(\text {CH}(P^{(i)})\).

*triangular path*of \(p\) w.r.t. \(T\), see Fig. 4. It is easy to see that the triangular path \(P_p(T)\) is uniquely defined for any triangulation \(T\). Moreover, for distinct triangulations \(T_1\) and \(T_2\), \(P_p(T_1)\) and \(P_p(T_2)\) are either identical or they intersect properly: Let \(i\) be the first position where \(\triangle _{p_i}(T_1) \ne \triangle _{p_i}(T_2)\), then those two triangles intersect, as they both are adjacent to \(p\), intersect \(\tau _p\), and have interiors free of points in \(P\). We are now ready to present the algorithm for counting matchings.

### 5.4 Algorithm for Counting Matchings

Each edge \(e\) of \(\triangle ^{M}\) is annotated with a bit \(b_{e}\) that indicates whether \(e\) belongs to \(M\) or not.

Each vertex \(p\) of \(\triangle ^{M}\) is annotated with a number \(0\le m_{p}\le n\) that represents the point in \(P\) that \(p\) is matched to. If \(m_{p}\) is (say) \(0\) then we know that \(p\) is not matched in \(M\).

Let us denote by \(\bar{\triangle }^{M}\) the annotated version of \(\triangle ^{M}\). Let \(S\) be a separator contained in \(\triangle ^{M}\) that splits \(\text {CH}(P)\) into regions \(R^{S}_{1},\ldots , R^{S}_{t}\). Separator \(S\) inherits all the information from \(\bar{\triangle }^{M}\). The separator thus annotated will be denoted by \(\bar{\triangle }^{M}_{S}\).

We say that an annotated constrained Delaunay triangulation is *legal* if and only if it is identical to \(\bar{\triangle }^{M}\) for some matching \(M\). Since there is a one-to-one correspondence between matchings and legal annotated constrained Delaunay triangulations, our goal is to count the latter.

*all possible*annotations for

*each one of them*. Each such annotated separator splits \(\text {CH}(P)\) into two smaller regions, which we solve recursively. In each such recursive sub-problem, we count legal annotated constrained Delaunay triangulations consistent with the annotated separator, i.e., for example, if two adjacent vertices of the separator have been annotated, and they agree to be matched to each other and the edge connecting them is annotated to be in the matching, then in future recursive sub-problems other edges adjacent to those two vertices cannot be annotated to be in a matching as well. Clearly, the only sub-problems that will contribute to the final computed number of matchings are the ones for which the algorithm, in its whole run, could complete a full annotated constrained Delaunay triangulation without finding any violation of the annotations inherited by the separators that led to that triangulation.

Let us elaborate on why it is necessary to use triangular paths instead of sn-paths. Note that no edge of a separator, formed by a triangular path, lies on the boundary of more than one sub-problem. This allows us to verify flippability of edges separately, and independently, in each sub-problem. If an edge belonged to more than one sub-problem (as is the case for sn-paths), then the flippability of this edge would depend on the choices made in each sub-problem, thus introducing dependency between these sub-problems.

As in the algorithm for counting triangulations, we use memoization so that the running time is dominated by the number of triples of annotated triangular paths. The size of each triangular path is \(\hbox {O}(k)\), and thus there are clearly at most \(n^{\mathrm{O}(k)}\) triangular paths. There are no more than \(n^{\mathrm{O}(k)}\) possible annotations per triangular path, as can be easily checked. In total, there are \(n^{\mathrm{O}(k)}\) triples of annotated triangular paths. Thus, the overall running time is \(n^{\mathrm{O}(k)}\), which even considers the polynomial overhead arising from checking flippability of edges and inclusion of points in triangles. This concludes the first part of Theorem 2.

In contrast to our algorithm for counting triangulations that runs in time \(\hbox {O}^{*}(3.1414^n)\) (see Sect. 4.3), for counting matchings we cannot prove a running time of the form \(c^n\) with a reasonably small constant \(c\). The reason is that triangular paths not only consist of descending paths, but also of dangling triangles, whose third point can be on an arbitrary layer. Specifically, if we consider the layers of the third vertices of all dangling triangles, then they are not sorted. This makes it hard to bound the number of triangular paths.

The annotations required for counting matchings are not very complicated, but for many other counting problems, this is a highly non-trivial task. An example of more involved annotations is given in the next section, where we consider the problem of counting spanning cycles.

### 5.5 Algorithm for Counting Spanning Cycles

Counting spanning cycles is more complicated than counting matchings. We first reduce the problem to counting *rooted and oriented* spanning cycles: Given any spanning cycle, we make it rooted by designating a *starting vertex*, and we make it oriented by assigning an *orientation* (clockwise or counter-clockwise). We then number the vertices in the spanning cycle from \(1\) to \(n\), beginning at the starting vertex (which is the root of the cycle) and continuing along the assigned direction. We also direct the edges along this direction. This way, each spanning cycle corresponds to exactly \(2n\) rooted and oriented spanning cycles, so it suffices to count the latter and divide by \(2n\). In the remainder we use the term HamCycle for rooted and oriented spanning cycles.

Each edge \(e\) in \(\triangle ^{H}\) is annotated with a bit \(b_{e}\) that indicates whether \(e\) belongs to \(H\) or not.

Each vertex \(p\) of \(\triangle ^{H}\) is annotated with \((\text {pos}_{p}, \text {prev}_{p}, \text {next}_{p})\), where \(\text {pos}_{p}\) is the number assigned to \(p\) in \(H\), \(\text {prev}_{p}\) is the point lying immediately before \(p\) in \(H\), and the \(\text {next}_{p}\) is the point lying immediately after \(p\) in \(H\).

The algorithm for counting matchings now carries over verbatim, if we appropriately enumerate annotations and check their consistency. The running time is again \(n^{\mathrm{O}(k)}\). This concludes the proof of Theorem 2.

## 6 Conclusions

In this paper, we have presented algorithms to count triangulations, crossing-free matchings, and crossing-free spanning cycles of a given set of points \(P\). All algorithms use the onion layers of \(P\) and the divide-and-conquer paradigm.

The algorithm to count triangulations presented in this paper has a provable worst-case running time of \(\hbox {O}^{*}(3.1414^{n})\). Moreover, it runs in polynomial time whenever the number of onion layers of the given set of points is constant. No other algorithm is currently known that runs in polynomial time restricted to any non-trivial set of instances. Finally, recent experiments [7, 9] indicate that our algorithm is highly relevant in practice as well.

Regarding other crossing-free structures, we presented a general framework that allows us to exactly count crossing-free structures that can be unequivocally encoded with an annotation scheme. We showed how to use our framework by giving annotation schemes that encode (perfect) matchings and spanning cycles. Very recently an annotation scheme for spanning trees, which is fully compatible with our framework, was designed by Alvarez at al. [11] (in the context of approximate counting). We obtained algorithms to exactly count these structures in time \(n^{\mathrm{O}(k)}\), where \(k\) is the number of onion layers. This implies polynomial-time algorithms for fixed \(k\). Algorithms with this property were not known before for these problems, and this, in particular, gives a partial answer to Problem 16 of The Open Problems Project, which asks whether \(|\mathcal {F}_{C}(P)|\) can *always* be computed in polynomial time [18].

In view of very recent developments on counting crossing-free structures [7, 11, 35], the most interesting question at this point is whether exact counting can always be done in sub-exponential time \((2^{o(n)})\), or, even more, whether it can always be done in polynomial time.

Our counting algorithms also allow us to generate crossing-free structures uniformly at random. For example, the problem of generating spanning cycles (uniformly) at random has attracted the attention of researchers for almost 20 years [13], in the form of generating random simple polygons on \(P\). Since our algorithms are based on the divide-and-conquer paradigm, we can easily adapt the method explained by Aichholzer [1] to produce such random structures, after running the counting algorithm.

## Footnotes

### References

- 1.Aichholzer, O.: The path of a triangulation. In: Proceedings of the 15th Annual Symposium on Computational Geometry, SoCG ’99, pp. 14–23. ACM Press, New York (1999)Google Scholar
- 2.Aichholzer, O., Krasser, H.: The point set order type data base: a collection of applications and results. In: Proceedings of the 13th Canadian Conference on Computational Geometry, CCCG ’01, pp. 17–20. Waterloo (2001)Google Scholar
- 3.Aichholzer, O., Hurtado, F., Noy, M.: A lower bound on the number of triangulations of planar point sets. Comput. Geom.
**29**(2), 135–145 (2004)CrossRefMATHMathSciNetGoogle Scholar - 4.Aichholzer, O., Aurenhammer, F., Huemer, C., Vogtenhuber, B.: Gray code enumeration of plane straight-line graphs. Graphs Comb.
**23**(5), 467–479 (2007)CrossRefMATHMathSciNetGoogle Scholar - 5.Aichholzer, O., Hackl, T., Huemer, C., Hurtado, F., Krasser, H., Vogtenhuber, B.: On the number of plane geometric graphs. Graphs Comb.
**23**(1), 67–84 (2007)CrossRefMATHMathSciNetGoogle Scholar - 6.Ajtai, M., Chvátal, V., Newborn, M., Szemerédi, E.: Crossing-free subgraphs. In: Peter, G.S., Hammer, L., Rosa, A., Turgeon, J. (eds.) Theory and Practice of Combinatorics a Collection of Articles Honoring Anton Kotzig on the Occasion of His Sixtieth Birthday. North-Holland Mathematics Studies, vol. 60, pp. 9–12. North-Holland, Amsterdam (1982)Google Scholar
- 7.Alvarez, V., Seidel, R.: A simple aggregative algorithm for counting triangulations of planar point sets and related problems. In: Proceedings of the 29th Annual Symposium on Computational Geometry, SoCG ’13, pp. 1–8. ACM Press, New York (2013)Google Scholar
- 8.Alvarez, V., Bringmann, K., Curticapean, R., Ray, S.: Counting crossing-free structures. In: Proceedings of the 28th Annual Symposium on Computational Geometry, SoCG ’12, pp. 61–68. ACM Press, New York (2012)Google Scholar
- 9.Alvarez, V., Bringmann, K., Curticapean, R., Ray, S.: Counting triangulations and other crossing-free structures via onion layers. Computing Research Repository (CoRR) (2013). Available at http://arxiv.org/abs/1312.4628
- 10.Alvarez, V., Bringmann, K., Ray, S.: A simple sweep line algorithm for counting triangulations and pseudo-triangulations. Computing Research Repository (CoRR) (2013). Available at http://arxiv.org/abs/1312.3188
- 11.Alvarez, V., Bringmann, K., Ray, S., Seidel, R.: Counting triangulations and other crossing-free structures approximately. Comput. Geom.
**48**(5), 386–397 (2015)CrossRefMathSciNetGoogle Scholar - 12.Anagnostou, E., Corneil, D.: Polynomial-time instances of the minimum weight triangulation problem. Comput. Geom.
**3**(5), 247–259 (1993)CrossRefMATHMathSciNetGoogle Scholar - 13.Auer, T., Held, M.: Heuristics for the generation of random polygons. In: Proceedings of the 8th Canadian Conference on Computational Geometry, CCCG ’96, pp. 38–43. (1996)Google Scholar
- 14.Avis, D., Fukuda, K.: Reverse search for enumeration. Discrete Appl. Math.
**65**(1–3), 21–46 (1996)CrossRefMATHMathSciNetGoogle Scholar - 15.Bespamyatnikh, S.: An efficient algorithm for enumeration of triangulations. Comput. Geom.
**23**(3), 271–279 (2002)CrossRefMATHMathSciNetGoogle Scholar - 16.Chew, L.P.: Constrained Delaunay triangulations. Algorithmica
**4**(1–4), 97–108 (1989)CrossRefMATHMathSciNetGoogle Scholar - 17.Dalal, K.: Counting the onion. Random Struct. Algorithms
**24**(2), 155–165 (2004)CrossRefMATHMathSciNetGoogle Scholar - 18.Demaine, E., Mitchell, J.S.B., O’Rourke, J.: Problem 16: Simple Polygonalizations. http://cs.smith.edu/~orourke/TOPP/P16.html#Problem.16 (2014). Accessed 12 May 2014
- 19.Dumitrescu, A., Schulz, A., Sheffer, A., Tóth, C.D.: Bounds on the maximum multiplicity of some common geometric graphs. SIAM J. Discrete Math.
**27**(2), 802–826 (2013)CrossRefMATHMathSciNetGoogle Scholar - 20.Flajolet, P., Noy, M.: Analytic combinatorics of non-crossing configurations. Discrete Math.
**204**(1–3), 203–229 (1999). Selected papers in honor of Henry W. GouldCrossRefMATHMathSciNetGoogle Scholar - 21.Flum, J., Grohe, M.: Parameterized Complexity Theory. Texts in Theoretical Computer Science. An EATCS Series. Springer, Berlin (2006)Google Scholar
- 22.García, A., Noy, M., Tejel, J.: Lower bounds on the number of crossing-free subgraphs of \({K}_n\). Comput. Geom.
**16**(4), 211–221 (2000)CrossRefMATHMathSciNetGoogle Scholar - 23.Hjelle, Ø., Dæhlen, M.: Triangulations and Applications (Mathematics and Visualization). Springer, Berlin (2006)Google Scholar
- 24.Hoffmann, M., Schulz, A., Sharir, M., Sheffer, A., Tóth, C., Welzl, E.: Counting plane graphs: flippability and its applications. In: Pach, J. (ed.) Thirty Essays on Geometric Graph Theory, pp. 303–325. Springer, New York (2013)CrossRefGoogle Scholar
- 25.Huemer, C., de Mier, A.: Lower bounds on the maximum number of non-crossing acyclic graphs. arXiv preprint 1310.5882, (2013). Available http://arxiv.org/abs/1310.5882
- 26.Katoh, N., Tanigawa, S.: Fast enumeration algorithms for non-crossing geometric graphs. Discrete Comput. Geom.
**42**(3), 443–468 (2009)CrossRefMATHMathSciNetGoogle Scholar - 27.Ray, S., Seidel, R.: A simple and less slow method for counting triangulations and for related problems. In: Proceedings of the 20th European Workshop on Computational Geometry, EWCG ’04 (2004)Google Scholar
- 28.Razen, A., Welzl, E.: Counting plane graphs with exponential speed-up. In: Calude, C., Rozenberg, G., Salomaa, A. (eds.) Rainbow of Computer Science, vol. 6570, pp. 36–46. Springer, Heidelberg (2011)CrossRefGoogle Scholar
- 29.Santos, F., Seidel, R.: A better upper bound on the number of triangulations of a planar point set. J. Comb. Theory Ser. A
**102**(1), 186–193 (2003)CrossRefMATHMathSciNetGoogle Scholar - 30.Sharir, M., Welzl, E.: On the number of crossing-free matchings, cycles, and partitions. SIAM J. Comput.
**36**(3), 695–720 (2006)CrossRefMATHMathSciNetGoogle Scholar - 31.Sharir, M., Sheffer, A.: Counting triangulations of planar point sets. Electron. J. Comb.
**18**(1), P70 (2011)MathSciNetGoogle Scholar - 32.Sharir, M., Sheffer, A., Welzl, E.: On degrees in random triangulations of point sets. J. Comb. Theory Ser. A
**118**(7), 1979–1999 (2011)CrossRefMATHMathSciNetGoogle Scholar - 33.Sharir, M., Sheffer, A., Welzl, E.: Counting plane graphs: perfect matchings, spanning cycles, and Kasteleyn’s technique. J. Comb. Theory Ser. A
**120**(4), 777–794 (2013)CrossRefMATHMathSciNetGoogle Scholar - 34.Sheffer, A.: Numbers of plane graphs. http://www.cs.tau.ac.il/~sheffera/counting/PlaneGraphs.html (2014). Accessed May 12 2014
- 35.Wettstein, M.: Counting and enumerating crossing-free geometric graphs. In: Proceedings of the 30th annual Symposium on Computational Geometry, SoCG ’14, pp. 1–10. ACM Press, New York (2014)Google Scholar
- 36.Zhu, C., Sundaram, G., Snoeyink, J., Mitchell, J.S.: Generating random polygons with given vertices. Comput. Geom.
**6**(5), 277–290 (1996)CrossRefMATHMathSciNetGoogle Scholar