LLMpediaThe first transparent, open encyclopedia generated by LLMs

Depth-first search

Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: Ford–Fulkerson method Hop 5 terminal

This article was accepted into the corpus but its outbound wikilinks were never NER-processed — typical at the deepest BFS hop or when the run's entity cap was reached. No expansion funnel to show.

Depth-first search
NameDepth-first search
Invented byCharles Trémaux; formalized by Edsger W. Dijkstra and Robert Tarjan
Year19th century (maze tracing); 20th century (graph theory)
InputGraph or tree, start vertex
OutputSearch tree, discovery/finish times, connectivity information
ComplexityTime: O(V + E); Space: O(V) (recursive stack)
GenreGraph traversal algorithm

Depth-first search is a graph traversal method that explores as far along each branch as possible before backtracking, producing a spanning tree or forest and enabling discovery/finish orderings, cycle detection, and connectivity analysis. Originating from maze-tracing techniques attributed to Charles Trémaux and later formalized in the work of Edsger W. Dijkstra and Robert Tarjan, it underpins many algorithms in graph theory, compiler construction, and network analysis. Depth-first search serves as a fundamental primitive for algorithms developed by researchers associated with Bell Labs, Massachusetts Institute of Technology, and institutions like Stanford University and Princeton University.

Introduction

Depth-first search operates on an abstract graph or tree structure, starting at a chosen vertex and exploring neighbor vertices recursively or via an explicit stack until all reachable vertices are visited. It contrasts with breadth-first strategies used in problems treated at Bell Labs and in courses at Carnegie Mellon University and University of California, Berkeley. DFS is central to proofs and algorithms by Tarjan, applications in parsing connected to work at Bell Labs (e.g., for Yacc), and theoretical treatments in texts by authors affiliated with Addison-Wesley and Prentice Hall.

Algorithm

The canonical procedure marks a start vertex as discovered, recursively visits an undiscovered neighbor, and upon reaching a vertex with no unexplored neighbors backtracks to continue with other neighbors. Implementations commonly record discovery and finish times, parent pointers, and vertex colors; such instrumentation appears in algorithmic presentations from MIT Press and lectures at Stanford University. DFS supports proofs and reductions used by scholars at Oxford University, Cambridge University, and in algorithmic competitions organized by ACM and ICPC.

Variants and extensions

Numerous variants extend DFS for specific tasks: iterative deepening depth-first search influenced research at SRI International and used in game tree search popularized by programs developed at IBM; depth-limited search is applied in tournament play at World Chess Federation events; randomized depth-first strategies appear in procedures from Los Alamos National Laboratory and in heuristics employed by teams from Google and Facebook. Other extensions include nondeterministic and symbolic DFS used in model checking at Bell Labs Research and in tools from Microsoft Research.

Complexity and correctness

On a graph with V vertices and E edges, DFS runs in O(V + E) time using adjacency lists and requires O(V) space for recursion or an explicit stack; these complexity bounds are standard in courses at Massachusetts Institute of Technology and textbooks by authors from Princeton University Press. Correctness proofs rely on induction and invariants similar to arguments found in seminars at ETH Zurich and lectures by researchers at Carnegie Mellon University. DFS properties underpin proofs of strong connectivity algorithms attributed to Kosaraju and Tarjan, and analyses are presented in conferences such as STOC and FOCS.

Applications

DFS is used for cycle detection in compilers and static analysis by teams at Bell Labs and Microsoft Research, topological sorting in build systems originating from practices at AT&T and Sun Microsystems, articulation point and bridge finding employed in network reliability studies at AT&T Labs and Nokia, and maze generation techniques traced to methods evaluated by Charles Trémaux. It appears in formal verification tools developed at NASA and model checking systems from CMU partners, in pathfinding utilities used by companies like Google and Uber, and in academic problems explored at contests by ACM and IOI.

Implementation details and examples

Typical pseudocode uses recursion with arrays or maps for discovered flags, parent pointers, and timestamps; practical implementations ship in libraries associated with Boost and language runtimes maintained by teams at Oracle Corporation and Microsoft. Iterative implementations replace recursion with an explicit stack, a pattern demonstrated in educational materials from Coursera and edX courses produced by professors at Stanford University and MIT. Example code often appears in repositories curated by contributors from GitHub and in algorithm collections published by Addison-Wesley authors.

Practical considerations and optimizations

When recursion depth may exceed system limits, iterative stacks or tail-call optimizations advised in systems programming texts from O'Reilly Media and Unix literature are used; these practices are common at organizations like Google and Amazon. For sparse graphs adjacency lists minimize overhead, while for dense graphs adjacency matrices—referenced in surveys from IEEE and ACM—can simplify implementations. Memory locality and cache-aware layouts recommended by research groups at Intel and NVIDIA can significantly affect performance in large-scale deployments used by Facebook and Netflix.

Category:Graph algorithms