BFS versus DFS for fixed-level targets in ordered trees

Stoyan Dimitrov
Department of Mathematics, Dartmouth college
emailtostoyan@gmail.com
Martin Minchev
Faculty of Mathematics and Informatics, Sofia University
mjminchev@fmi.uni-sofia.bg
Yan Zhuang
Department of Mathematics and Computer Science, Davidson College
yazhuang@davidson.edu


Abstract

We find the average time complexity of the breadth-first search (BFS) and the depth-first search (DFS) algorithms, when one searches for a target node selected uniformly at random among all nodes at level \(\ell\) in the set of ordered trees with \(n\) edges. Intuition suggests that on average BFS must be asymptotically faster than DFS if and only if \(\ell\), as a function of \(n\), is below a certain threshold. We confirm this intuition by showing that there exists a unique constant \(\lambda\approx 0.789004\), such that in expectation BFS is asymptotically faster than DFS if and only if \(\ell\leq \lambda\sqrt{n}\). This gives us a practical rule to select between the two algorithms, even when we do not know the exact value of \(\ell\), but only an estimate of it. Furthermore, we find the asymptotic average time complexity of BFS in the given setting for an arbitrary class of Galton–Watson trees, which includes ordered trees, binary trees, and other popular classes. We use results on the occupation measure of Brownian excursions, as well as combinatorial identities related to lattice paths. Finally, we consider the simple truncated DFS algorithm, which can be shown easily to be asymptotically faster than both BFS and DFS when \(\ell\) is known in advance. We show that in fact its asymptotic time complexity is \(1/2\) of the asymptotic complexity of BFS, when \(\ell = s\sqrt{n}\) for any constant \(s\). Several further questions are also raised.

Keywords: breadth-first search, depth-first search, average-case complexity, trees, Galton–Watson trees, random graphs.

1 Introduction↩︎

Several important problems in computer science and artificial intelligence can be formulated as search problems [1]. Some examples include the traveling salesman problem, scheduling problems, and the problem of finding optimal moves in various games. Most decision-making problems can be also naturally thought of as search problems, where the decision space is modeled as a graph or a tree. For many of these problems, a different search algorithm is optimal, depending on the instance [2]. Some machine learning approaches exist for algorithm selection [3] depending on the instance, but they are usually less useful than having an exact average-case comparison.

In this paper, we find the average time complexity of the classical tree search algorithms—breadth-first search (BFS) and depth-first search (DFS)—when we perform a search for a random target node at a fixed level, given that we begin at the root of an ordered tree with a prescribed number of edges. We consider the most simple scenario when no additional information about the tree is available. Then, it is reasonable to assume that the target node is sampled uniformly from all nodes at the prescribed level among all trees with the given number of edges. BFS and DFS are compared in terms of their complexities for each target node level, yielding an optimal criterion for choosing between them.

In particular, by using a folklore correspondence between ordered trees and Dyck paths, we find that the expected number of steps made by DFS, when we search for a unique target node on level \(\ell\) in a tree with \(n\) edges, is \(\frac{\ell}{2\ell +1}(n+\ell + 1)\). Then, we find the expected number of steps made by BFS via results of Takács [4] on the occupation measure of Brownian excursions. A connection between the generating function for the BFS time-complexity and the so-called Fibonacci polynomials is also established. The average time complexities of the two algorithms are compared in the asymptotic case, when \(\ell,n\to \infty\), and when \(\ell\) is a function of \(n\). Consequently, we find a unique threshold \(\lambda_{n}\approx 0.789\sqrt{n}\), such that BFS is asymptotically faster than DFS if and only if \(\ell\leq \lambda_n\). This confirms the intuition that BFS should have advantage when the target is close to the root, while DFS is superior when the target is far from the root. The limit of the ratio of the two complexities is also found for certain intervals for the target level \(\ell\).

While ordered trees are a very general class of structures used to model various recursive processes, we also find the asymptotic average time complexity of BFS for an arbitrary class of Galton–Watson trees, which includes ordered trees, binary and \(m\)-ary trees, labeled trees and other classes. This generalization is obtained by utilizing some results on stochastic process and the limiting shape of trees by Aldous [5]. Finally, we propose a variation of DFS called truncated DFS, and we show that it has a better average time performance than both BFS and DFS when the target level \(\ell\) is known in advance. It is also shown that the average-case time complexity of the truncated DFS is half of those of BFS, when \(\ell = s\sqrt{n}\), for any constant \(s\).

Our results have several possible applications, since they are related to the complexity of the two most popular search algorithms in the universal scenario of traversing a tree. Note that in the cases when the size of the tree, \(n\), is not known in advance, one may first use the well-known method of Knuth [6] to estimate that size, before using our formulas to find the better search method for different levels \(\ell\).

1.1 Problem formulation and main result↩︎

Consider the set \(\mathcal{T}\) of all unlabeled rooted ordered trees, which we simply refer to as ordered trees or trees. In each ordered tree, we have a fixed node called a root, as well as a fixed ordering for the children of each node. Let \(\mathcal{T}_{n}\) denote the subset of trees in \(\mathcal{T}\) having exactly \(n\) edges; it is well known that the number of trees in \(\mathcal{T}_{n}\) is the \(n\)th Catalan number \[C_{n} = \frac{1}{n+1}\binom{2n}{n}.\] Note that each tree in \(\mathcal{T}_{n}\) has \(n+1\) nodes. The level of a node \(v\) is the length of the unique path from \(v\) to the root; thus the root is at level \(0\). Trees will be drawn with the root at the top.

For trees, BFS explores the entire neighborhood of the current node and then continues its execution recursively with the children of the current node one-by-one, while DFS follows one path for as long as possible and backtracks when stuck. DFS is equivalent to a pre-order traversal of the tree, that is, the root is visited first and then recursively the subtrees from left to right. Figure 1 illustrates the orders in which BFS and DFS will explore the nodes of a particular tree, if the initial node is the root.

Figure 1: The \mathop{\mathrm{bfsScore}} and \mathop{\mathrm{dfsScore}} of each node in a tree with 9 edges.

Let us call the label received by a node \(v\), when doing the traversals, the bfsScore and the dfsScore of \(v\), respectively. We define them formally as follows: \[\begin{align} \mathop{\mathrm{bfsScore}}(v) &\mathrel{\vcenter{:}}= \text{the number of nodes visited before v when using BFS}. \\ \mathop{\mathrm{dfsScore}}(v) &\mathrel{\vcenter{:}}= \text{the number of nodes visited before v when using DFS}. \end{align}\] It is important to note that \(\mathop{\mathrm{bfsScore}}(v)\) and \(\mathop{\mathrm{dfsScore}}(v)\) also give the number of steps taken in searching for \(v\) when one starts at the root and uses BFS and DFS, respectively. Thus, these two quantities measure the time complexity of the two algorithms when the target is \(v\).

Our goal will be to compare the average time complexity of BFS and DFS—i.e., the average \(\mathop{\mathrm{bfsScore}}\) and the average \(\mathop{\mathrm{dfsScore}}\)—under a minimal set of assumptions for the search. In particular, consider a search from the root of some tree \(T\in \mathcal{T}_{n}\) to a specific target node \(x\) in \(T\), by using BFS or DFS. We assume that we have a function telling us whether the current node is the target \(x\), but we do not know the number of children of the current node or anything else about it. If the target \(x\) is chosen uniformly at random among all the nodes in the trees in \(\mathcal{T}_{n}\), then it is readily seen that the expected number of steps needed to reach \(x\) is the same for both BFS and DFS, namely \[\frac{|\mathcal{T}_{n}|\sum_{i=1}^{n}i}{n|\mathcal{T}_{n}|} = \frac{1}{n}\frac{n(n+1)}{2} = \frac{n+1}{2}.\] Would this change if the level of the target node is fixed? We compare the expected number of steps of the two algorithms, if \(x\) is selected uniformly at random from all nodes at a fixed level \(\ell\) among the trees in \(\mathcal{T}_{n}\)? For instance, when \(n=3\) and \(\ell=2\), we have \(5\) such nodes as seen in Figure 2. Note that under this setting, the chance for \(T\) to be each of the trees in \(\mathcal{T}_{n}\) is not the same, but it is proportional to the number of nodes at level \(\ell\).

Figure 2: The target node is selected uniformly at random among the five circled nodes at level \ell=2, when we have n=3 edges.

Intuition suggests that BFS is a better choice if \(\ell\) is relatively small, while DFS should be preferred when \(\ell\) is large. What is the exact place where DFS becomes faster, and is this place unique? To answer this question, we need to compute and compare the two expectations given below, where \(\mathop{\mathrm{lev}}(T,\ell)\) denotes the set of nodes at level \(\ell\) in the tree \(T\): \[\mathop{\mathbb{E}}_{\substack{x\in \mathop{\mathrm{lev}}(T,\ell) \\T\in \mathcal{T}_{n}}}(\mathop{\mathrm{bfsScore}}(x)) \quad\text{and}\quad \mathop{\mathbb{E}}_{\substack{x\in \mathop{\mathrm{lev}}(T,\ell) \\T\in \mathcal{T}_{n}}}(\mathop{\mathrm{dfsScore}}(x)).\] Each of the two expectations is a fraction with denominator equal to the total number of nodes at level \(\ell\) among the trees in \(\mathcal{T}_{n}\). A result of Dershowitz and Zaks gives us this denominator.

Theorem 1 (Dershowitz–Zaks [7]). The total number of nodes at level \(\ell\) among trees in \(\mathcal{T}_{n}\) is equal to \[\label{eq:N} \frac{2\ell +1}{2n+1}\binom{2n+1}{n-\ell }.\tag{1}\]

Therefore, comparing the average time complexity of BFS and DFS is equivalent to comparing the two sums defined below: \[\mathop{\mathrm{totalB}}(n,\ell ) \mathrel{\vcenter{:}}=\sum_{T\in{\mathcal{T}}_{n}} \sum\limits_{v\in \mathop{\mathrm{lev}}(T,\ell )} \mathop{\mathrm{bfsScore}}(v) \quad \text{and} \quad \mathop{\mathrm{totalD}}(n,\ell ) \mathrel{\vcenter{:}}=\sum_{T\in{\mathcal{T}}_{n}} \sum\limits_{v\in \mathop{\mathrm{lev}}(T,\ell )} \mathop{\mathrm{dfsScore}}(v).\] The main result of this paper is the following theorem.

Theorem 2. For each \(n\geq 1\), there is a threshold \(\lambda_n\) such that \(\mathop{\mathrm{totalB}}(n,\ell ) \leq \mathop{\mathrm{totalD}}(n,\ell )\) if and only if \(\ell \leq \lambda_n\). Moreover, as \(n \to \infty\), we have \[\lambda_n \sim \lambda\sqrt{n}\] where \(\lambda \approx 0.789004\) is the unique positive root of the equation \[xe^{-x^2} - 2\sqrt{\pi}\mathopen{}\mathclose{\left(\Phi\mathopen{}\mathclose{\left(2x\sqrt{2} }\right)- \Phi\mathopen{}\mathclose{\left(x\sqrt{2} }\right) }\right) = 0\] and \(\Phi\) is the cumulative distribution function of the standard normal distribution.

Therefore, BFS is asymptotically faster than DFS if and only if \(\ell\leq \lambda\sqrt{n}\), for the given constant \(\lambda\). We also give explicit formulas for \(\mathop{\mathrm{totalB}}(n,\ell )\) and \(\mathop{\mathrm{totalD}}(n,\ell )\), and thus for the average time complexities of BFS and DFS in the considered settings.

1.2 Related works↩︎

The average performance of search algorithms over different families of graphs is a direction in which not many exact results are known. An article of Everitt and Hutter [8] contains the only study we found considering the average-case complexities of BFS and DFS on trees for a fixed target level. However, their results are about complete binary trees with given depth as opposed to ordered trees with arbitrary depth, as in our case. Furthermore, the way they sample the target nodes is different and the obtained expressions for the expected running times, in case of a single target node, are only approximations (see [8]). Another article by Stone and Sipala [9] investigates the average time complexity of two variations of DFS in binary trees.

If the number of the vertices in the tree is not known in advance, one can use the simple algorithm of Knuth [6] to obtain an unbiased estimator of this number, before using our results. Knuth’s method can be applied when having a tree in any given family of Galton–Watson trees. Some alternative methods for estimation of the size of the tree were suggested by Kilby et al. [10]. Two useful articles on algorithm selection for combinatorial search problems are the work of Rice [11] and the survey by Kotthoff [3].

Several other results exist on both BFS and DFS, and their variations. The average performance of the \(A^{*}\) algorithm (which reduces to BFS if no heuristic information is available) is studied in [12], when searching in graphs. A recent article by Jacquet and Janson [13] gives asymptotic results concerning several statistics when DFS begins at a random node of a random directed graph with certain distribution of the outdegrees for its vertices. In addition, DFS has been used to obtain some classical results in enumerative combinatorics [14], [15].

1.3 Outline of the paper↩︎

The organization of our paper is as follows:

  • In Section 2, we find a simple exact formula for \(\mathop{\mathrm{totalD}}(n,\ell )\). Our proof for this formula utilizes a classical bijection between ordered trees and Dyck paths; this allows us to translate the problem to establishing an identity, for which we give a combinatorial proof by interpreting both sides as counting certain lattice paths.

  • In Section 3, we obtain a summation formula for \(\mathop{\mathrm{totalB}}(n,\ell )\) via results of Takács [4] used to study the occupation measure of Brownian excursions. In addition, we find the asymptotic behavior of \(\mathop{\mathrm{totalB}}(n,\ell )\) depending on \(\ell\).

  • Section 4 is devoted to the proof of our main result—Theorem 2—which establishes a unique threshold for which BFS becomes asymptotically faster than DFS. In Section 4.1, we show that when \(n^{1/3}\prec\ell\prec\sqrt n\), then BFS can be arbitrarily faster than DFS, while if \(\sqrt{n}\prec \ell \prec \sqrt{n\ln{n}}\), then DFS can be at most twice as fast. Here and throughout the paper, \(f(x) \prec g(x)\) means \(f(x) = o(g(x))\).

  • In Section 5, we find a different formula for \(\mathop{\mathrm{totalB}}(n,\ell )\) by using generating function techniques. This approach reveals a curious identity expressing the generating function for \(\mathop{\mathrm{totalB}}(n,\ell )\) in terms of the Catalan generating function and Fibonacci polynomials; see Theorem 9 (b). We then derive an alternative formula for \(\mathop{\mathrm{totalB}}(n,\ell )\) by extracting coefficients from the generating function formula we found; see Theorem 14. Along the way—in Section 5.1—we give several identities related to Fibonacci polynomials needed for proving Theorem 9.

  • Section 6 establishes an expression for the asymptotic value of \(\mathop{\mathrm{totalB}}(n,\ell)\), for any given \(\ell\), when we have an arbitrary Galton–Watson tree; see Equation 35 .

  • In Section 7, we introduce a new algorithm called truncated DFS, which is faster in expectation than both BFS or DFS when we know the level \(\ell\) in advance. We show that this algorithm is twice as fast as BFS, when \(\ell = s\sqrt{n}\), for any constant \(s\).

  • We conclude in Section 8 by presenting several questions for future study.

2 Exact formula for the average time complexity of DFS↩︎

In this section, we establish a surprisingly simple formula for \(\mathop{\mathrm{totalD}}(n,\ell )\) by using a classical correspondence between ordered trees and lattice paths. When we refer to a lattice path from \((a,b)\) to \((c,d)\), we will mean a path in \(\mathbb{Z}^{2}\) starting at \((a,b)\), ending at \((c,d)\), and consisting of a sequence of steps from a prescribed step set \(S\). We will work with two kinds of lattice paths, defined as follows:

  • A diagonal path is a lattice path with step set \(S = \{(0,1), (1,0)\}\), with \((0,1)\) and \((1,0)\) called \(N\) and \(E\) steps, respectively (from North and East).

  • A horizontal path is a lattice path with step set \(S = \{(1,1), (1,-1)\}\), with \((1,1)\) and \((1,-1)\) called \(U\) and \(D\) steps, respectively (from Up and Down).

A Dyck path of semilength \(n\) is a diagonal path from \((0,0)\) to \((n,n)\) that stays weakly above the diagonal \(y=x\). Note that a simple bijection between horizontal and diagonal paths is to send a horizontal \(U\) (respectively \(D\)) step to a diagonal \(N\) (respectively \(E\)) step. Note also that the set of Dyck paths maps to the set of horizontal paths from \((0,0)\) to \((2n,0)\), staying weakly above \(y=0\).

Given \(a\leq b\) and \(c \leq d\), let \([(a,b)\rightarrow(c,d)]\) denotes the number of diagonal paths from \((a,b)\) to \((c,d)\) that stay weakly above the diagonal \(y=x\). We shall need the following well-known fact from lattice path enumeration.

Lemma 1 ([16]). For every \(j\geq i\), the number of diagonal paths from \((0,0)\) to \((i,j)\) that stay weakly above \(y=x\) is given by \[[(0,0)\rightarrow(i,j)] = \frac{j+1-i}{j+i+1}\binom{j+i+1}{i}.\]

For example, when \(i=n\) and \(j=n\), we get that the number of Dyck paths of semilength \(n\) is \[[(0,0)\rightarrow(n,n)] = \frac{1}{2n+1}\binom{2n+1}{n} = \frac{1}{n+1}\binom{2n}{n} = C_n,\] the \(n\)th Catalan number.

Below is our main result of this section.

Theorem 3. For every \(n\geq 0\) and \(0 \leq \ell \leq n\), we have \[\label{eq:totalD} \mathop{\mathrm{totalD}}(n,\ell ) = \ell\binom{2n}{n-\ell }.\tag{2}\]

Proof. We will use a folklore bijection between ordered trees and Dyck paths, known in the literature as the glove or the accordion bijection [17]. Execute a pre-order traversal for an ordered tree (i.e., run DFS without a target). During this process, write a \(N\) step whenever we go further away from the root, and an \(E\) step every time we go closer to the root. Whenever we are at a given node \(v\) on level \(\ell\) in an ordered tree, we will be on the line \(y=x+\ell\) in the corresponding Dyck path since we have \(\ell\) more \(N\) steps than \(E\) steps and thus \(v\) has coordinates \((i,i+\ell )\) for some \(i\geq 0\). It is readily seen that \(\mathop{\mathrm{dfsScore}}(v)\) is equal to the number of \(N\) steps in the prefix of the corresponding Dyck path that ends at the first point on the line \(y=x+\ell\) corresponding to \(v\). Note that the last step in this prefix is always an \(N\) and the last step in all other prefixes ending at points corresponding to \(v\) is an \(E\) since we go to \(v\) from a node at level \(\ell+1\), when we visit it for the second time or more.

It follows that the contribution of a given tree \(T\) to \(\mathop{\mathrm{totalD}}(n,\ell )\) is the sum of the number of \(N\) steps in all prefixes \(p\) of the Dyck path corresponding to \(T\), such that \(p\) ends with an \(N\) step at the line \(y=x+\ell\). Therefore, it suffices to count pairs \((\mu,\nu)\) of diagonal paths—both staying weakly above the diagonal \(y=x\)—such that \(\mu\) begins at \((0,0)\) and ends with an \(N\) step at \(y=x+\ell\), \(\nu\) begins at the endpoint of \(\mu\) and ends at the point \((n,n)\), and the pair \((\mu,\nu)\) is weighted by the number of \(N\) steps in \(\mu\) (see Figure 3 below).

Figure 3: A Dyck path that is an image of an ordered tree under the folklore bijection. The \mathop{\mathrm{dfsScore}} of the tree node corresponding to the point marked with a cross is equal to the number of N steps in the prefix of the path ending at that point.

If \(\mu\) has \(j\) \(N\) steps and \(i\) \(E\) steps, then its endpoint is \((i,j)\) and \(j = i + \ell\). Hence \(j \geq \ell\) and we have \[\begin{align} \mathop{\mathrm{totalD}}(n,\ell ) &= \sum\limits_{j = l}^{n} j\cdot[(0,0)\rightarrow(i,j-1)]\cdot[(i,j)\rightarrow(n,n)] \\ &= \sum\limits_{j = \ell }^{n} j\cdot[(0,0)\rightarrow(j-\ell ,j-1)]\cdot[(j-\ell ,j)\rightarrow(n,n)]. \end{align}\] By symmetry and Lemma 1, we have \[\begin{align} \mathop{\mathrm{totalD}}(n,\ell ) &= \sum\limits_{j = \ell }^{n} j\cdot[(0,0)\rightarrow(j-\ell ,j-1)]\cdot[(0,0)\rightarrow(n-j,n-j+\ell )] \\ &= \sum\limits_{j = \ell }^{n} \frac{j\ell }{2j-\ell } \binom{2j-\ell }{j} \frac{\ell + 1}{2n-2j+\ell +1} \binom{2n-2j+\ell +1}{n-j} \\ &= \ell \sum\limits_{j = \ell }^{n} \frac{\ell +1}{2n-2j+\ell +1} \binom{2j-\ell -1}{j-1}\binom{2n-2j+\ell +1}{n-j}. \end{align}\] It remains to prove that \[\label{eq:paths} \sum\limits_{j = \ell }^{n} \frac{\ell +1}{2n-2j+ \ell +1} \binom{2j- \ell -1}{j-1}\binom{2n-2j+\ell +1}{n-j} = \binom{2n}{n- \ell }.\tag{3}\] The last follows from Gould’s generalized Vandermonde convolution [18], with the substitution \(N=n-\ell\), \(k=n-j\), \(\alpha=\ell-1\), \(\gamma=\ell+1\), and \(\beta=2\).

However, we provide also a combinatorial proof by showing that both sides of 3 count horizontal paths from \((0,0)\) to \((2n,2)\), i.e., those with \(n+1\) \(U\)s and \(n-1\) \(D\)s crossing the horizontal line \(y=\ell\).

Let \(P\) be such a path. We decompose \(P\) as \(P = P'P''\), where \(P'\) ends at the first point at which \(P\) reaches \(y=\ell +1\), and where \(P''\) is the remaining path (see Figure 4 below). Note that the number of \(D\) steps of \(P''\) can be from \(\ell-1\) to \(n-1\). If \(P''\) has \(j-1\) \(D\) steps, then it must have \((j-1)-(\ell -1)\) \(U\) steps, and \(P''\) can be any path of this kind. Thus, there are \(\binom{2(j-1)-(\ell -1)}{j-1} = \binom{2j-\ell -1}{j-1}\) possibilities for \(P''\).

As for \(P'\), first observe that since we have \(2n\) steps in \(P\) and \(2j-\ell -1\) steps in \(P''\), there are \(2n-2j+\ell +1\) steps in \(P'\). In particular, there are \(n-j\) \(D\) steps in \(P'\), as we have \(n-1\) \(D\) steps in \(P\) and \(j-1\) such steps in \(P''\). There are \(\binom{2n-2j+\ell +1}{n-j}\) paths with \(n-j\) \(D\) steps and \(2n-2j+\ell +1\) steps in total, but we only want to count those that do not cross \(y=\ell\). Lemma 1 essentially gives what we want, although we need to translate our situation to the setting of diagonal paths.

Upon excluding the last step in \(P'\) (which must be an \(U\) step ending at \(y=\ell +1\)), we must count the horizontal paths starting at \((0,0)\) that consist of \(n-j\) \(D\) steps, \(n-j+\ell\) \(U\) steps, and which do not cross \(y=\ell\). Mapping any such horizontal path to a diagonal path via the canonical bijection gives a diagonal path with the same number of \(N\) and \(E\) steps and which stays weakly above \(y=x\). By Lemma 1, the number of these paths is exactly \(\binom{2n-2j+\ell +1}{n-j}\frac{\ell +1}{2n-2j+\ell +1}\), so this counts the possibilities for \(P'\). Therefore, the left-hand side of 3 counts the paths \(P\) satisfying the prescribed conditions.

Figure 4: The decomposition P=P'P'' of the paths crossing y=\ell counted by the two sides of Equation 3 .

On the other hand, we can use the reflection principle [19] to show that the number of horizontal paths from \((0,0)\) to \((2n,2)\) that cross \(y=\ell\) is exactly \(\binom{2n}{n-\ell }\). Taking the same decomposition \(P=P'P''\), the reflection of \(P'\) about \(y=\ell +1\) together with \(P''\) gives us a horizontal path starting at \((0,2\ell +2)\) and ending at \((2n,2)\). Each of these paths have \(n+\ell\) \(D\) steps and \(n-\ell\) \(U\) steps. The described map is surjective since every horizontal path from \((0,2\ell +2)\) to \((2n,2)\) crosses \(y=\ell +1\). Given such a path, we can take the first point where it intersects \(y=\ell +1\) and reflect the prefix ending there, yielding a horizontal path from \((0,0)\) to \((2n,2)\) that crosses \(y=\ell\). ◻

Using Theorems 1 and 3, we can now obtain the expected \(\mathop{\mathrm{dfsScore}}\) over all nodes at a given level \(\ell\) among the trees in \(\mathcal{T}_{n}\): \[\mathop{\mathbb{E}}_{\substack{x\in \mathop{\mathrm{lev}}(T,\ell ) \\T\in \mathcal{T}_{n}}}(\mathop{\mathrm{dfsScore}}(x)) = \frac{\ell\binom{2n}{n-\ell }}{\frac{2\ell +1}{2n+1}\binom{2n+1}{n-\ell }} = \frac{\ell }{2\ell +1}(n+\ell +1).\] When \(\ell \to \infty\) and \(n \to \infty\), with \(l\prec n\), this expectation is approximately \(n/2\).

3 Exact formula for the average time complexity of BFS↩︎

In this section, we give an exact summation formula for \(\mathop{\mathrm{totalB}}(n,\ell )\). To begin, let us define some random variables on the trees in \(\mathcal{T}_{n}\): \[\label{def:Random32variables} \begin{align} h_n(\ell ) &\mathrel{\vcenter{:}}= \text{total number of vertices at level \ell},\\ H_n(\ell ) &\mathrel{\vcenter{:}}= \text{total number of vertices at levels \leq \ell },\\ \nu_n(\ell ) &\mathrel{\vcenter{:}}= \text{total number of vertices at levels \geq \ell },\\ S_n(\ell ) &\mathrel{\vcenter{:}}= \text{sum of bfsScores on level \ell}. \end{align}\tag{4}\] For a sample realization of these random variables, see Figure 5.

Figure 5: Sample realization of the random variables defined in 4 .

We can express \(\mathop{\mathrm{totalB}}(n,\ell )\) in terms of these quantities in the following way: \[\begin{align} \mathop{\mathrm{totalB}}(n,\ell ) = \mathopen{}\mathclose{\left|\mathcal{T}_n}\right|\cdot \mathbb{E}\mathopen{}\mathclose{\left[S_n(\ell )}\right] &= C_n \cdot \mathbb{E}\mathopen{}\mathclose{\left[\binom{H_n(\ell )}{2}-\binom{H_n(\ell -1)}{2}}\right] \nonumber\\ &= C_n \cdot \mathbb{E}\mathopen{}\mathclose{\left[\binom{n+1-v_n(\ell +1)}{2}-\binom{n+1- v_n(\ell )}{2}}\right] \nonumber\\ &=C_n\cdot\mathbb{E}\mathopen{}\mathclose{\left[\binom{v_n(\ell +1)}{2} - \binom{v_n(\ell )}{2} - n\mathopen{}\mathclose{\left(v_n(\ell +1) - v_n(\ell ) }\right)}\right]. \label{eq:totB32expectation} \end{align}\tag{5}\] Moreover, in what follows, we shall use the following results of Takács [4]: \[\begin{align} C_n \cdot \mathbb{E}\mathopen{}\mathclose{\left[v_n(\ell )}\right] &= \binom{2n}{n-\ell }, \quad \text{and} \tag{6}\\ C_n\cdot \mathbb{E}\mathopen{}\mathclose{\left[\binom{v_n(\ell )}{2}}\right] &= (n+\ell )\binom{2n}{n-\ell } - \frac{n+2\ell }{2} \binom{2n}{n-2\ell }- 2 \ell\sum_{j=\ell }^{2\ell -1}\binom{2n}{n-j}. \tag{7} \end{align}\] The motivation of Takács was to find explicit expressions for the moments of the occupation measure of a Brownian excursion as a limit of the respective moments for simple Bernoulli excursions. Using our notation, the occupation measure of the Bernoulli excursion is exactly \(v_n(\ell )\), and the Brownian excursion is the natural encoding of the limit of properly scaled random trees from \(\mathcal{T}_n\)—that is, the continuum random tree introduced by Aldous in [20][22]. In fact, this link allow us to generalize our asymptotics for \(\mathop{\mathrm{totalB}}(n,\ell )\) on \(\mathcal{T}_n\) to all classes of trees which can be constructed as conditioned Galton–Watson trees (see Section 6).

A formula for \(\mathop{\mathrm{totalB}}(n,\ell )\) is obtained below. In the statement of this result, \(\Phi\) denotes the cumulative distribution function of the standard normal distribution: \[\Phi(s) \mathrel{\vcenter{:}}= \frac{1}{\sqrt{2\pi}}\int_{-\infty}^s e^{-x^2/2}\, \mathrm{d}x.\] As noted in Section 1.3, we use the notation \(a_n\prec b_n\) to mean that \(a_n=o(b_n)\), that is, \(a_n/b_n\to 0\) as \(n\to\infty\). Similarly, \(a_n\succ b_n\) means that \(a_n=\omega(a_n)\).

Theorem 4. For every \(n \geq 0\) and \(0 \leq \ell \leq n\), we have \[\begin{align} \label{eq:totalBExpr} \mathop{\mathrm{totalB}}(n,\ell ) &= \frac{n(2\ell +1)}{n+\ell +1}\binom{2n}{n-\ell } - \binom{2n}{n-2\ell-1} - 2 \sum_{j = \ell + 1}^{2\ell } \binom{2n}{n-j}\\ &= \mathop{\mathrm{totalD}}(n,\ell ) + \mathop{\mathrm{totalD}}(n,\ell+1 ) - \binom{2n}{n-2\ell -1} - 2 \sum_{j = \ell +1}^{2\ell } \binom{2n}{n-j}. \nonumber \end{align}\tag{8}\] Moreover, if \(s=\ell /\sqrt{n}\), we have \[\label{eq:asymptotics32totalB} \frac{\mathop{\mathrm{totalB}}(n,s\sqrt{n})}{4^n} = \frac{2s}{\sqrt{\pi}}e^{-s^2}-2\mathopen{}\mathclose{\left(\Phi\mathopen{}\mathclose{\left(2\sqrt{2}s }\right)-\Phi\mathopen{}\mathclose{\left(\sqrt{2}s }\right) }\right)+\mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{\sqrt{n}} }\right),\tag{9}\] and if \(s \succ n^\epsilon\) for some \(\epsilon > 0\), we have \[\label{eq:exp32bound} \frac{\mathop{\mathrm{totalB}}(n,s\sqrt{n})}{4^n} \leq 2s\sqrt{n}e^{-n^{2\epsilon}} = \mathrm{o}\mathopen{}\mathclose{\left(e^{-n^\epsilon} }\right).\tag{10}\]

Remark 5. The last result shows that the levels with non-negligible \(\mathop{\mathrm{totalB}}\) (with respect to the sum of all scores) are exactly those of order \(s\sqrt{n}\) for a constant \(s\), in the sense that \[\text{if s \prec 1 or s \succ 1, then } \frac{\mathop{\mathrm{totalB}}(n,s\sqrt{n})}{4^n} = \mathrm{o}\mathopen{}\mathclose{\left(1 }\right).\] More precisely, using 9 for \(s\prec n^\epsilon\) and 10 for \(s\succ n^\epsilon\), we have that \[\frac{\mathop{\mathrm{totalB}}(n,s\sqrt{n})}{4^n} = \begin{cases} \mathrm{O}\mathopen{}\mathclose{\left(\max\{s,n^{-1/2}\} }\right), &\text{if s \prec 1},\\ \mathrm{O}\mathopen{}\mathclose{\left(\max\{se^{-s^2},n^{-1/2}\} }\right), &\text{if 1 \prec s \prec n^\epsilon},\\ \mathrm{o}\mathopen{}\mathclose{\left(e^{-n^\epsilon} }\right), &\text{if s \succ n^\epsilon}. \end{cases}\]

