Depth-First Search definition
Depth-first search explores one branch of a graph as far as possible before backtracking.
Depth-First Search in a picture
How it works
Mark each vertex when it is first reached. Recursively explore an unvisited neighbor, or use an explicit stack to manage the branch. When no unvisited neighbor remains, return to the previous vertex and continue from there.
Worked examples
What structure supports the search without recursion?
An explicit last-in, first-out stack or stack of traversal frames.
What if a vertex has only visited neighbors?
Backtrack.
Does depth-first search guarantee a shortest path in an unweighted graph?
No. It may discover a longer branch first.
Common mistake
Track visited vertices to avoid looping around cycles.
Quick check
Can neighbor order change the visitation order?
Show answer
Yes.
Which graph search visits by distance layers?
Show answer
Breadth-first search.
Sources
Flashcard
Depth-First Search
Reveal the definition
Depth-first search explores one branch of a graph as far as possible before backtracking.
Effortless Math. “Depth-First Search.” Math Dictionary.



