BFS versus DFS for fixed-level targets in ordered trees
Provides theoretical guidance for choosing between BFS and DFS in tree search when target level is known approximately, relevant to algorithm designers.
The paper derives the average time complexity of BFS and DFS for finding a target node at a fixed level in ordered trees, showing BFS is asymptotically faster than DFS if and only if the level is at most λ√n (λ≈0.789). It also provides asymptotic complexity for BFS in Galton-Watson trees and shows truncated DFS is twice as fast as BFS.
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 $λ\approx 0.789004$, such that in expectation BFS is asymptotically faster than DFS if and only if $\ell\leq λ\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.