Proof of Theorem 4. Substituting 6 and 7 into 5 , we get

\[\begin{align} \label{eq:totalB32calc} \mathop{\mathrm{totalB}}(n,\ell ) &= (n+\ell +1)\binom{2n}{n-\ell -1} - (n+\ell )\binom{2n}{n-\ell } -\frac{n+2\ell +2}{2}\binom{2n}{n-2\ell -2}+\frac{n+2\ell }{2}\binom{2n}{n-2\ell } \nonumber\\ &\hphantom{{}= (n} -2(\ell +1)\sum_{j=\ell +1}^{2\ell +1} \binom{2n}{n-j}+ 2\ell \sum_{j=\ell }^{2\ell -1} \binom{2n}{n-j}- n\mathopen{}\mathclose{\left(\binom{2n}{n-\ell -1} - \binom{2n}{n-\ell } }\right) \nonumber\\ &= \mathopen{}\mathclose{\left(\ell +1 }\right)\binom{2n}{n-\ell -1} + l\binom{2n}{n-\ell } \nonumber\\ &\hphantom{{}= (n}+ \binom{2n}{n-2\ell -1}\mathopen{}\mathclose{\left(-\frac{n-2\ell -1}{2} + \frac{n+2\ell +1}{2} -2\ell -2 }\right) -2 \sum_{j=\ell +1}^{2\ell}\binom{2n}{n-j} \nonumber \\ &= \frac{n(2\ell +1)}{n+\ell +1}\binom{2n}{n-\ell } - \binom{2n}{n-2\ell -1} -2 \sum_{j=\ell +1}^{2\ell }\binom{2n}{n-j} \end{align}\tag{11}\]

as needed. The fact that the first term in the last expression is equal to \(\mathop{\mathrm{totalD}}(n,\ell ) + \mathop{\mathrm{totalD}}(n,\ell +1)\) can be seen from the second equality above and Theorem 3.

For the remaining asymptotic statements, we will use two additional facts giving us asymptotic bounds for \(\binom{2n}{n-\ell }\) and \(\sum_{j=\ell +1}^{2\ell }\binom{2n}{n-j}\), respectively. The first fact is a variant of the local limit theorem [23], which states that for a binomial random variable \(\mathcal{B}_{2n} \sim \operatorname{Bin}(2n, 1/2)\), we have \[\sup_{\ell }\,\mathopen{}\mathclose{\left|\mathbb{P}\mathopen{}\mathclose{\left(\mathcal{B}_{2n} = n-\ell }\right) - \frac{1}{\sqrt{\pi n}}e^{-\ell^2/n} }\right|\leq \frac{c_0}{n^{3/2}}\] for some constant \(c_0 > 0\); this implies \[\label{eq:local32limit} \binom{2n}{n-\ell } = 4^n \mathopen{}\mathclose{\left(\frac{1}{\sqrt{\pi n}}e^{-\ell^2/n} + \mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{n^{3/2}} }\right) }\right) = 4^n\mathopen{}\mathclose{\left(\mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{\sqrt{n}} }\right) }\right).\tag{12}\] The second fact is the standard central limit theorem, which along with the Berry–Essen bound (see [24]), implies that \[\label{eq:Berry-Essen} \sup_{x}\,\mathopen{}\mathclose{\left| \mathbb{P}\mathopen{}\mathclose{\left(\frac{\mathcal{B}_{2n}-n}{\sqrt{n/2}} \leq x }\right) - \Phi\mathopen{}\mathclose{\left(x }\right)}\right| = \sup_{x}\, \mathopen{}\mathclose{\left| \mathbb{P}\mathopen{}\mathclose{\left(\mathcal{B}_{2n} \leq x }\right) - \Phi\mathopen{}\mathclose{\left(\frac{x-n}{\sqrt{n/2}} }\right)}\right| \leq \frac{1}{\sqrt{2n}}.\tag{13}\] Therefore, using \(s = \ell/\sqrt{n}\), we have \[\begin{align} \mkern-48mu \sum_{j=\ell +1}^{2\ell }\binom{2n}{n-j} = 4^n \mathbb{P}\mathopen{}\mathclose{\left(n+\ell +1 \leq \mathcal{B}_{2n} \leq n+2\ell }\right) = 4^n\mathopen{}\mathclose{\left(\Phi\mathopen{}\mathclose{\left(2\sqrt{2}s }\right)-\Phi\mathopen{}\mathclose{\left(\sqrt{2}s }\right)+\mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{\sqrt{n}} }\right) }\right). \label{e-2nnj} \end{align}\tag{14}\] Substituting 12 and 14 into 11 , we obtain \[\label{eq:expand32totalB} \begin{align} \frac{1}{4^n}\mathop{\mathrm{totalB}}(n,s\sqrt{n}) &= \frac{2s\sqrt{n}+1}{1+(s\sqrt{n}+1)/n}\mathopen{}\mathclose{\left(\frac{1}{\sqrt{\pi n}}e^{-s^2} + \mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{n^{3/2}} }\right) }\right) \\ & \hphantom{{}= \frac{2s\sqrt{n}+1}{1+(s\sqrt{n}+1)/n}\frac{2s\sqrt{n}+1}{1}} -2\mathopen{}\mathclose{\left(\Phi\mathopen{}\mathclose{\left(2\sqrt{2}s }\right)-\Phi\mathopen{}\mathclose{\left(\sqrt{2}s }\right) }\right)+\mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{\sqrt{n}} }\right). \end{align}\tag{15}\] In fact, 15 holds for every \(s\) that is a function of \(n\). To further expand, we first note that if \(\ell \succ n^{1/2+\epsilon}\) for some \(\epsilon>0\), or equivalently if \(s \succ n^\epsilon\), then \(\mathop{\mathrm{totalB}}(n,\ell )\) is very small. Indeed, we can get the following inequalities: \[\label{eq:totalB32in32proof} \frac{1}{4^n}\mathop{\mathrm{totalB}}(n,\ell ) \leq \frac{n(2\ell +1)}{n+\ell +1} \frac{1}{4^n}\binom{2n}{n-\ell } \leq n\mathbb{P}\mathopen{}\mathclose{\left(\mathcal{B}_{2n} \geq n +\ell }\right) \leq ne^{-\ell^2/n} \leq n e^{-n^{2\epsilon}} = \mathrm{o}\mathopen{}\mathclose{\left(e^{-n^\epsilon} }\right).\tag{16}\] For the first inequality, we upper-bounded \(\mathop{\mathrm{totalB}}(n,\ell )\) by the first term of the expression obtained in 11 , since it is the only positive term. For the second inequality, we use \[\frac{1}{4^{n}}\binom{2n}{n-\ell } = \mathbb{P}\mathopen{}\mathclose{\left(\mathcal{B}_{2n} = n +\ell }\right)\leq \mathbb{P}\mathopen{}\mathclose{\left(\mathcal{B}_{2n} \geq n +\ell }\right).\] Finally, the third inequality follows from Hoeffding’s inequality [25], and thus we have established 10 . Further, using the Taylor expansion \(1/(1+x) = 1 + \mathrm{O}\mathopen{}\mathclose{\left(x }\right)\) in 15 , we obtain \[\begin{align} \frac{1}{4^n}\mathop{\mathrm{totalB}}(n,s\sqrt{n}) &= \mathopen{}\mathclose{\left(2s\sqrt{n} + 1 }\right)\mathopen{}\mathclose{\left(1+\mathrm{O}\mathopen{}\mathclose{\left(\frac{s}{\sqrt{n}} }\right) + \mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{n} }\right) }\right)\mathopen{}\mathclose{\left(\frac{1}{\sqrt{\pi n}}e^{-s^2} + \mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{n^{3/2}} }\right) }\right) \\ & \hphantom{{}= \frac{2s\sqrt{n}+1}{1+(s\sqrt{n}+1)/n}\frac{2s\sqrt{n}+1}{1}} -2\mathopen{}\mathclose{\left(\Phi\mathopen{}\mathclose{\left(2\sqrt{2}s }\right)-\Phi\mathopen{}\mathclose{\left(\sqrt{2}s }\right) }\right)+\mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{\sqrt{n}} }\right)\\ &= \frac{2se^{-s^2}}{\sqrt{\pi}}-2\mathopen{}\mathclose{\left(\Phi\mathopen{}\mathclose{\left(2\sqrt{2}s }\right)-\Phi\mathopen{}\mathclose{\left(\sqrt{2}s }\right) }\right) +\mathrm{O}\mathopen{}\mathclose{\left(\frac{1}{\sqrt{n}} }\right), \end{align}\] where after expanding the former equation, we use the inequality \(s \leq \sqrt{n}\) and the fact that \(se^{-s^2}\) and \(s^2e^{-s^2}\) are bounded functions of \(s\). ◻

4 Comparing the average time complexity of BFS and DFS.↩︎

Now, we are ready to prove the main result of this paper.

Proof of Theorem 2. Combining the results of Theorems 3 and 4, we have \[f_n(\ell ) \mathrel{\vcenter{:}}= \mathop{\mathrm{totalB}}(n,\ell ) - \mathop{\mathrm{totalD}}(n,\ell ) = (\ell +1)\binom{2n}{n-\ell -1} - \binom{2n}{n-2\ell -1} - 2 \sum_{j = \ell +1}^{2\ell } \binom{2n}{n-j}.\] Therefore, by Equation 9 and the Stirling approximation for \(\mathop{\mathrm{totalD}}(n,\ell )\), we have \[f_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)\sim \frac{4^n}{\sqrt{\pi}} \mathopen{}\mathclose{\left( s e^{-s^2} - 2\sqrt{\pi}\mathopen{}\mathclose{\left( \Phi\mathopen{}\mathclose{\left(2\sqrt{2}s}\right) - \Phi\mathopen{}\mathclose{\left(\sqrt{2}s }\right) }\right) }\right)\] when \(s\geq 0\) and \(n\to \infty\). It is readily verified that the function in the brackets has a single positive root, which establishes the second part of the theorem provided that the threshold is unique.

We note that it can be checked that if \(f_n(\ell ) = 0\) with some \(\ell \in (0, n)\), then if \(n\) is large enough, \(\ell\) should be of order \(\sqrt{n}\), and therefore we are in the scenario considered above. However, as we have observed that the threshold is unique for small values of \(n\) too, we prove that it exists for all \(n\).

