Consider a search from the root of an ordered tree with edges to some target node at a fixed distance from that root. We compare the average time complexity of the breadth-first search (BFS) and depth-first search (DFS) algorithms, when the target node is selected uniformly at random among all nodes at level in the ordered trees with edges. Intuition suggests that BFS should have better average performance when is small, while DFS must have an advantage when is large. But where exactly is the threshold, as a function of , and is it unique? We obtain explicit formulas for the expected number of steps of both BFS and DFS, by using results on the occupation measure of Brownian excursions, as well as a combinatorial proof of an identity related to lattice paths. This allows us to show that there exists a unique constant , such that in expectation BFS is asymptotically faster than DFS if and only if . Furthermore, we find the asymptotic average time complexity of BFS in the given setting for any class of GaltonWatson trees, including binary trees and ordered trees. Finally, we introduce the truncated DFS algorithm, which performs better than both BFS and DFS when is known in advance, and we find a formula evaluating the average time complexity of this algorithm.

生成讲解博客的中文版本

生成AI智能校验的中文版本