Depth-First Search
Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids.
Depth-First Search Practice Problems
Easy
3 problems- 32easy
Flood Fill
Change the color of a connected region in an image, starting from one pixel.
- 33easy
Maximum Depth of Binary Tree
Find the number of nodes along the longest path from the root of a tree to a leaf.
- 210easy
Path Sum
Check whether a binary tree has a root-to-leaf path that adds up to a target sum.
Medium
3 problemsHard
2 problemsRelated concepts
| Topic | Description |
|---|---|
| Breadth-First Search | Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph. |
| Graphs | Nodes and edges modeling networks, dependencies, and paths. |
| Trees | Hierarchical nodes with parent–child links for ordered and nested data. |
| Backtracking | Try a choice, keep going, and undo it if it fails, used to generate permutations, combinations, and valid layouts. |
| Topological Sort | Order the nodes of a graph so every task comes after everything it depends on, used for scheduling and build order. |
| Dijkstra's Algorithm | Find the shortest path from a starting node to every other node in a graph where edges have non-negative weights. |