Let \(n\geq 3\). First note that \(f_n(1)< 0=f_n(0)\) and \(f_n(n-1)>0=f_n(n)\). We will show that \(g_n(\ell ) \mathrel{\vcenter{:}}= f_n(\ell ) - f_n(\ell -1)\) changes sign two times, and because \(f_n\) is decreasing around \(0\) and \(n\), this would mean that \(f_n(\ell -1)\leq 0\) and \(f_n(\ell ) > 0\) for a unique \(\ell\in(0,n)\). A brief calculation shows that \[g_n(\ell ) =f_n(\ell ) - f_n(\ell -1) = \frac{-2\ell^2+3n+2}{n+\ell +1}\binom{2n}{n+\ell } - \binom{2n+2}{n+2\ell +1}.\] Denote the first term \(A(\ell )\) and the second \(B(\ell )\), where we skip the dependence on \(n\) for simpler notation. Since \(g_n\) is negative for \(2\ell^2\geq 3n+2\), let us consider \(\ell\) for which \(A(\ell )>0\). Moreover, consider only the non-trivial cases where \(B(\ell )>0\), i.e., \(2\ell < n\). This will be implied by the previous restriction when \(n \geq 7\). In these cases, observe that \[\mathop{\mathrm{sign}}\mathopen{}\mathclose{\left(g_n(\ell ) }\right) = \mathop{\mathrm{sign}}\mathopen{}\mathclose{\left(A(\ell )-B(\ell ) }\right) = \mathop{\mathrm{sign}}\mathopen{}\mathclose{\left(\frac{A(\ell )}{B(\ell )} - 1 }\right).\] Therefore, setting \(D(\ell ) \mathrel{\vcenter{:}}= A(\ell )/B(\ell )\), we have to solve \(D(\ell ) > 1\). We have that \[\frac{D(\ell +1)}{D(\ell )} = \frac{(-2(\ell +1)^2 + 3n + 2)(n+2\ell +2)(n+2\ell +3)(n-\ell )}{(-2\ell^2 + 3n + 2)(n+\ell +2)(n-2\ell )(n-2\ell +1)},\] so \(D(\ell +1)>D(\ell )\) if and only if \[\begin{gather} \quad h(\ell )\mathrel{\vcenter{:}}= n^3(14\ell +4) + n^2(-12\ell^3-16\ell^2+28\ell +6) \\ +n(-52\ell^3-76\ell^2-12\ell -4) +16\ell^5+48\ell^4+36\ell^3+12\ell^2 +8\ell > 0. \quad \end{gather}\] Differentiating, we obtain \[\begin{align} h'(\ell) &= 14n^3 + n^2(-36\ell^2\!-\!32\ell \!+\!28)+n(-156\ell^2\!-\!152\ell\!-\!12)+80\ell^4\!+\!192\ell^3\!+\!108\ell^2\!+\!24\ell\!+\!8,\\ h''(\ell ) &= n^2(-72\ell \!-\!32)+n(-312\ell \!-\!152)+320\ell^3\!+\!576\ell^2\!+\!216\ell \!+\!24\\ &= \ell (-72n^2\!-\!312n\!+\!320\ell^2\!+\!216)-32n^2\!-\!152n\!+\!576\ell^2\!+\!24\\ &<\ell \mathopen{}\mathclose{\left(-72n^2\!+\!168 n\!+\!536 }\right) -32n^2 \!+\! 712n \!+\! 600 < 0 \end{align}\] for \(n \geq 10\) and where we used \(2\ell^2 < 3n+2\). (The statement of the theorem, that is uniqueness of the threshold, for \(n < 10\) can be verified directly.) Therefore, \(h\) is strictly concave. A direct substitution shows that \(h(0) > 0\) and \(h(6\sqrt{n}/5) <0\), so \(D(\ell )\) initially increases, then decreases. As \(D(1) <1\), this means that \(g_n\) changes sign \(0\) or \(2\) times, but the former is impossible since \(\sum_k g_n(k) = 0\) and \(g_n(1)<0\). Thus our proof is complete. ◻

Theorem 2 gives us a unique threshold occurring at \(\lambda\sqrt{n}\), where \(\lambda\approx 0.789004\). It is natural to suspect that this threshold will be close to the average level of a node in \(\mathcal{T}_n\), when \(n\to\infty\). In order to make this comparison, we will use the following result of Flajolet and Sedgewick.

Theorem 6 ([26]). The average level of the nodes among all trees in \(\mathcal{T}_{n}\) is \(\frac{1}{2}\sqrt{\pi n} + \mathrm{O}\mathopen{}\mathclose{\left(1 }\right)\).

We have that \(\frac{1}{2}\sqrt{\pi}\approx 0.8862>0.789\approx\lambda\) and thus for ordered trees, the unique threshold occurs around the average level for the nodes in \(\mathcal{T}_{n}\), but slightly below it. In Section 8, we ask whether this is a general phenomenon that applies to other families of trees. For instance, is there a similar transition for binary trees around the average level for the nodes in them? We also ask for an explanation of the obtained small discrepancy in the case of ordered trees.

4.1 The BFS and DFS complexity ratio for certain intervals of target levels↩︎

We will also show that the ratios between the average complexities of BFS and DFS are the constants \(0\) and \(2\), in two large intervals for \(\ell\) around \(\ell = \sqrt{n}\).

First, observe that Theorem 3 and the local limit theorem (see Equation 12 ) imply that for any \(\ell = s\sqrt{n}\), \[\frac{\mathop{\mathrm{totalD}}(n,s\sqrt n)}{4^n}\longrightarrow g(s):=\frac{s}{\sqrt\pi}e^{-s^2}.\] In addition, recall that Equation 9 gives that for any \(\ell = s\sqrt{n}\), \[\frac{\mathop{\mathrm{totalB}}(n,s\sqrt n)}{4^n} \;\longrightarrow\; B(s) := \frac{2s}{\sqrt\pi}e^{-s^2} - 2\Delta(s) = 2(g(s)-\Delta(s)), \qquad n\to\infty, \label{eq:Bform}\tag{17}\] where \[\Delta(s) := \Phi(2\sqrt2\,s) - \Phi(\sqrt2\,s).\]

We then have \[\label{eq:BDratio} \frac{\mathop{\mathrm{totalB}}(n,s\sqrt n)}{\mathop{\mathrm{totalD}}(n,s\sqrt n)}\to \frac{B(s)}{g(s)} = 2\mathopen{}\mathclose{\left(1-\frac{\Delta(s)}{g(s)}}\right).\tag{18}\] To investigate this ratio at \(s\to 0\), we will need the expansion of \(\Phi\) near \(0\) to third order.

Lemma 2 (Taylor expansion of \(\Phi\) at \(0\)). As \(x\to0\), \[\Phi(x) = \frac{1}{2} + \frac{1}{\sqrt{2\pi}}\mathopen{}\mathclose{\left(x-\frac{x^3}{6}}\right) + O(x^5).\]

Proof. By definition \(\Phi(x)=\frac{1}{2}+\frac{1}{\sqrt{2\pi}}\int_0^x e^{-t^2/2}\,dt\). The MacLaurin series of the integrand is, \[e^{-t^2/2} = 1-\frac{t^2}{2}+\frac{t^4}{8}-O(t^6).\] Integrating term by term over \([0,x]\) gives us \[\int_0^x e^{-t^2/2}\,dt = x - \frac{x^3}{6} + \frac{x^5}{40} - O(x^7).\] Substituting in the definition of \(\Phi\) gives the claim. ◻

Apply Lemma 2 at \(x=2\sqrt2\,s\) and \(x=\sqrt2\,s\). Using \((2\sqrt2\,s)^3 = 8\cdot2\sqrt2\,s^3=16\sqrt2\,s^3\) and \((\sqrt2\,s)^3=2\sqrt2\,s^3\), \[\Phi(2\sqrt2\,s) = \frac{1}{2}+\frac{1}{\sqrt{2\pi}}\mathopen{}\mathclose{\left(2\sqrt2\,s-\frac{16\sqrt2}{6}s^3}\right)+O(s^5) = \frac{1}{2}+\frac{1}{\sqrt{2\pi}}\mathopen{}\mathclose{\left(2\sqrt2\,s-\frac{8\sqrt2}{3}s^3}\right)+O(s^5),\] \[\Phi(\sqrt2\,s) = \frac{1}{2}+\frac{1}{\sqrt{2\pi}}\mathopen{}\mathclose{\left(\sqrt2\,s-\frac{2\sqrt2}{6}s^3}\right)+O(s^5) = \frac{1}{2}+\frac{1}{\sqrt{2\pi}}\mathopen{}\mathclose{\left(\sqrt2\,s-\frac{\sqrt2}{3}s^3}\right)+O(s^5).\] After simplification, we obtain that when \(s\to0\), \[\Delta(s) = \Phi(2\sqrt2\,s)-\Phi(\sqrt2\,s) = \frac{1}{\sqrt{2\pi}}\mathopen{}\mathclose{\left(\sqrt2\,s-\frac{7\sqrt2}{3}s^3}\right)+O(s^5) = \frac{s}{\sqrt\pi} - \frac{7}{3\sqrt\pi}\,s^3 + O(s^5).\]

Meanwhile \[g(s)=\dfrac{s}{\sqrt\pi}e^{-s^2}=\dfrac{s}{\sqrt\pi}\bigl(1-s^2+O(s^4)\bigr)=\dfrac{s}{\sqrt\pi}-\dfrac{s^3}{\sqrt\pi}+O(s^5).\] Hence in \(B(s)=2g(s)-2\Delta(s)\) the linear terms cancel exactly, and only the cubic terms survive: \[B(s) = 2\mathopen{}\mathclose{\left(-\frac{s^3}{\sqrt\pi}}\right)-2\mathopen{}\mathclose{\left(-\frac{7}{3\sqrt\pi}s^3}\right)+O(s^5) = \mathopen{}\mathclose{\left(-2+\frac{14}{3}}\right)\frac{s^3}{\sqrt\pi}+O(s^5) = \frac{8}{3\sqrt\pi}\,s^3+O(s^5).\] Consequently, when \(s\to 0\), \[\frac{\mathop{\mathrm{totalB}}(n,s\sqrt n)}{\mathop{\mathrm{totalD}}(n,s\sqrt n)} \;\longrightarrow\;\frac{B(s)}{g(s)} \sim \frac{8}{3}s^2 \;\longrightarrow\;0. \label{eq:ratio0}\tag{19}\] In fact, this conclusion is not limited to a fixed constant \(s\), but extends to any sequence of target levels tending to \(0\) relative to \(\sqrt n\), at a suitable rate, as follows.

Theorem 7. Let \(\ell=\ell(n)\) be a sequence of target levels satisfying \(n^{1/3}\prec\ell(n)\prec\sqrt n\) (equivalently, \(s(n):=\ell(n)/\sqrt n\) satisfies \(n^{1/6}s(n)\to\infty\) and \(s(n)\to0\)). Then \[\frac{\mathrm{totalB}(n,\ell(n))}{\mathrm{totalD}(n,\ell(n))} \longrightarrow 0, \qquad n\to\infty.\]

Proof. Equation 9 holds for every \(s\) that is a function of \(n\) — its two ingredients, the local limit theorem and the BerryEsseen bound, are \(\sup_\ell\)- and \(\sup_x\)-bounds with a universal constant, not statements calibrated to one fixed \(s\). Hence, uniformly in \(\ell=o(n)\), \[\frac{\mathrm{totalB}(n,\ell)}{4^n} = B(s)+O(n^{-1/2}), \qquad \frac{\mathrm{totalD}(n,\ell)}{4^n} = g(s)+O(n^{-1/2}), \qquad s=\ell/\sqrt n,\] with implied constants independent of \(s\). Since \(s(n)\to0\), we have \(B(s)\sim\frac{8}{3\sqrt\pi}s^3\) near \(0\), so the \(O(n^{-1/2})\) error term above is dominated by \(B(s(n))\) precisely when \(s(n)^3\succ n^{-1/2}\), i.e.when \(n^{1/6}s(n)\to\infty\), equivalently \(\ell(n)\succ n^{1/3}\); and since \(g\succ B\) near \(0\), the same rate suffices for the error to be negligible relative to \(g(s(n))\) as well. Under the hypothesis \(n^{1/3}\prec\ell(n)\prec\sqrt n\), both error terms become relative \(o(1)\) corrections, and \[\frac{\mathrm{totalB}(n,\ell(n))}{\mathrm{totalD}(n,\ell(n))} = \frac{B(s(n))\bigl(1+o(1)\bigr)}{g(s(n))\mathopen{}\mathclose{\left(1+o(1)}\right)} \sim \frac{8}{3} s(n)^2 \longrightarrow 0. \qedhere\] ◻

When \(s\to\infty\), we will need the Lemma below which can be proven via integration by parts.

Lemma 3 (Mills’ ratio, [27]). For \(\varphi(x)=\frac{1}{\sqrt{2\pi}}e^{-x^2/2}\), as \(x\to\infty\), \[1-\Phi(x) = \frac{\varphi(x)}{x}\bigl(1+O(x^{-2})\bigr).\]

Write \(\Delta(s)\) as a difference of two upper tails, \[\Delta(s) = \Phi(2\sqrt2\,s)-\Phi(\sqrt2\,s) = \bigl[1-\Phi(\sqrt2\,s)\bigr] - \bigl[1-\Phi(2\sqrt2\,s)\bigr],\] and apply Lemma 3. Since \((\sqrt2\,s)^2/2 = s^2\), we have \(\varphi(\sqrt2\,s)=\frac{1}{\sqrt{2\pi}}e^{-s^2}\) and thus \[1-\Phi(\sqrt2\,s) = \frac{\varphi(\sqrt2\,s)}{\sqrt2\,s}\bigl(1+O(s^{-2})\bigr) = \frac{e^{-s^2}}{\sqrt{2\pi}\cdot\sqrt2\,s}\bigl(1+O(s^{-2})\bigr) = \frac{e^{-s^2}}{2\sqrt\pi\,s}\bigl(1+O(s^{-2})\bigr).\] For the second tail, since \((2\sqrt2\,s)^2/2=4s^2\), we have \(\varphi(2\sqrt2\,s)=\frac{1}{\sqrt{2\pi}}e^{-4s^2}\), so \[1-\Phi(2\sqrt2\,s) = \frac{\varphi(2\sqrt2\,s)}{2\sqrt2\,s}\bigl(1+O(s^{-2})\bigr) = \frac{e^{-4s^2}}{\sqrt{2\pi}\cdot2\sqrt2\,s}\bigl(1+O(s^{-2})\bigr) = \frac{e^{-4s^2}}{4\sqrt\pi\,s}\bigl(1+O(s^{-2})\bigr).\] The second tail is exponentially smaller than the first since when \(s\to\infty\) their ratio is \[\frac{e^{-4s^2}/(4\sqrt\pi\,s)}{e^{-s^2}/(2\sqrt\pi\,s)} = \frac{1}{2}\,e^{-3s^2} \longrightarrow 0\] Thus, after subtracting we obtain \[\Delta(s) = \frac{e^{-s^2}}{2\sqrt\pi\,s}\bigl(1+O(s^{-2})\bigr) - \frac{e^{-4s^2}}{4\sqrt\pi\,s}\bigl(1+O(s^{-2})\bigr) = \frac{e^{-s^2}}{2\sqrt\pi\,s}\bigl(1+O(s^{-2})\bigr).\] Therefore, \[\frac{\Delta(s)}{g(s)} = \frac{\dfrac{e^{-s^2}}{2\sqrt\pi\,s}\bigl(1+O(s^{-2})\bigr)}{\dfrac{s}{\sqrt\pi}e^{-s^2}} = \frac{1}{2\sqrt\pi\,s}\cdot\frac{\sqrt\pi}{s}\,\bigl(1+O(s^{-2})\bigr) = \frac{1}{2s^2}\bigl(1+O(s^{-2})\bigr) \;\longrightarrow\;0.\] In particular \(\Delta(s)=o(g(s))\). Hence, when \(s\to\infty\), by Equation 18 we have \[B(s) \sim 2g(s)\qquad\text{ and } \qquad \frac{\mathop{\mathrm{totalB}}(n,s\sqrt n)}{\mathop{\mathrm{totalD}}(n,s\sqrt n)} \;\longrightarrow\;2. \label{eq:ratioinf}\tag{20}\] As with the previous limit, this conclusion is not limited to a fixed \(s\), and extends as follows.

Theorem 8. Let \(\ell=\ell(n)\) be a sequence of target levels satisfying \(\sqrt n\prec\ell(n)\prec\sqrt{n\ln n}\) (equivalently, \(s(n):=\ell(n)/\sqrt n\) satisfies \(s(n)\to\infty\) and \(s(n)/\sqrt{\ln n}\to0\)). Then \[\frac{\mathrm{totalB}(n,\ell(n))}{\mathrm{totalD}(n,\ell(n))} \longrightarrow 2, \qquad n\to\infty.\]

Proof. By the same uniform form of Equation 9 used in the proof of Theorem 7, it suffices to check that \(g(s(n))\) dominates the \(O(n^{-1/2})\) error term, since \(B(s)\sim2g(s)\) and \(\Delta(s)=o(g(s))\) as \(s\to\infty\) by (22). Now \[g(s) = \frac{s}{\sqrt\pi}e^{-s^2} \succ n^{-1/2} \iff s^2 \prec \tfrac12\ln n + \ln s + O(1),\] and since \(\ln s(n) = o(\ln n)\), this holds whenever \(s(n)^2=o(\ln n)\), i.e.\(s(n)=o\bigl(\sqrt{\ln n}\bigr)\), equivalently \(\ell(n)=o\bigl(\sqrt{n\ln n}\bigr)\). Under this condition both \(\mathrm{totalB}(n,\ell)/4^n\) and \(\mathrm{totalD}(n,\ell)/4^n\) reduce to their leading terms \(B(s(n))\sim2g(s(n))\) and \(g(s(n))\), giving \[\frac{\mathrm{totalB}(n,\ell(n))}{\mathrm{totalD}(n,\ell(n))} \longrightarrow 2. \qedhere\] ◻

Together, Theorems 7 and 8 show that the ratio \(\mathrm{totalB}(n,\ell)/\mathrm{totalD}(n,\ell)\) already exhibits its limiting behavior \(0\), respectively \(2\), for every target level in certain large intervals. The exponents \(\tfrac13\) and \(\tfrac12\) in these two theorems are not claimed to be sharp. In fact, we suspect that the two theorems hold whenever \(\ell\prec \sqrt{n}\) and \(\ell\succ \sqrt{n}\), respectively. Yet, we were not able to show that. One reason for us to believe the mentioned extension is possible (at least for the latter interval) is Theorem 17, its possible extension mentioned in Remark 18, and the fact that the truncated DFS algorithm is almost identical to the DFS algorithm for large target levels \(\ell\).

5 The generating function for \(\mathop{\mathrm{totalB}}\) and Fibonacci polynomials↩︎

In this section, we obtain an expression for the generating function of \(\mathop{\mathrm{totalB}}(n,\ell )\), without using the results in the previous Section 3. Instead, we use a generating function approach which demonstrates a surprising connection between the generating function of \(\mathop{\mathrm{totalB}}(n,\ell )\) and Fibonacci polynomials. Furthermore, we leverage this connection to find a formula for \(\mathop{\mathrm{totalB}}(n,\ell )\) as a difference of two alternating sums, which is different from the one from Equation 8 . We begin by defining the generating functions \[F_{\ell }(x,y,z) \mathrel{\vcenter{:}}= \sum_{n=0}^{\infty} \sum\limits_{T\in \mathcal{T}_n} x^{k(T)}y^{m(T)}z^{n},\] where \(k(T)\) is the number of non-root nodes in \(T\) at levels smaller than \(\ell\) and \(m(T)\) is the number of nodes in \(T\) at level \(\ell\). Now, consider the ordinary generating function \[C=C(z)\mathrel{\vcenter{:}}= \sum_{n=0}^{\infty} C_n z^n = \frac{1-\sqrt{1-4z}}{2z} = \frac{2}{1+\sqrt{1-4z}}\] for the Catalan numbers \(C_n\). Since \(C_n\) counts ordered trees with \(n\) edges and every ordered tree has a single node (the root) at level 0, it follows that \[F_0 = yC = \frac{2y}{1+\sqrt{1-4z}}.\] Using one of the standard decompositions of ordered trees, which gives that the children of the root of every ordered tree are themselves roots of ordered trees, implies the equations \[\label{eq:F-1} F_{1} = 1 + zF_{0} + (zF_{0})^2 + \cdots = \frac{1}{1-zF_{0}} = \frac{1}{1-yzC}\tag{21}\] and \[\label{eq:F-l} F_{\ell } = 1 + xzF_{\ell -1} + (xzF_{\ell -1})^2 + \cdots = \frac{1}{1-xzF_{\ell -1}} \quad (\ell\geq 2).\tag{22}\] This recursive relation shows that \(F_\ell\) can be written as a continued fraction as, for example, in the work of de Bruijn, Knuth and Rice [28]. The formula for \(F_\ell\) that one can obtain via this approach, will be proven directly in Section 5.2. Then, since our goal is to find \(\mathop{\mathrm{totalB}}(n,\ell )\), we will use the obtained formula for \(F_\ell\) to find the generating function \[B_{\ell }=B_{\ell }(z)\mathrel{\vcenter{:}}=\sum_{n=0}^{\infty}\mathop{\mathrm{totalB}}(n,\ell )z^{n}.\] If \(m(T)=m\) and \(k(T)=k\), then a straightforward counting argument yields \[\sum\limits_{v\in \mathop{\mathrm{lev}}(T,\ell )} \mathop{\mathrm{bfsScore}}(v) = mk + \frac{m(m+1)}{2}.\] The latter equation gives us the following expression for \(B_\ell\) in terms of \(F_\ell\) and its derivatives. \[\label{e-BF} B_{\ell }=\mathopen{}\mathclose{\left[\Big(\frac{\partial^{2}}{\partial x\partial y}+\frac{1}{2}\cdot\frac{\partial^{2}}{\partial y^{2}}+\frac{\partial}{\partial y}\Big)\,F_{\ell }}\right]_{\substack{x=1,\,y=1} }.\tag{23}\]

5.1 Fibonacci polynomials and some identities↩︎

In this section, we prove some lemmas that will be needed to show that the generating functions \(F_{\ell }\) and \(B_{\ell }\) can be expressed in terms of the Fibonacci polynomials \(f_{n}(z)\) defined by \[f_{n}(z)\mathrel{\vcenter{:}}=\sum_{k=0}^{\mathopen{}\mathclose{\left\lfloor n/2}\right\rfloor }{n-k \choose k}z^{k}\] for \(n\geq0\) (and \(f_{n}(z)\mathrel{\vcenter{:}}= 0\) for \(n<0\)). The first few polynomials \(f_{n}(z)\) are displayed in Table ¿tbl:tb-fibpoly?. It is well known that the \(n\)th Fibonacci number \(f_n\) (defined with initial terms \(f_0=1\) and \(f_1=1\)) counts square-domino tilings of a \(1\times n\) rectangle, and the coefficient \({n-k \choose k}\) of \(f_{n}(z)\) counts such tilings with \(k\) dominoes and \(n-2k\) squares.1 Thus setting \(z=1\) in \(f_{n}(z)\) recovers the \(n\)th Fibonacci number \(f_n\).

The first few Fibonacci polynomials.
\(n\) \(f_{n}(z)\) \(n\) \(f_{n}(z)\)
\(0\) \(1\) \(5\) \(1+4z+3z^{2}\)
\(1\) \(1\) \(6\) \(1+5z+6z^{2}+z^{3}\)
\(2\) \(1+z\) \(7\) \(1+6z+10z^{2}+4z^{3}\)
\(3\) \(1+2z\) \(8\) \(1+7z+15z^{2}+10z^{3}+z^{4}\)
\(4\) \(1+3z+z^{2}\) \(9\) \(1+8z+21z^{2}+20z^{3}+5z^{4}\)

Next, we prove several technical lemmas related to Fibonacci polynomials.

Lemma 4. For all \(n\geq0\), we have \(f_{n+1}(z)=f_{n}(z)+zf_{n-1}(z)\).

Proof. This follows from the combinatorial proof that the number of square-domino tilings of a \(1\times n\) rectangle satisfy the Fibonacci recurrence; the term \(f_{n-1}(z)\) is multiplied by the variable \(z\) (keeping track of dominoes), because that corresponds to the case where we add a domino to the end of a \(1\times(n-1)\) tiling to get a \(1\times(n+1)\) tiling. ◻

Lemma 5. For all \(n\geq0\), we have \(f_{n}(z)^{2}-f_{n-1}(z)f_{n+1}(z)=(-z)^{n}\).

Proof. This formula is a straightforward refinement of Cassini’s formula \(f_{n}^{2}-f_{n-1}f_{n+1}=(-1)^{n}\) for the Fibonacci numbers \(f_{n}\), and the “tail-swapping” combinatorial proof of Cassini’s formula (see [29]) suffices to prove this refinement as well. ◻

Lemma 6. For all \(n\geq0\), we have \(\mathopen{}\mathclose{\left(f_{n}(-z)-f_{n-1}(-z)zC}\right)^{-1}=C^{n}\).

Proof. The case \(n=0\) reduces to the statement \((1-0\cdot zC)^{-1}=1\), which is obviously true, and the case \(n=1\) reduces to \((1-zC)^{-1}=C\), which is equivalent to the functional equation \(C=1+zC^{2}\) for the Catalan generating function. Now, assume that \(\mathopen{}\mathclose{\left(f_{n}(-z)-f_{n-1}(-z)zC}\right)^{-1}=C^{n}\) for a fixed \(n\geq1\). We then have \[\begin{align} C^{n+1} & =\mathopen{}\mathclose{\left(f_{n}(-z)-f_{n-1}(-z)zC}\right)^{-1}(1-zC)^{-1}\\ & =\mathopen{}\mathclose{\left(f_{n}(-z)-f_{n-1}(-z)zC-f_{n}(-z)zC+f_{n-1}(-z)z^{2}C^{2}}\right)^{-1}\\ & =\mathopen{}\mathclose{\left(f_{n}(-z)-zf_{n-1}(-z)+zf_{n-1}(-z)-f_{n-1}(-z)zC-f_{n}(-z)zC+f_{n-1}(-z)z^{2}C^{2}}\right)^{-1}\\ & =\mathopen{}\mathclose{\left(f_{n+1}(-z)-f_{n}(-z)zC+zf_{n-1}(-z)\mathopen{}\mathclose{\left(1-C+zC^{2}}\right)}\right)^{-1}\\ & =\mathopen{}\mathclose{\left(f_{n+1}(-z)-f_{n}(-z)zC}\right)^{-1}, \end{align}\] and the result follows by induction. ◻

Lemma 7. For all \(n\geq0\), we have \[nf_{n}(-z)-2z\frac{\mathrm{d}}{\mathrm{d}z}f_{n}(-z)=-\frac{\mathrm{d}}{\mathrm{d}z}f_{n+1}(-z).\]

Proof. Consider the ordinary generating function \[G(z,x)\mathrel{\vcenter{:}}=\sum_{n=0}^{\infty}f_{n}(z)x^{n}=\frac{1}{1-x-zx^{2}}\] for the Fibonacci polynomials. Taking the partial derivatives of \(G(-z,x)\) yields \[\frac{\partial}{\partial x}G(-z,x)=\frac{1-2zx}{(1-x+zx^{2})^2}\quad\text{and}\quad\frac{\partial}{\partial z}G(-z,x)=\frac{-x^{2}}{(1-x+zx^{2})^2},\] so we have the partial differential equation \[x^{2}\frac{\partial}{\partial x}G(-z,x)=(2zx-1)\frac{\partial}{\partial z}G(-z,x),\] which is equivalent to \[x\frac{\partial}{\partial x}G(-z,x)-2z\frac{\partial}{\partial z}G(-z,x)=-\frac{1}{x}\frac{\partial}{\partial z}G(-z,x).\label{e-diffeq}\tag{24}\] Extracting coefficients of \(x^{n}\) from both sides of (24 ) completes the proof. ◻

Lemma 8. For all \(n\geq0\), we have \[f_{n}(-z)=\frac{\mathrm{d}}{\mathrm{d}z}f_{n+1}(-z)-z\frac{\mathrm{d}}{\mathrm{d}z}f_{n}(-z)+\frac{\mathrm{d}}{\mathrm{d}z}f_{n+2}(-z).\]

Proof. We can use the generating function \[\sum_{n=0}^{\infty}\frac{\mathrm{d}}{\mathrm{d}z}f_{n}(-z)x^{n}=\frac{\partial}{\partial z}G(-z,x)=\frac{-x^{2}}{(1-x+zx^{2})^{2}}\] from the proof of Lemma 7. Observe that \[\begin{align} \sum_{n=0}^{\infty}f_{n}(-z)x^{n} & =\frac{1}{1-x+zx^{2}}\\ & =\frac{-x}{(1-x+zx^{2})^{2}}+\frac{zx^{2}}{(1-x+zx^{2})^{2}}+\frac{1}{(1-x+zx^{2})^{2}}\\ & =\sum_{n=0}^{\infty}\Big(\frac{\mathrm{d}}{\mathrm{d}z}f_{n+1}(-z)-z\frac{\mathrm{d}}{\mathrm{d}z}f_{n}(-z)-\frac{\mathrm{d}}{\mathrm{d}z}f_{n+2}(-z)\Big)x^{n}. \end{align}\] Extracting coefficients of \(x^{n}\) completes the proof. ◻

5.2 Alternative \(\mathop{\mathrm{totalB}}\) formula↩︎

We are now ready to establish the connection between the generating functions \(F_\ell\) and \(B_\ell\) and Fibonacci polynomials, which will lead to an explicit formula for \(\mathop{\mathrm{totalB}}(n,\ell )\) as a difference of two alternating sums.

Theorem 9. For all \(\ell\geq1\), we have \[}\qquad F_{\ell }(x,y,z)=\frac{f_{\ell -1}(-xz)-f_{\ell -2}(-xz)yzC}{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}\] and \[}\qquad B_{\ell }(z)=z^{\ell }C^{3\ell +1}\mathopen{}\mathclose{\left(zC\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)-\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell +1}(-z)}\right).\]

