Depth-First Search

Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids.

Related concepts

TopicDescription
Breadth-First SearchExplore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph.
GraphsNodes and edges modeling networks, dependencies, and paths.
TreesHierarchical nodes with parent–child links for ordered and nested data.
BacktrackingTry a choice, keep going, and undo it if it fails, used to generate permutations, combinations, and valid layouts.
Topological SortOrder the nodes of a graph so every task comes after everything it depends on, used for scheduling and build order.
Dijkstra's AlgorithmFind the shortest path from a starting node to every other node in a graph where edges have non-negative weights.