
Depth-first search
Depth-first search (DFS) is a method for exploring a network or a collection of connected items, like a graph or a maze. Starting from a chosen point, it dives deep along one path, exploring as far as possible before backtracking to explore other routes. Imagine walking through a maze: you pick a route, follow it to the end, then go back to a previous junction to try a different path. DFS systematically explores each branch fully before moving on, making it useful for tasks like finding connected components, solving puzzles, and navigating complex structures efficiently.