Remark 10. The explicit generating function in Theorem 9 can also be viewed as a possible starting point for an asymptotic derivation of \(\mathop{\mathrm{totalB}}(n,\ell)\), for instance by using singularity-analysis methods for bivariate coefficients such as Drmota’s theorem on coefficients of powers of generating functions [30]. Such an approach would require singularity analysis uniform in the level parameter \(\ell\), particularly in the regime \(\ell=s\sqrt n\). In the present paper we do not pursue this second asymptotic derivation, since Theorem 4 already gives the asymptotics needed for the BFS and DFS comparison. The purpose of this section is instead to give an independent exact-formula approach and to record the connection with continued fractions and Fibonacci polynomials.

Remark 11. Using a basic continued fraction observation (used in [28]), one can guess that \[F_{\ell} = \frac{T_{\ell-1}}{T_{\ell}},\] for some polynomial \(T_{\ell}(x,y,z)\). Indeed, if \(F_{\ell} = \frac{P_{\ell}}{T_{\ell}}\) for some polynomials \(P\) and \(T\), then Equation 22 implies \[F_{\ell} = \frac{P_{\ell}}{T_{\ell}} = \frac{1}{1-xzP_{\ell-1}/T_{\ell-1}} = \frac{T_{\ell-1}}{T_{\ell-1} - xzP_{\ell-1}},\] and thus \(P_{\ell} = T_{\ell-1}\), so \[\label{eq:reqT} T_{\ell} = T_{\ell-1} - xzP_{\ell-1} = T_{\ell-1} - xzT_{\ell-2}.\tag{25}\] Now, if we know that \(T_{l} = f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC\), it is straightforward to verify the recurrence 25 , using Lemma 4. In fact, one can find an expression for \(T_{l}\), and thus for \(F_{\ell}\) by solving that recurrence. We give a less technical and direct inductive proof of Theorem 9 a).

Remark 12. In order to find \(F_{\ell }(x,y,z)\), one can also use the results of Kemp [31], who found an expression for \(Q_{k}(x,y) = \sum_{n\geq 1}\sum_{r\geq 1} Q_{n,k,r}x^{n}y^{r}\), where \(Q_{n,k,r}\) is the number of trees in \(\mathcal{T}_{n+1}\) with \(r\) nodes at maximal level \(k\). Specifically Lemma 2 and Equation 8 in [31], together with the observation that \(Q_{k}(x,y)\) is equal to \(F_{l}(x,y,z)\) after the substitution \(x\mapsto xz\), \(y\mapsto \frac{y}{x}\frac{1-\sqrt{1-4z}}{2z}\), will give us an expression for \(F_{l}(x,y,z)\). However, the described approach would be comparatively technical and does not exhibit the connection with the Fibonacci polynomials.

Proof of Theorem 9. We begin by proving (a). Recall that \[F_{1}=\frac{1}{1-yzC} \qquad \text{and} \qquad F_{\ell }=\frac{1}{1-xzF_{\ell -1}} \quad (l \geq 2).\] The desired result is easily verified for \(\ell=1\) using the formula for \(F_1\). Proceeding via induction, let us assume that the result holds for a fixed \(\ell\geq1\). Then, by the recursive formula for \(F_\ell\), we have \[\begin{align} F_{\ell +1} & =\frac{1}{1-xz\frac{f_{\ell -1}(-xz)-f_{\ell -2}(-xz)yzC}{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}}\\ & =\frac{1}{\frac{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}-\frac{f_{\ell -1}(-xz)xz-f_{\ell -2}(-xz)xyz^{2}C}{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}}\\ & =\frac{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC-f_{\ell -1}(-xz)xz+f_{\ell -2}(-xz)xyz^{2}C}\\ & =\frac{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}{(f_{\ell }(-xz)-f_{\ell -1}(-xz)xz)-(f_{\ell -1}(-xz)-f_{\ell -2}(-xz)xz)yzC}\\ & =\frac{f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}{f_{\ell +1}(-xz)-f_{\ell }(-xz)yzC}, \end{align}\] where the last equality is obtained via Lemma 4. Hence (a) is proven.

We now move on to (b). In light of 23 , let us proceed by taking the required derivatives. Using the formula from (a), we get \[\frac{\partial F_{\ell }}{\partial y} =\frac{(f_{\ell -1}(-xz)^{2}-f_{\ell -2}(-xz)f_{\ell }(-xz))zC}{(f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC)^{2}} =\frac{x^{\ell -1}z^{\ell }C}{(f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC)^{2}}, \label{e-dFldy}\tag{26}\] where the last step is obtained via Lemma 5. Taking the derivative with respect to \(y\) and dividing by \(2\) yields \[\frac{1}{2}\frac{\partial^{2}F_{\ell }}{\partial y^{2}}=\frac{f_{\ell -1}(-xz)x^{\ell -1}z^{\ell +1}C^{2}}{(f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC)^{3}}, \label{e-dFldy2}\tag{27}\] where \[\frac{1}{2}\frac{\partial^{2}F_{\ell }}{\partial y^{2}}+\frac{\partial F_{\ell }}{\partial y}=\frac{x^{\ell -1}z^{\ell }C\mathopen{}\mathclose{\left(f_{\ell }(-xz)+f_{\ell -1}(-xz)(1-y)zC}\right)}{(f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC)^{3}}.\] Therefore, \[\mathopen{}\mathclose{\left[\frac{1}{2}\frac{\partial^{2}F_{\ell }}{\partial y^{2}}+\frac{\partial F_{\ell }}{\partial y}}\right]_{x=1,\,y=1} =\frac{f_{\ell }(-z)z^{\ell }C}{(f_{\ell }(-z)-f_{\ell -1}(-z)zC)^{3}} =z^{\ell }C^{3\ell +1}f_{\ell }(-z)\] from Lemma 6.

