Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M10832

Depth-First Search

Depth-First Search
DecideHigh supportDecision Science
Included
account_tree

Updated 2026-07-30

Loading revision record…

Summary

In computer science, depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking…

Definition

A traversal/search strategy: go all the way down one path until no further progress is possible, then backtrack and try another path. The counterpart is breadth-first search (exploring all adjacent options first). Scaffold use: clarify the choice between "depth-first" and "breadth-first". Each strategy has its applicable scenarios: - Depth-first: when the solution is likely deep, or when a complete path is needed - Breadth-first: when the solution is likely shallow, or when the shortest path is needed

How to use

Clarify the choice between "depth-first" and "breadth-first". Each strategy has its applicable scenarios: - Depth-first: when the solution is likely deep, or when a complete path is needed - Breadth-first: when the solution is likely shallow, or when the shortest path is needed

Mechanism

DFS: starting from the origin, go as deep as possible along one branch, then backtrack to explore sibling branches upon reaching a leaf; can be implemented with a stack or recursion, space is better than BFS, but does not guarantee finding the shortest path.

Practice

In progress 0/4

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

Cases

  • Maze solving, topological sorting, connected components; backtracking for Sudoku.

Common pitfalls

  • Confusing with BFS (DFS does not guarantee shortest path); not marking visited leads to infinite loops; excessive recursion depth causes stack overflow.
Sources

Source support: Explicit

References currently contain only Wikipedia links; primary sources still need review.

  • link
    en.wikipedia.orghttps://en.wikipedia.org/wiki/Depth-first_searchZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS