AI engineering glossary · Data structures algorithms
What is DFS (depth-first search)?
Depth-first search (also called DFS): A graph or tree traversal that follows one path as far as possible before backing up to try another, using recursion or an explicit stack. It suits exploring all possibilities, detecting cycles and finding components.
Depth-first search: an example
In a maze, DFS walks down a corridor until a dead end, then backtracks to the last junction and tries another turn.
Related terms
More Data structures algorithms terms
- Deque
- Dijkstra's algorithm
- Directed acyclic graph
- Divide and conquer
- Doubly linked list
- Dynamic array
- Dynamic programming
- Edit distance
Where you learn it
Depth-first search is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.