Now, consider the derivative of \(\partial F_{\ell }/\partial y\) with respect to \(x\). If \(\ell=1\), then \(\partial F_{\ell }/\partial y\) does not contain \(x\), so \(\partial^{2}F_{\ell }/\partial x\partial y=0\) and therefore \[\begin{align} B_{1} & =\mathopen{}\mathclose{\left[\frac{1}{2}\frac{\partial^{2}F_{\ell }}{\partial y^{2}}+\frac{\partial F_{\ell }}{\partial y}}\right]_{x=1,\,y=1}\\ & =z^{1}C^{3(1)+1}f_{1}(-z)\\ & =z^{1}C^{3(1)+1}\cdot1\\ & =z^{1}C^{3(1)+1}\mathopen{}\mathclose{\left(zC\frac{\mathrm{d}}{\mathrm{d}z}f_{1}(-z)-\frac{\mathrm{d}}{\mathrm{d}z}f_{2}(-z)}\right). \end{align}\] If \(\ell\geq2\), then we have \[\frac{\partial^{2}F_{\ell }}{\partial x\partial y}=\frac{x^{\ell -2}z^{\ell }C\mathopen{}\mathclose{\left((\ell -1)\mathopen{}\mathclose{\left(f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC}\right)-2x\mathopen{}\mathclose{\left(\frac{\partial f_{\ell }(-xz)}{\partial x}-\frac{\partial f_{\ell -1}(-xz)}{\partial x}yzC}\right)}\right)}{(f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC)^{3}}.\] Observing that \[\label{e-dfldx} \mathopen{}\mathclose{\left.\frac{\partial f_{\ell }(-xz)}{\partial x}}\right|_{x=1}=z\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)\tag{28}\] and using Lemma 6, we get \[\begin{align} \mkern-36mu \mathopen{}\mathclose{\left.\frac{\partial^{2}F_{\ell }}{\partial x\partial y}}\right|_{x=1,\,y=1} &= \frac{z^{\ell }C\mathopen{}\mathclose{\left((\ell -1)\mathopen{}\mathclose{\left(f_{\ell }(-z)-f_{\ell -1}(-z)zC}\right)-2\mathopen{}\mathclose{\left(z\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)-z\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell -1}(-z)zC}\right)}\right)}{(f_{\ell }(-xz)-f_{\ell -1}(-xz)yzC)^{3}}\nonumber \\ & \mkern-50mu = z^{\ell }C^{3\ell +1}\mathopen{}\mathclose{\left((\ell -1)\mathopen{}\mathclose{\left(f_{\ell }(-z)-f_{\ell -1}(-z)zC}\right)-2\mathopen{}\mathclose{\left(z\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)-z^{2}C\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell -1}(-z)}\right)}\right), \label{e-dFldxdy} \end{align}\tag{29}\] and thus \[\begin{align} & B_{\ell }(z)=\mathopen{}\mathclose{\left[\Big(\frac{\partial^{2}}{\partial x\partial y}+\frac{1}{2}\cdot\frac{\partial^{2}}{\partial y^{2}}+\frac{\partial}{\partial y}\Big)\,F_{\ell }}\right]_{\substack{x=1,\,y=1} }\\ & \quad=z^{\ell }C^{3\ell +1}\mathopen{}\mathclose{\left((\ell -1)\mathopen{}\mathclose{\left(f_{\ell }(-z)-f_{\ell -1}(-z)zC}\right)-2\mathopen{}\mathclose{\left(z\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)-z^{2}C\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell -1}(-z)}\right)+f_{\ell }(-z)}\right)\\ & \quad=z^{\ell }C^{3\ell +1}\mathopen{}\mathclose{\left(\ell f_{\ell }(-z)-2z\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)-\mathopen{}\mathclose{\left((\ell -1)f_{\ell -1}(-z)-2\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell -1}(-z)}\right)zC}\right)\\ & \quad=z^{\ell }C^{3\ell +1}\mathopen{}\mathclose{\left(zC\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)-\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell +1}(-z)}\right) \end{align}\] from Lemma 7. ◻

Remark 13. As a sanity check, using Theorem 9 a) and Lemma 6, we can see that \(F_{\ell}(1,1,z) = \frac{C^{-(l-1)}}{C^{-l}} = C\).

By extracting coefficients from the generating function \(B_{\ell }\), we get an explicit formula for \(\mathop{\mathrm{totalB}}(n,\ell )\), for which we give a proof below. In this proof, we use the standard notation \([z^n]\, f\) for the coefficient of \(z^n\) in \(f\).

Theorem 14. For all \(n \geq 0\) and \(0 \leq \ell \leq n\), we have \[\begin{align} \label{eq:totalBalt} \mathop{\mathrm{totalB}}(n,\ell ) & =\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor (\ell +1)/2}\right\rfloor }(-1)^{k-1}k{\ell -k+1 \choose k}\frac{3\ell +1}{n-k+2\ell +2}{2n-2k+\ell +2 \choose n-\ell -k+1}\\ & \qquad\qquad\qquad-\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor \ell /2}\right\rfloor }(-1)^{k-1}k{\ell -k \choose k}\frac{3\ell +2}{n-k+2\ell +2}{2n-2k+\ell +1 \choose n-\ell -k}.\nonumber \end{align}\tag{30}\]

Proof. We first note that \[C^{m}=\sum_{n=0}^{\infty}\frac{m}{n+m}{2n+m-1 \choose n}z^{n}, \label{e-Cpow}\tag{31}\] as can be proven by a straightforward application of Lagrange inversion [32]. Using this fact, along with Theorem 9 (b) and \[\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)=\sum_{k=0}^{\mathopen{}\mathclose{\left\lfloor \ell /2}\right\rfloor }(-1)^{k}k{\ell -k \choose k}z^{k-1},\] we get \[\begin{align} & \mathop{\mathrm{totalB}}(n,\ell )=[z^{n}]\,B_{\ell }(z)\\ & \qquad=[z^{n}]\,z^{\ell }C^{3\ell +1}\mathopen{}\mathclose{\left(zC\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell }(-z)-\frac{\mathrm{d}}{\mathrm{d}z}f_{\ell +1}(-z)}\right)\\ & \qquad=[z^{n}]\,\mathopen{}\mathclose{\left(\sum_{k=0}^{\mathopen{}\mathclose{\left\lfloor \ell /2}\right\rfloor }(-1)^{k}k{\ell -k \choose k}z^{\ell +k}C^{3\ell +2}-\sum_{k=0}^{\mathopen{}\mathclose{\left\lfloor (\ell +1)/2}\right\rfloor }(-1)^{k}k{\ell +1-k \choose k}z^{\ell +k-1}C^{3\ell +1}}\right)\\ & \qquad=[z^{n}]\,\mathopen{}\mathclose{\left(\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor (\ell +1)/2}\right\rfloor }(-1)^{k-1}k{\ell +1-k \choose k}z^{\ell +k-1}C^{3\ell +1}-\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor \ell /2}\right\rfloor }(-1)^{k-1}k{\ell -k \choose k}z^{\ell +k}C^{3\ell +2}}\right)\\ & \qquad=\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor (\ell +1)/2}\right\rfloor }(-1)^{k-1}k{\ell +1-k \choose k}[z^{n-\ell -k+1}]C^{3\ell +1}-\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor \ell /2}\right\rfloor }(-1)^{k-1}k{\ell -k \choose k}[z^{n-\ell -k}]C^{3\ell +2}\\ & \qquad=\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor (\ell +1)/2}\right\rfloor }(-1)^{k-1}k{\ell +1-k \choose k}[z^{n- \ell -k+1}]\sum_{n=0}^{\infty}\frac{3\ell +1}{n+3\ell +1}{2n+3l \choose n}z^{n}\\ & \qquad\qquad\qquad\qquad\qquad-\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor \ell /2}\right\rfloor }(-1)^{k-1}k{\ell -k \choose k}[z^{n-\ell -k}]\sum_{n=0}^{\infty}\frac{3\ell +2}{n+3\ell +2}{2n+3\ell +1 \choose n}z^{n}\\ & \qquad=\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor (\ell +1)/2}\right\rfloor }(-1)^{k-1}k{\ell -k+1 \choose k}\frac{3\ell +1}{n-k+2\ell +2}{2n-2k+\ell +2 \choose n-\ell -k+1}\\ & \qquad\qquad\qquad\qquad\qquad-\sum_{k=1}^{\mathopen{}\mathclose{\left\lfloor \ell /2}\right\rfloor }(-1)^{k-1}k{\ell -k \choose k}\frac{3\ell +2}{n-k+2\ell +2}{2n-2k+\ell +1 \choose n-\ell -k}. \qedhere \end{align}\] ◻

It would be interesting to give a direct proof that our two expressions for \(\mathop{\mathrm{totalB}}(n,\ell )\)—in Equations 8 and 30 —are in fact equal. Recovering the asymptotics of \(\mathop{\mathrm{totalB}}(n,\ell)\) obtained in Theorem 4 from Equation 30 would be also interesting and we were not able to do that.

6 General results on the asymptotics of totalB for Galton–Watson trees↩︎

A well-known class of random rooted trees are the Galton–Watson trees. In this section, we generalize Theorem 4 to Galton–Watson trees. Here, we present a short overview of these objects. For a thorough and rigorous presentation of Galton–Watson trees, and random trees in general, we refer to the surveys by Le Gall [33] and Janson [34], as well as the book of Drmota [35].

Let \(Z\) be a random variable on \(\{0,1,2,\dots\}\) with \[\mathbb{E}\mathopen{}\mathclose{\left[Z}\right] = 1 \quad \text{and} \quad \mathbb{V}\mathrm{ar}{Z} = \sigma^2.\] We define a Galton–Watson tree \(T^{(Z)}\) with an offspring distribution \(Z\) recursively, by giving each node independently a random number of children distributed as \(Z\). Let us define \(\mathcal{T}^{(Z)}_n\) to be the set of all possible trees \(T^{(Z)}\) with \(n\) edges, endowed with the conditional probability induced by \(Z\). As observed by Aldous (see [21] and [35]), the uniform distribution on some frequently used sets of rooted trees is generated by \(\mathcal{T}_n^{(Z)}\) for a suitable \(Z\). For example:

  • ordered trees, when \(Z\) has a geometric distribution—i.e., \(\mathbb{P}(Z=k) = 1/2^{k+1}\) for \(k \geq 0\).

  • strict \(m\)-ary trees (every node has \(0\) or \(m\) children), when \(\mathbb{P}(Z=0) = \mathbb{P}(Z=m) = 1/2\).

  • \(m\)-ary trees when \(Z\) has a binomial \(\operatorname{Bin}(m,1/m)\) distribution.

  • labeled trees when \(Z\) has a Poisson distribution with parameter 1—i.e., when \(\mathbb{P}(Z = k) = e^{-1}/k!\).

We obtain the asymptotics of \(\mathop{\mathrm{totalB}}(n,s\sqrt{n})\) on all these sets of trees; see Corollary 1.

As we have already seen in Section 2, an ordered tree with \(n\) edges can be associated with a discrete excursion from \(0\) to \(2n\) via its corresponding Dyck path. It is therefore natural to expect that, after scaling, the corresponding Dyck path converges weakly to a standard Brownian excursion \(\mathbf{e}\) of length 1, and thus the trees themselves will have a weak limit in some abstract sense. This was formalized in the classical works of Aldous [20][22], who called this limiting object the continuum random tree.

Using the random variables defined in Equation 4 , in order to find \(\mathop{\mathrm{totalB}}(n,l)\) in the general case, we can use the equation \[\begin{align} S_n(\ell ) = \binom{H_n(\ell )}{2} - \binom{H_n(\ell -1)}{2} &= \frac{1}{2}\mathopen{}\mathclose{\left(H_n(\ell ) - H_n(\ell -1) }\right) \mathopen{}\mathclose{\left(H_n(\ell ) + H_n(\ell -1) - 1 }\right) \nonumber \\ &= \frac{1}{2} h_n(\ell )\mathopen{}\mathclose{\left(2H_n(\ell ) + h_n(\ell )-1 }\right). \label{eq:32S95n40l41} \end{align}\tag{32}\] Following the work of Aldous, the random variables \(h_n(\ell )\) and \(H_{n}(\ell )\)—giving the number of vertices at level \(\ell\) and the accumulated number of vertices up to level \(\ell\), respectively—should converge to the respective quantities for the Brownian excursion. To formalize this, first extend \(h_n\) and \(H_n\) by linear interpolation to be defined on all reals in \([0,2n]\) instead of only on integers. That is, define \[h_n(t) \mathrel{\vcenter{:}}= \mathopen{}\mathclose{\left(\lfloor t\rfloor+1-t }\right)h_n\mathopen{}\mathclose{\left(\lfloor t\rfloor }\right) + \mathopen{}\mathclose{\left(t-\lfloor t\rfloor }\right)h_n\mathopen{}\mathclose{\left(\lfloor t\rfloor+1 }\right)\] for \(t \in [0,2n]\), and \(h_n(t) \mathrel{\vcenter{:}}= 0\) for \(t\notin [0,2n]\). Next, let us define \[\mu_s \mathrel{\vcenter{:}}= \int_0^1 \mathbb{1}_{\mathopen{}\mathclose{\left\{{\mathbf{e}_t \leq s}}\right\}}\, \mathrm{d}s \quad \text{and} \quad L_s \mathrel{\vcenter{:}}= \frac{\mathrm{d}}{\mathrm{d}s}\mu_s = \lim_{\epsilon \to 0}\frac{1}{\epsilon} \int_0^1 \mathbb{1}_{\mathopen{}\mathclose{\left\{{\mathbf{e}_t \in [s, s+\epsilon]}}\right\}}\,\mathrm{d}t,\] called, respectively, the occupation measure and occupation density (or local time) of \(\mathbf{e}\). It was proven by Aldous in [21] that for a tree in \(\mathcal{T}_n^{(Z)}\), \[\mathopen{}\mathclose{\left(\frac{1}{n}H_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right) }\right)_{s\geq 0} \xrightarrow[\quad]{d} \mathopen{}\mathclose{\left(\mu_{\sigma s/2} }\right)_{s\geq 0},\] as processes on the set of continuous real functions on \([0,1]\), endowed with the uniform norm. It was also conjectured therein (see [21] Conjecture 4), and proven by Drmota and Gittenberger in [36], that \[\label{eq:32h95n40l4132limit} \mathopen{}\mathclose{\left(\frac{1}{\sqrt{n}}h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right) }\right)_{s\geq 0} \xrightarrow[\quad]{d} \mathopen{}\mathclose{\left(\frac{\sigma}{2}L_{\sigma s/2} }\right)_{ s\geq 0}.\tag{33}\] We now have the needed background to state the main result of this section.

Theorem 15. For random trees from \(\mathcal{T}_n^{(Z)}\), we have \[\frac{1}{n^{3/2}}\mathbb{E}\mathopen{}\mathclose{\left[S_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}\right] \to \sigma K_{\sigma s},\] for any constant \(s \geq 0\) as \(n \to \infty\), where \[\label{eq:def32K95s} K_s \mathrel{\vcenter{:}}= \frac{1}{2} \mathbb{E}\mathopen{}\mathclose{\left[ L_{s/2} \mu_{s/2}}\right]= 2se^{-s^2} - 2\sqrt{\pi}\mathopen{}\mathclose{\left(\Phi\mathopen{}\mathclose{\left(2\sqrt{2}s }\right) - \Phi\mathopen{}\mathclose{\left(\sqrt{2}s }\right) }\right).\tag{34}\] As a consequence, if the trees in \(\mathcal{T}_n^{(Z)}\) are equiprobable, then we have \[\label{eq:totalB-GW-asymp} \mathop{\mathrm{totalB}}\mathopen{}\mathclose{\left(n,s\sqrt{n} }\right) \sim \sigma K_{\sigma s} n^{3/2}\mathopen{}\mathclose{\left|\mathcal{T}_n^{(Z)}}\right|\tag{35}\] as \(n\to \infty\).

