Overview
Depth-First Search uses recursion or an explicit stack to visit a node, continue to an unvisited neighbor, and backtrack when no unexplored neighbors remain.
Explores a graph by following one path as far as possible before backtracking.
Compact metadata for implementation and discovery.
Depth-First Search uses recursion or an explicit stack to visit a node, continue to an unvisited neighbor, and backtrack when no unexplored neighbors remain.
Quick facts
Runtime and memory behavior at a glance.
Best
O(V + E)
Average
O(V + E)
Worst
O(V + E)
Space
O(V)
Show the active path extending and then backtracking.
DFS is a traversal pattern behind many graph algorithms, including topological sort and strongly connected components.
What each reference supports for this entry.
Textbook reference for the algorithmic family and analysis of Depth-First Search.
Good next jumps from the relationship graph, ranked for useful discovery.
Graph Traversal · Core
Iterative deepening DFS repeats depth-limited DFS with increasing search limits.
Compare with thisGraph Traversal · Core
DFS discovery and lowlink values drive the decomposition.
Compare with thisGraph Traversal · Core
Bridge detection uses DFS discovery and low-link values to find edges whose removal disconnects a graph.
Compare with thisOptimization · Core
Backtracking typically explores assignments through depth-first recursive search.
Compare with thisDFS recursion state is commonly used for directed cycle detection.
Tarjan's SCC algorithm builds on DFS discovery state.
DFS finishing order is a common way to compute topological order.