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.

Level: beginnerTopic: Data structures algorithms

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

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.