Proof. From 32 , we know that \[\label{eq:32S95n32in32proof} \begin{align} \frac{1}{n^{3/2}} \mathbb{E}\mathopen{}\mathclose{\left[S_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}\right] = \mathbb{E}\mathopen{}\mathclose{\left[ \frac{h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}{\sqrt{n}}\cdot \frac{{H_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}}{n}}\right] + \frac{1}{2n^{3/2}} \mathopen{}\mathclose{\left(\mathbb{E}\mathopen{}\mathclose{\left[h_n^2\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}\right] -\mathbb{E}\mathopen{}\mathclose{\left[ h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}\right] }\right). \end{align}\tag{36}\] By [37], the last two expectations in 36 are of order \(n\) and \(n^{1/2}\), respectively, so we need only consider the first term. By a standard argument—see, e.g., [5]—Equation 33 implies \[\mathopen{}\mathclose{\left(\frac{h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}{\sqrt{n}} , \frac{H_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}{n} }\right)_{s \geq 0} \xrightarrow[\quad]{d} \mathopen{}\mathclose{\left(\frac{\sigma}{2}L_{\sigma s/2},\mu_{\sigma s/2} }\right)_{s \geq 0}.\] Indeed, by Skorohod–Dudley’s theorem [38], we can find a coupling such that the convergence in 33 is almost sure and therefore \[\mathopen{}\mathclose{\left(\frac{h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}{\sqrt{n}}, \int_0^s \frac{h_n(y\sqrt{n})}{\sqrt{n}}\, \mathrm{d}y }\right)_{s \geq 0} \xrightarrow[\quad]{d} \mathopen{}\mathclose{\left(\frac{\sigma}{2}L_{\sigma s/2},\frac{\sigma}{2} \int_0^s L_{\sigma y/2}\, \mathrm{d}y }\right)_{s \geq 0}.\] The last term is \(H_{\sigma s/2}\) by the definition of the local time \(\ell\), and it remains to link \(H_n\) with the integral of \(h_n\), which is readily done. As an illustration, consider the case where \(s\sqrt{n}\) is an integer. Then, we have \[\frac{H_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}{n} = \frac{1}{n}\mathopen{}\mathclose{\left(\int_0^{s\sqrt{n}} {h_n(y)}\, \mathrm{d}y + \frac{1}{2} \mathopen{}\mathclose{\left(1 + h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right) }\right) }\right) = \int_0^s \frac{h_n\mathopen{}\mathclose{\left(y\sqrt{n} }\right)}{\sqrt{n}}\, \mathrm{d}y + \mathrm{o}\mathopen{}\mathclose{\left(1 }\right).\] Therefore, by the continuous mapping theorem, we have \[\label{eq:32weak32hH} \frac{1}{n^{3/2}} h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)H_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right) \xrightarrow[\quad]{d} \frac{\sigma}{2} L_{\sigma s/2}\mu_{\sigma s/2}.\tag{37}\] To obtain convergence of the means from the last convergence in distribution, we need to check for uniform integrability. For this, it will be enough to ensure an uniform \(L^p\) bound for some \(p>1\); see, e.g., [39]. This is indeed the case as \[H_n(s \sqrt{n}) \leq \sum_{j \leq s\sqrt{n} + 1} h_n(j) \leq (s\sqrt{n} + 1) \sup_m h_n(m),\] so \[\frac{1}{n^{3/2}} h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)H_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right) \leq \frac{(s\sqrt{n} + 1)}{\sqrt{n}} \mathopen{}\mathclose{\left( \frac{\sup_m h_n(m)}{\sqrt{n}} }\right)^2,\] and the last quantity is uniformly bounded in \(L^p\) by [37]. Therefore, 37 implies that \[\frac{1}{n^{3/2}}\mathbb{E}\mathopen{}\mathclose{\left[h_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right){H_n\mathopen{}\mathclose{\left(s\sqrt{n} }\right)}}\right] \xrightarrow[n \to \infty]{} \sigma \mathbb{E}\mathopen{}\mathclose{\left[\frac{1}{2} L_{\sigma s/2} \mu_{\sigma s/2}}\right].\] Substituting into 36 , we get \[\label{e-con1} \frac{1}{n^{3/2}}\mathbb{E}\mathopen{}\mathclose{\left[S_n(s\sqrt{n})}\right] \to \sigma K_{\sigma s}.\tag{38}\] It is immediate from 38 that if the probability on \(\mathcal{T}_n^{(Z)}\) is uniform, then \[\label{e-con2} \frac{1}{n^{3/2}} \cdot \frac{\mathop{\mathrm{totalB}}\mathopen{}\mathclose{\left(n, s\sqrt{n} }\right)}{|\mathcal{T}_n^{(Z)}|} \to \sigma K_{\sigma s}.\tag{39}\] It remains to identify the constant \(K_{s} = \mathbb{E}\mathopen{}\mathclose{\left[L_{s/2}\mu_{s/2}}\right]/2\). Recall that random ordered trees can be constructed as Galton–Watson trees with offspring distribution \(Z\), such that \(\mathbb{P}(Z=k) = 1/2^{k+ 1}\) and \(\mathbb{V}\mathrm{ar}Z = 1\). Therefore 39 reads \[\mathop{\mathrm{totalB}}\mathopen{}\mathclose{\left(n, s\sqrt{n} }\right) \xrightarrow[n \to \infty]{} n^{3/2} \mathopen{}\mathclose{\left|\mathcal{T}_n}\right| K_s.\] However, we know that \(|\mathcal{T}_n|\) is equal to the \(n\)th Catalan number \(C_n\), and using \(C_{n} = \frac{4^{n}}{\sqrt{\pi}n^{3/2}}(1+\Theta(\frac{1}{n}))\), we obtain \[\mathop{\mathrm{totalB}}\mathopen{}\mathclose{\left(n, s\sqrt{n} }\right) \sim \frac{K_s}{\sqrt{\pi}}4^n.\] Comparing this with Equation 9 in Theorem 4, we find the desired explicit expression for \(K_s\). ◻

Corollary 1. Let \(K_s\) be defined as in Equation 34 , and let \(s \geq 0\).

  1. On \(m\)-ary trees—i.e., when \(Z = \operatorname{Bin}(m, 1/m)\) and \(\sigma = \sqrt{(m-1)/m}\)—we have \[\mathop{\mathrm{totalB}}\mathopen{}\mathclose{\left(n,s\sqrt{n} }\right) \sim \sigma K_{\sigma s} \frac{n^{3/2} }{(m-1)n + 1}\binom{mn}{n} \sim \frac{K_{\sigma s}}{\sqrt{2\pi}}\frac{m^{mn}}{(m-1)^{(m-1)n+1}}.\]

  2. On rooted labeled trees—i.e., when \(Z\sim \operatorname{Poi}(1)\) and \(\sigma = 1\)—we have \[\mathop{\mathrm{totalB}}\mathopen{}\mathclose{\left(n,s\sqrt{n} }\right) \sim K_{s} n^{3/2} n^{n-1} = K_s n^{n+1/2}.\]

7 Search in case of a known target level↩︎

In Section 4, we compared the average performance of BFS and DFS when searching for a random node at a fixed level \(\ell\), and we determined which of the two algorithms has an advantage depending on \(\ell\). However, if we know \(\ell\) in advance, it is reasonable to use a simple modification of the DFS algorithm that we call truncated DFS, which does not visit nodes at levels larger than \(\ell\).

Definition 1 (Truncated DFS). Apply DFS and ignore nodes at levels \(>\ell\), where \(\ell\) is fixed.

Let us define \[\mathop{\mathrm{dfsTruncScore}}(v)\mathrel{\vcenter{:}}= \text{the number of nodes visited before v when using truncated DFS.}\] Figure 6 gives an example of a tree traversal when using truncated DFS with \(\ell=2\). Each node is labeled with its \(\mathop{\mathrm{dfsTruncScore}}\). Note that nodes at levels above \(\ell=2\) are not visited and that \(\mathop{\mathrm{dfsTruncScore}}(v)\) gives the number of steps made by the algorithm if the target is \(v\).

Figure 6: The order of exploration for the truncated DFS algorithm.

One can see that the truncated DFS has a smaller expected number of steps compared to both BFS and DFS. For DFS, this is immediate, since while using DFS we visit additional nodes that are skipped when using the truncated version. For BFS, observe that in any tree the nodes at level \(\ell\) have the largest bfsScores among all nodes at levels below \(\ell+1\). However, for the truncated DFS, for most of the trees, the nodes at level \(\ell\) are not those with the largest \(\mathop{\mathrm{dfsTruncScore}}\). Thus the truncated DFS is also faster than BFS on average.

Our next goal will be to prove a statement on \(\mathop{\mathrm{totalDTrunc}}(n,\ell )\) exploiting a particular symmetry, which will be used later to find the asymptotic average time complexity of the truncated DFS algorithm. Recall from Section 5 that \[F_{\ell }=\sum_{n=0}^{\infty}\sum_{T\in{\mathcal{T}}_n}x^{k(T)}y^{m(T)}z^{n},\] where \(k=k(T)\) is the number of non-root nodes in \(T\) at levels smaller than \(\ell\) and \(m=m(T)\) is the number of nodes in \(T\) at level \(\ell\).

Theorem 16. For all \(n \geq 1\) and \(0 \leq \ell \leq n\), we have \[\mathop{\mathrm{totalDTrunc}}(n,\ell ) = \mathop{\mathrm{totalD}}(n,\ell ) - \frac{1}{2} \sum_{T \in \mathcal{T}_n} (m(T)-1)(n-k(T)-m(T)).\]

Proof. We will show that \(\mathop{\mathrm{totalDTrunc}}(n,\ell )\) is equal to \(\mathop{\mathrm{totalD}}(n,\ell )\) minus the number of pairs of nodes \((x,y)\) among all trees \(T \in \mathcal{T}_n\) satisfying the following properties:

  1. \(x\) is at level \(\ell\);

  2. \(y\) is at level larger than \(\ell\);

  3. \(y\) is visited before \(x\) in the inorder traversal of \(T\);

  4. \(y\) is not a descendant of \(x\).

To see this, fix a node \(x\) at level \(\ell\) in a tree \(T \in \mathcal{T}_n\). Then we can obtain \(\mathop{\mathrm{dfsTruncScore}}(x)\) from \(\mathop{\mathrm{dfsScore}}(x)\) by subtracting the number of nodes \(y\) in \(T\) with the above properties, since these are precisely the nodes that are not visited when using the truncated DFS algorithm to search for \(x\), but are visited when using (ordinary) DFS.

It remains to count the pairs \((x,y)\) satisfying the above properties. Suppose that \(T \in \mathcal{T}_n\) has \(k\) nodes at levels smaller than \(\ell\) and \(m\) nodes at level \(\ell\). If we only care about the levels of \(x\) and \(y\), i.e., if we disregard conditions (c) and (d) above, then there are \(m(n-k-m)\) pairs in \(T\). Out of those, there are \(n-k-m\) pairs for which \(y\) is a descendant of \(x\). For each of the \(n-k-m\) possible nodes \(y\), there is exactly one node \(x\) at level \(\ell\) of which \(y\) is a descendant. Therefore, \(m(n-k-m) - (n-k-m) = (m-1)(n-k-m)\) pairs remain. We must sum up over all trees in \(T_n\) and divide the result by 2, because by symmetry \(y\) is visited before \(x\) when performing inorder traversal in exactly half of these pairs. ◻

The latter theorem implies that if we define the generating function \(D_{\ell }\) by \[\begin{align} D_{\ell }=D_{\ell }(z) & \mathrel{\vcenter{:}}=\sum_{n=0}^{\infty} \sum_{T \in \mathcal{T}_n} (m(T)-1)(n-k(T)-m(T))z^{n} \nonumber \\ & =\mathopen{}\mathclose{\left[\Bigg(z\frac{\partial^{2}}{\partial yz}-\frac{\partial^{2}}{\partial xy}-z\frac{\partial}{\partial z}+\frac{\partial}{\partial x}-\frac{\partial^{2}}{\partial y^{2}}\Bigg)F_{\ell }}\right]_{x=1,\,y=1}, \label{e-Dl} \end{align}\tag{40}\] the coefficient of \(z^{n}\) in \(D_{\ell }\) will be twice the difference between \(\mathop{\mathrm{totalD}}(n,\ell )\) and \(\mathop{\mathrm{totalDTrunc}}(n,\ell )\). One can use this expression for \(D_\ell\) to obtain an alternating summation formula for \(\mathop{\mathrm{totalDTrunc}}(n,\ell )\), as the one in Equation 30 for \(\mathop{\mathrm{totalB}}(n,\ell)\). This can be done again by a similar generating function approach to the one used in Section 5.2. We will not include this explicit \(\mathop{\mathrm{totalDTrunc}}(n,\ell )\) formula here, since the obtained expression is comprised of several complicated alternating sums, and the generating function approach is very technical. Instead, we will prove that the truncated DFS algorithm is twice as fast as BFS, in the average case, for any given level \(\ell = s\sqrt{n}\), where \(s\) is a constant.

7.1 Asymptotic complexity of the truncated DFS↩︎

Here, we find an expression (Equation@eq:eq:exact ) for the complexity of the truncated DFS algorithm, \(totalDTrunc(n,\ell)\), for any target level \(\ell\). We also evaluate this expression when \(s\) is a constant. Recall from Section 3, that \(h_n(\ell)\), \(H_n(\ell)\) and \(\nu_n(\ell)\) are denoting the number of vertices at levels \(\ell\), less or equal to \(\ell\) and greater or equal to \(\ell\), respectively. If \(N(n,\ell) := C_n\,\mathbb{E}[h_n(\ell)]\) denotes the exact total number of nodes at level \(\ell\) among trees in \(T_n\), then Theorem 1 gives \[N(n,\ell) := C_n\,\mathbb{E}[h_n(\ell)] = \frac{2\ell+1}{2n+1}\binom{2n+1}{n-\ell},\] Recall from Section 4.1 that \[\frac{\mathop{\mathrm{totalB}}(n,s\sqrt n)}{4^n} \;\longrightarrow\; B(s) := \frac{2s}{\sqrt\pi}e^{-s^2} - 2\Delta(s), \qquad n\to\infty, \label{hwaokisj}\tag{41}\] where \[\Delta(s) := \Phi(2\sqrt2\,s) - \Phi(\sqrt2\,s).\] Recall also that \[\frac{\mathop{\mathrm{totalD}}(n,s\sqrt n)}{4^n}\longrightarrow g(s):=\frac{s}{\sqrt\pi}e^{-s^2}.\] By Theorem 16, \[\begin{align} \mathop{\mathrm{totalD}}(n,\ell) - \mathop{\mathrm{totalDTrunc}}(n,\ell) &= \tfrac12\sum_{T\in T_n}\bigl(m(T)-1\bigr)\bigl(n-k(T)-m(T)\bigr) \notag\\[4pt] &= \tfrac12\,C_n\,\mathbb{E}\bigl[(h_n(\ell)-1)\,\nu_n(\ell+1)\bigr], \label{eq:thm72} \end{align}\tag{42}\] Here, we are using that \(n-k(T)-m(T)=\nu_n(\ell+1)=n+1-H_n(\ell)\), which follows directly from the definitions of \(k(T)\) and \(m(T)\) given before Theorem 16.

For a tree with \(m=h_n(\ell)\) nodes at level \(\ell\), visited in BFS order, right after all of the \(H_n(\ell-1)\) nodes at levels less than \(\ell\), we get \(H_n(\ell-1), H_n(\ell-1)+1,\dots,H_n(\ell-1)+m-1\) for the BFS scores of the nodes on level \(\ell\). Summing up and using that \(h_{n} = m\), we obtain \[S_n(\ell) = m\,H_n(\ell-1) + \binom m2 = m\bigl(H_n(\ell)-m\bigr) + \binom m2 = h_n(\ell)H_n(\ell) - \tfrac{1}{2}h_n(\ell)\bigl(h_n(\ell)+1\bigr).\] Since \(C_n\mathbb{E}[S_n(\ell)] = \mathop{\mathrm{totalB}}(n,\ell)\) by definition, then taking the expectation on both sides, multiplying by \(C_n\) and reordering leads to \[C_n\,\mathbb{E}[h_n(\ell)H_n(\ell)] \;=\; \mathop{\mathrm{totalB}}(n,\ell) + \tfrac12\,C_n\,\mathbb{E}[h_n(\ell)^2] + \tfrac12\,N(n,\ell). \label{eq:hH}\tag{43}\] Since \(\nu_n(\ell + 1) = n+1 - H_n(\ell)\), we expand the product in 42 to get \[(h_n(\ell)-1)(n+1-H_n(\ell)) = (n+1)h_n(\ell) - h_n(\ell)H_n(\ell) - (n+1) + H_n(\ell).\] Taking, again, the expectation on both sides, multiplying by \(C_n\), and using Equation 42 and Equation 43 , gives us \[\begin{align} \mathop{\mathrm{totalD}}(n,\ell)-\mathop{\mathrm{totalDTrunc}}(n,\ell) &= \tfrac12\Bigl[(n+1)N(n,\ell) - \mathop{\mathrm{totalB}}(n,\ell)\Bigr] - \tfrac14 C_n\mathbb{E}[h_n(\ell)^2] - \tfrac14 N(n,\ell) \notag\\ &-\tfrac12(n+1)C_n\;+\;\tfrac12 C_n\mathbb{E}[H_n(\ell)]. \label{eq:exact} \end{align}\tag{44}\] Let \(s>0\) be a fixed constant and let \(\ell=s\sqrt n\), \(n\to\infty\). As pointed out in the proof of Theorem 15, in this case we have \(E[h_n(s\sqrt n)] = \mathcal{O}(\sqrt{n})\) and \(E[h_n(s\sqrt n)^{2}] = \mathcal{O}(n)\). Thus, \[N(n,\ell) = C_n\,\mathbb{E}[h_n(s\sqrt n)] = \mathcal{O}(\sqrt n\,C_n)=\mathcal{O}\!\mathopen{}\mathclose{\left(\tfrac{4^n}{n}}\right),\qquad C_n\,\mathbb{E}[h_n(s\sqrt n)^2] = \mathcal{O}(n\,C_n) = \mathcal{O}\!\mathopen{}\mathclose{\left(\tfrac{4^n}{\sqrt n}}\right),\] and trivially \(C_n\mathbb{E}[H_n(\ell)]\le (n+1)C_n = \mathcal{O}(4^n/\sqrt n)\). To see the latter, recall that \(C_n \sim \frac{4^{n}}{\sqrt{\pi}n^{3/2}}\). Hence every term in 44 except the first one is \(o(4^n)\).

