PrevNext
Very Frequent
 0/13

Depth First Search (DFS)

Authors: Siyong Huang, Andrew Wang, Jason Chen, Benjamin Qi

Recursively traversing a graph.

DFS in Undirected Graphs

Resources
CSAup to but not including "More about DFS"
CPHexample diagram + code

A connected component is a maximal set of connected nodes in an undirected graph. In other words, two nodes are in the same connected component if and only if they can reach each other via edges in the graph.

Focus Problem – read through this problem before continuing!

For example, the goal of this problem above is to add edges such that the entire graph is a single connected component.

Solution - Building Roads

Solution

Optional: Adjacency List Without an Array of Vectors

See here.

Problems

StatusSourceProblem NameDifficultyTagsSolutionURL
SilverEasy
Show Tags

DFS

External Sol
SilverEasy
Show Tags

DFS

SilverEasy
Show Tags

DFS

External Sol
SilverEasy
Show Tags

Tree, DFS

KattisEasy
Show Tags

DFS

SilverNormal
Show Tags

Sorting

External Sol
GoldNormal
Show Tags

DFS, Binary Search

SilverNormal
Show Tags

DFS, Binary Search

KattisVery Hard
Show Tags

DFS, Binary Search

DFS in Directed Graphs

StatusSourceProblem NameDifficultyTagsSolutionURL
CSESEasy
CCONormal
SilverHardExternal Sol

Module Progress:

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!

Give Us Feedback on Depth First Search (DFS)!

PrevNext