IT lexicon › Programming › DFS

DFS Depth-First Search

Programming På svenska → Updated: 2026-05-24

Graph traversal algorithm — go as deep as possible along each branch before backtracking. Implemented recursively or with a stack.

Usage: topological sorting, cycle detection, finding connected components, solving mazes, compiler passes. Tarjan's SCC + bridges algorithms are built on DFS. Distinct from BFS: DFS uses less memory (O(d) depth) but doesn't find shortest paths. Iterative DFS via stack avoids stack overflow on deep graphs. git log traverses the commit DAG via DFS.

← Back to the lexicon