For that first term, the known formulas for \(N(n,\ell)\) and \(\mathop{\mathrm{totalD}}(n,\ell)\) given by Equation 1 and Equation 2 , respectively, give \[n\cdot\frac{N(n,\ell)}{\mathop{\mathrm{totalD}}(n,\ell)} = n\frac{\frac{2\ell+1}{2n+1}\binom{2n+1}{n-\ell}}{\ell\binom{2n}{n-\ell}} = \frac{n(2\ell+1)}{\ell(n+\ell+1)}\;\xrightarrow[\ell=o(n)]{}\;2, \label{eq:nN}\tag{45}\] so that \((n+1)N(n,\ell)\sim 2\,\mathop{\mathrm{totalD}}(n,\ell)\) for \(\ell=s\sqrt n\). Thus, dividing 44 by \(4^n\) and taking \(n\to\infty\) gives \[\frac{\mathop{\mathrm{totalD}}(n,\ell)-\mathop{\mathrm{totalDTrunc}}(n,\ell)}{4^n}\;\longrightarrow\; g(s) - \tfrac12 B(s). \label{eq:diff}\tag{46}\] Combining 46 with 17 results in \[g(s)-\tfrac12 B(s) = g(s) - \Bigl(g(s)-\Delta(s)\Bigr) = \Delta(s),\] so \(\mathop{\mathrm{totalD}}(n,\ell)-\mathop{\mathrm{totalDTrunc}}(n,\ell) \sim 4^n\Delta(s)\), and therefore we proved the last major result of this paper, formulated below.

Theorem 17. Let \(\ell = s\sqrt n\) for a fixed constant \(s>0\). As \(n\to\infty\), \[\frac{\mathop{\mathrm{totalDTrunc}}(n,\ell)}{4^n} \;\longrightarrow\; g(s)-\Delta(s) \;=\; \frac{s}{\sqrt\pi}e^{-s^2} \;-\;\Phi(2\sqrt2\,s)+\Phi(\sqrt2\,s) \;=\; \frac{B(s)}{2}. \label{eq:main}\tag{47}\] Equivalently, when \(s>0\) is a fixed constant and \(n\to\infty\), we have \[\label{eq:totalDTruncTotalB} \mathop{\mathrm{totalDTrunc}}(n,s\sqrt n)\;\sim\;\tfrac12\,\mathop{\mathrm{totalB}}(n,s\sqrt n).\tag{48}\]

Remark 18. We believe that Equation 48 holds for an arbitrary level \(\ell = s\sqrt{n}\), but not just when \(s\) is a constant. The most immediate approach would be to use again Equation 44 , yet we were not able to extend our statement to the cases of \(s\) being a function of \(n\). The heuristic argument sketched on Figure 7 below provides some additional intuition why the equation may hold in general (see the caption).

Figure 7: Given that the target node v is in a fixed tree, on average v would be in the middle of level \ell. The nodes in the gray area (traversed with the truncated DFS) are roughly 1/2 of those traversed by BFS (the nodes above the dashed line denoting level \ell or on that level, but visited prior to v).

8 Further questions↩︎

To conclude this paper, we present the following questions for future study.

Question 1. Suppose that we compare BFS and DFS for a random target node at a given level, but in binary trees. Is there, again, a unique threshold where DFS becomes faster than BFS, which is close to the average level for a node in binary trees? If yes, is there a small difference between the threshold and this average node level, as proven for ordered trees at the end of Section 4?

The results in Section 6 give asymptotics for BFS on general conditioned Galton–Watson trees. It would be interesting to develop a corresponding asymptotic theory for DFS-type quantities, including ordinary DFS and truncated DFS. One possible analytic approach would be to derive functional equations for the generating functions encoding the relevant score quantities in the framework of simply generated trees; see e.g. Drmota [35]. Such a method could potentially yield asymptotic results not only for ordered trees, but also for broader classes of simply generated trees, equivalently for associated conditioned Galton–Watson trees.

There may also be a probabilistic route through the continuum random tree. For BFS-type quantities, profile and local-time convergence are sufficient, since BFS depends essentially on the number of vertices at prescribed levels and on cumulative profiles. In contrast, DFS-type quantities are sensitive to the depth-first order of the vertices. A CRT approach to ordinary DFS or truncated DFS would therefore seem to require convergence of more refined functionals of the discrete contour process, such as time-indexed measures of level upcrossings. We are not aware of such a convergence result in a directly applicable form, but it seems to be a natural direction for future work. We ask the same question for the truncated DFS algorithm, as well.

Question 2. Can one obtain asymptotic formulas for \(\mathop{\mathrm{totalD}}(n,\ell)\) and \(\mathop{\mathrm{totalDTrunc}}(n,\ell)\), uniformly in regimes such as \(\ell=s\sqrt n\), for general simply generated trees or conditioned Galton–Watson trees?

The next question is related to Section 7. In the standard implementation of BFS, we push the root into a queue. Then, we push the children of the node at the top of the queue, until we traverse all of them. Then, we pop that node and continue in the same way with the new element that is at the top. DFS is executed in the same way, but the nodes are pushed onto a stack instead of a queue. It is sensible to allow pushing nodes on both sides of a double-ended queue (deque).

Question 3. What is the optimal search algorithm implemented using a deque, if \(\ell\) is known in advance and the target is selected uniformly at random among all nodes on level \(\ell\) in \(\mathcal{T}_{n}\)?

We believe that truncated DFS is not only faster in expectation than both BFS and DFS, but that it is faster in expectation than any algorithm that can be implemented with a deque.

Question 4. Given that \(n\) and the target level \(\ell\) are known in advance, is it true that the truncated DFS algorithm defined in Section 7 is faster in expectation than any algorithm that uses only a deque, i.e., an algorithm that can switch between BFS and DFS at every step?

Question 5. Suppose that we do not know the exact level \(\ell\) where our target node is located, but only that \(\ell\) is in an interval \([u,v]\). What is the optimal algorithm, using the deque data structure, in this setting?

Question 6. Suppose that we have multiple target nodes chosen uniformly at random among those at a given level \(\ell\) in the trees with \(n\) edges. What are the average-case time complexities of BFS and DFS in this scenario?

Acknowledgments↩︎

We wish to recognize and thank Luz Grisales Gómez for her involvement at the beginning stages of this project. The first author is thankful to Svante Janson for pointing out reference [21]. The same author is also indebted to George Spahn for mentioning the idea of the truncated DFS algorithm. The first author was partially supported by an AMS-Simons Travel Grant. The second author is supported by the European Union’s NextGenerationEU, through the National Recovery and Resilience Plan of the Republic of Bulgaria, project No BG-RRP-2.004-0008. The third author was partially supported by an AMS-Simons Travel Grant and NSF grant DMS-2316181. Finally, Claude Sonnet 5 was used to obtain some of the results in Section 4.1 and in Section 7.1, as well as for catching mistakes throughout the paper.

References↩︎

[1]
S. Russell and P. Norvig, Artificial intelligence: A Modern Approach, Fourth. Pearson, 2021.
[2]
P. Kerschke, H. Hoos, F. Neumann, and H. Trautmann, “Automated algorithm selection: Survey and perspectives,” Evol. Comput., vol. 27, no. 1, pp. 3–45, 2019.
[3]
L. Kotthoff, Algorithm selection for combinatorial search problems: A survey,” in Data Mining and Constraint Programming, vol. 10101, Cham: Springer, 2016, pp. 149–190.
[4]
L. Takács, “The distribution of the sojourn time for the Brownian excursion,” Methodol. Comput. Appl. Probab., vol. 1, no. 1, pp. 7–28, 1999, doi: 10.1023/A:1010060107265.
[5]
D. Aldous, “Brownian excursion conditioned on its local time,” Electron. Comm. Probab., vol. 3, pp. 79–90, 1998, doi: 10.1214/ECP.v3-996.
[6]
D. Knuth, “Estimating the efficiency of backtrack programs,” Math. Comp., vol. 29, no. 129, pp. 122–136, 1975.
[7]
N. Dershowitz and S. Zaks, “Enumerations of ordered trees,” Discrete Math., vol. 31, no. 1, pp. 9–28, 1980, doi: 10.1016/0012-365X(80)90168-5.
[8]
T. Everitt and M. Hutter, Analytical results on the BFS vs. DFS algorithm selection problem. Part I: Tree search,” in AI 2015: Advances in Artificial Intelligence, vol. 9457, Cham: Springer, 2015, pp. 157–165.
[9]
H. Stone and P. Sipala, “The average complexity of depth-first search with backtracking and cutoff,” IBM J. Res. Develop., vol. 30, no. 3, pp. 242–258, 1986.
[10]
P. Kilby, J. Slaney, S. Thiébaux, T. Walsh, et al., “Estimating search tree size,” in Proc. Of the 21st national conf. Of artificial intelligence, AAAI, menlo park, 2006.
[11]
J. Rice, “The algorithm selection problem,” in Advances in computers, vol. 15, Elsevier, 1976, pp. 65–118.
[12]
A. Sen, A. Bagchi, and W. Zhang, “An average-case analysis of graph search,” in Proceedings of the AAAI/IAAI, 2002, pp. 757–763.
[13]
P. Jacquet and S. Janson, “Depth-first search performance in a random digraph with geometric outdegree distribution,” La Matematica, pp. 1–31, 2024.
[14]
I. Gessel and B. Sagan, “The Tutte polynomial of a graph, depth-first search,” Electron. J. Combin., vol. 3, no. 1, pp. Research Paper 9, 9 pp., 1996.
[15]
I. Gessel and D.-L. Wang, “Depth-first search as a combinatorial correspondence,” J. Combin. Theory Ser. A, vol. 26, no. 3, pp. 308–313, 1979.
[16]
C. Krattenthaler, “Lattice path enumeration,” in Handbook of Enumerative Combinatorics, Boca Raton, FL: CRC Press, 2015, pp. 589–678.
[17]
D. Callan, “Some bijections and identities for the Catalan and fine numbers.” Séminaire Lotharingien de Combinatoire [electronic only], vol. 53, pp. B53e–16, 2005.
[18]
H. Gould, “Some generalizations of Vandermonde’s convolution,” Amer. Math. Monthly, vol. 63, no. 2, pp. 84–91, 1956.
[19]
K. Humphreys, “A history and a survey of lattice path enumeration,” J. Statist. Plann. Inference, vol. 140, no. 8, pp. 2237–2254, 2010, doi: 10.1016/j.jspi.2010.01.020.
[20]
D. Aldous, “The continuum random tree. I,” Ann. Probab., vol. 19, no. 1, pp. 1–28, 1991, [Online]. Available: http://links.jstor.org/sici?sici=0091-1798(199101)19:1<1:TCRTI>2.0.CO;2-B&origin=MSN.
[21]
D. Aldous, The continuum random tree. II. An overview,” in Stochastic Analysis (Durham, 1990), vol. 167, Cambridge: Cambridge Univ. Press, 1991, pp. 23–70.
[22]
D. Aldous, “The continuum random tree. III,” Ann. Probab., vol. 21, no. 1, pp. 248–289, 1993, [Online]. Available: http://links.jstor.org/sici?sici=0091-1798(199301)21:1<248:TCRTI>2.0.CO;2-1&origin=MSN.
[23]
V. Petrov, Sums of Independent Random Variables, vol. 82. New York-Heidelberg: Springer-Verlag, 1975, p. x+346.
[24]
A. Shiryaev, Probability. 1, Third., vol. 95. New York: Springer, 2016, p. xvii+486.
[25]
W. Hoeffding, “Probability inequalities for sums of bounded random variables,” J. Amer. Statist. Assoc., vol. 58, pp. 13–30, 1963, [Online]. Available: http://links.jstor.org/sici?sici=0162-1459(196303)58:301<13:PIFSOB>2.0.CO;2-D&origin=MSN.
[26]
P. Flajolet and R. Sedgewick, Analytic Combinatorics. Cambridge University Press, 2009.
[27]
J. P. Mills, “Table of the ratio: Area to bounded ordinate, for any portion of normal curve,” Biometrika, vol. 18, no. 3–4, pp. 395–400, 1926.
[28]
N. G. de Bruijn, D. E. Knuth, and S. Rice, “The average height of planted plane trees,” in Graph theory and computing, Elsevier, 1972, pp. 15–22.
[29]
A. Benjamin and J. Quinn, Proofs That Really Count: The Art of Combinatorial Proof, vol. 27. Washington, DC: Mathematical Association of America, 2003, p. xiv+194.
[30]
M. Drmota, “A bivariate asymptotic expansion of coefficients of powers of generating functions,” European Journal of Combinatorics, vol. 15, pp. 139–152, 1994.
[31]
R. Kemp, “On the number of deepest nodes in ordered trees,” Discrete mathematics, vol. 81, no. 3, pp. 247–258, 1990.
[32]
I. Gessel, “Lagrange inversion,” J. Combin. Theory Ser. A, vol. 144, pp. 212–249, 2016, doi: 10.1016/j.jcta.2016.06.018.
[33]
J.-F. Le Gall, “Random trees and applications,” Probab. Surv., vol. 2, pp. 245–311, 2005, doi: 10.1214/154957805100000140.
[34]
S. Janson, “Simply generated trees, conditioned Galton-Watson trees, random allocations and condensation,” Probab. Surv., vol. 9, pp. 103–252, 2012, doi: 10.1214/11-PS188.
[35]
M. Drmota, Random Trees: An interplay between combinatorics and probability. Springer Vienna, 2009, p. xvii+458.
[36]
M. Drmota and B. Gittenberger, “On the profile of random trees,” Random Structures Algorithms, vol. 10, no. 4, pp. 421–451, 1997, doi: 10.1002/(SICI)1098-2418(199707)10:4<421::AID-RSA2>3.3.CO;2-P.
[37]
M. Drmota and B. Gittenberger, “The width of Galton-Watson trees conditioned by the size,” Discrete Math. Theor. Comput. Sci., vol. 6, no. 2, pp. 387–400, 2004.
[38]
O. Kallenberg, Foundations of Modern Probability, vol. 99. Springer, Cham, 2021, p. xii+946.
[39]
P.-A. Meyer, Probability and Potentials. Waltham, MA: Blaisdell Publishing Co., 1966, p. xiii+266.

  1. We note that [29] and some other sources define Fibonacci polynomials slightly differently, by taking the coefficient of \(z^n\) in \(f_{n}(z)\) to be the number of square-domino tilings of a \(1\times n\) rectangle with \(k\) squares and \((n-k)/2\) dominoes.↩︎