[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-81493-en":3,"doc-seo-81493-105":30,"detail-sidebar-cat-0-en-105":91},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":21,"is_downloadable":21,"audit_status":21,"page_count":22,"language":23,"language_code":24,"site_id":25,"html_lang":24,"table_of_contents":26,"faqs":27,"seo_title":13,"seo_description":14,"update_tm":28,"read_time":29},81493,1099513958607,"Jiven","https://ap-avatar.wpscdn.com/avatar/100002390cf8733938c?x-image-process=image/resize,m_fixed,w_180,h_180&k=1778829742770036399",8,"Research & Report","BFS versus DFS for Fixed-Level Targets in Ordered Trees","Average-case time complexity comparison of breadth-first search (BFS) and depth-first search (DFS) on ordered trees. The target node is chosen uniformly at random among nodes at a fixed depth level ℓ among all rooted ordered trees with n edges. A unique threshold λ ≈ 0.789004 is identified such that the expected BFS time is asymptotically smaller than DFS exactly when ℓ ≤ λ√n. Results extend to Galton–Watson tree classes and analyze a truncated DFS variant.","arXiv :2404 .05664v2 [ cs .DS] 10 Jul 2026  \nBFS VERSUS DFS FOR FIXED-LEVEL TARGETS IN ORDERED TREES  \nSTOYAN DIMITROV  \nDEPARTMENT OF MATHEMATICS, DARTMOUTH COLLEGE  \nEMAILTOSTOYAN@GMAIL.COM  \nMARTIN MINCHEV  \nFACULTY OF MATHEMATICS AND INFORMATICS, SOFIA UNIVERSITY  \nMJMINCHEV@FMI .UNI-SOFIA .BG  \nYAN ZHUANG  \nDEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE, DAVIDSON COLLEGE  \nYAZHUANG@DAVIDSON.EDU  \nAbstract. 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 ℓ 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 ℓ, as a function of n, is below a certain threshold. We confirm this intuition by showing that there exists a unique constant λ ≈ 0.789004, such that in expectation BFS is asymptotically faster than DFSif and only if ℓ ≤ λ √n. This gives us a practical rule to select between the two algorithms, even when we do not know the exact value of ℓ, 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 ℓ is known in advance.  \nWe show that in fact its asymptotic time complexity is 1/2 of the asymptotic complexity of BFS, when ℓ = s √n for any constant s. Several further questions are also raised.  \nKeywords: breadth-first search, depth-first search, average-case complexity, trees, Galton– Watson trees, random graphs.  \n1. Introduction  \nSeveral important problems in computer science and artificial intelligence can be formulated as search problems [35, Chapter 3] . Some examples include the traveling salesman problem, scheduling problems, and the problem of finding optimal moves in various games. Most decisionmaking 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 [25] . Some machine learning approaches exist for algorithm selection [28] depending on the instance, but they are usually less useful than having an exact average-case comparison.  \nIn 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.  \nIn 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 ℓ in a tree with n edges, is 2ℓ(n + ℓ + 1) . Then, we find the expected number of steps made by BFS via results of Tak´acs [39] 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 ℓ, n → ∞ , and when ℓ is a function of n. Consequently, we find a unique thre","cbCaifSQVrDhOzBa","https://ap.wps.com/l/cbCaifSQVrDhOzBa","pdf",481589,4,1,28,"English","en",105,"# Introduction\n## Problem formulation and main result","[{\"question\":\"How are BFS and DFS compared in this study?\",\"answer\":\"The study compares BFS and DFS by their average time complexity when searching for a target node at a fixed level ℓ in ordered rooted trees with n edges.\"},{\"question\":\"What threshold determines whether BFS is faster than DFS?\",\"answer\":\"A unique constant λ ≈ 0.789004 determines the asymptotic regime: BFS is asymptotically faster than DFS if and only if ℓ ≤ λ√n.\"},{\"question\":\"Does the paper cover more than ordered trees?\",\"answer\":\"Yes. It derives the asymptotic average BFS time complexity for broader Galton–Watson tree classes, which include ordered trees, binary trees, and other popular families.\"}]",1784173797,71,{"code":4,"msg":31,"data":32},"ok",{"site_id":25,"language":24,"slug":33,"title":13,"keywords":34,"description":14,"schema_data":35,"social_meta":86,"head_meta":88,"extra_data":90,"updated_unix":28},"bfs-versus-dfs-for-fixed-level-targets-in-ordered-trees","",{"@graph":36,"@context":85},[37,53,68],{"@type":38,"itemListElement":39},"BreadcrumbList",[40,44,48,51],{"item":41,"name":42,"@type":43,"position":21},"https://docshare.wps.com","Home","ListItem",{"item":45,"name":46,"@type":43,"position":47},"https://docshare.wps.com/document/","Document",2,{"item":49,"name":12,"@type":43,"position":50},"https://docshare.wps.com/document/research-report/",3,{"item":52,"name":13,"@type":43,"position":20},"https://docshare.wps.com/document/bfs-versus-dfs-for-fixed-level-targets-in-ordered-trees/81493/",{"url":52,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":24,"description":14,"dateModified":61,"datePublished":62,"encodingFormat":60,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":41,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-24","2026-07-16",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81],{"name":72,"@type":73,"acceptedAnswer":74},"How are BFS and DFS compared in this study?","Question",{"text":75,"@type":76},"The study compares BFS and DFS by their average time complexity when searching for a target node at a fixed level ℓ in ordered rooted trees with n edges.","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"What threshold determines whether BFS is faster than DFS?",{"text":80,"@type":76},"A unique constant λ ≈ 0.789004 determines the asymptotic regime: BFS is asymptotically faster than DFS if and only if ℓ ≤ λ√n.",{"name":82,"@type":73,"acceptedAnswer":83},"Does the paper cover more than ordered trees?",{"text":84,"@type":76},"Yes. It derives the asymptotic average BFS time complexity for broader Galton–Watson tree classes, which include ordered trees, binary trees, and other popular families.","https://schema.org",{"og:url":52,"og:type":87,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":89,"canonical":52},"index,follow",{"doc_id":7,"site_id":25},{"code":4,"msg":5,"data":92},[93,97,101,105,110,115,120,123,128,131,135],{"id":21,"doc_module":4,"doc_module_name":46,"category_name":94,"show_sort_weight":95,"slug":96},"Story & Novel",90,"story-novel",{"id":47,"doc_module":4,"doc_module_name":46,"category_name":98,"show_sort_weight":99,"slug":100},"Literature",80,"literature",{"id":20,"doc_module":4,"doc_module_name":46,"category_name":102,"show_sort_weight":103,"slug":104},"Exam",70,"exam",{"id":106,"doc_module":4,"doc_module_name":46,"category_name":107,"show_sort_weight":108,"slug":109},5,"Comic",60,"comic",{"id":111,"doc_module":4,"doc_module_name":46,"category_name":112,"show_sort_weight":113,"slug":114},6,"Technology",50,"technology",{"id":116,"doc_module":4,"doc_module_name":46,"category_name":117,"show_sort_weight":118,"slug":119},7,"Healthcare",40,"healthcare",{"id":11,"doc_module":4,"doc_module_name":46,"category_name":12,"show_sort_weight":121,"slug":122},30,"research-report",{"id":124,"doc_module":4,"doc_module_name":46,"category_name":125,"show_sort_weight":126,"slug":127},9,"Religion & Spirituality",20,"religion-spirituality",{"id":126,"doc_module":4,"doc_module_name":46,"category_name":129,"show_sort_weight":126,"slug":130},"World Cup","world-cup",{"id":132,"doc_module":4,"doc_module_name":46,"category_name":133,"show_sort_weight":132,"slug":134},10,"Lifestyle","lifestyle",{"id":136,"doc_module":4,"doc_module_name":46,"category_name":137,"show_sort_weight":106,"slug":138},19,"General","general"]