Depth First
Search
Cracking
Data Secrets!
What is Depth
First Search?
Depth First Search (DFS)
explores nodes by going deep into branches first.
How Does
DFS Work?
DFS
uses a stack to keep
track of nodes,
marking them as visited.
Read More
Starting the
Search
Begin at a selected
node,
push it onto the
stack,
and mark it
visited
Exploring
Neighbors
Pop the top node, visit its
unvisited neighbors,
and push them onto the stack.
Backtracking
If a node has no
unvisited neighbors,
backtrack to explore other paths.
Applications
of
DFS
DFS
is used in pathfinding,
puzzle-solving,
and network analysis.
Complexity of
DFS
Time complexity is
O(V+E)O(V+E),
where
VV
is vertices and
EE
is edges.