SearcharxivSearch

arXiv · 2404.05664

BFS versus DFS for fixed-level targets in ordered trees

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 \textit{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.

Explore related subjects

Keep this discovery

BibTeXRIS

Stoyan Dimitrov, Martin Minchev, Yan Zhuang. 2024-04-08. BFS versus DFS for fixed-level targets in ordered trees. https://arxiv.org/abs/2404.05664

Cite the original work for its findings. Save a collection to share your selection of sources.

KEEP EXPLORING

Related papers

Quasi-Monte Carlo Beyond Hardy-Krause II: $(1 + \varepsilon)n$ Samples Suffice

Numerical integration studies how well one can estimate the integral of a function $f$ over $[0,1)^d$ using $n$ sample points. The two classical methods, Monte Carlo (MC) and quasi-Monte Carlo (QMC), have complementary strengths and weaknesses, and a fundamental question is to design an approach that combines the benefits of both. Recently, building on the transference principle in discrepancy theory, Bansal and Jiang~\cite{BJ25a} gave a randomized QMC method that bridges MC and QMC guarantees using only i.i.d.\ samples. Their method also goes beyond the classical Koksma--Hlawka inequality: it achieves integration error $\widetilde{O}_d(\sigma_{\mathsf{SO}}(f)/n)$, where the smoothed-out variation $\sigma_{\mathsf{SO}}(f)$ can be substantially smaller than the Hardy--Krause variation that governs the classical bound. However, their algorithm requires $n^2$ i.i.d.\ samples as input, and this quadratic blowup is inherent to any method based on the transference principle. In this work, we bypass the quadratic blowup: for any constant $\varepsilon > 0$, we show that $(1+\varepsilon)n$ i.i.d.\ samples suffice to both obtain the beyond-Hardy--Krause guarantee of~\cite{BJ25a}, resolving an open problem posed there, and to produce low-discrepancy point sequences. Our algorithms are variants of the online Haar-thinning method of Dwivedi, Feldheim, Gurel-Gurevich, and Ramdas~\cite{DFG+19}.

cs.DS

Single-Exponential Algorithms and a Polynomial Kernel for Strong Connectivity Augmentation

Strong Connectivity Augmentation (SCA) asks whether a directed acyclic graph can be made strongly connected by adding at most $k$ prescribed links whose total weight is within a given budget. Klinkby, Misra, and Saurabh (SODA 2021) gave an $O^*(2^{O(k\log k)})$-time algorithm and asked whether the problem admits a single-exponential parameterized algorithm and a polynomial kernel. We answer both questions affirmatively: SCA can be solved in $O^*(9^k)$ time and admits a polynomial kernel with $O(k^4)$ vertices and $O(k^{16})$ bits. For unweighted SCA, we obtain $O^*(4^k)$ time and a kernel with $O(k^3)$ vertices. Our algorithms are based on a particularly simple reduction to Strongly Connected Spanning Subgraph with two edge costs.

cs.DS