← Back to Algorithms
DFS & BFS Maze Traversal
A visualization of Depth-First and Breadth-First Search, two fundamental algorithms for traversing graphs and trees, applied to a maze.
Depth-First Search (DFS)
DFS explores as far as possible along each branch before backtracking. It uses a stack (or recursion) to keep track of nodes to visit. Think of it as a single explorer diving deep into a tunnel until they hit a dead end, then backtracking to try another path.
Breadth-First Search (BFS)
BFS explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. It uses a queue to keep track of nodes to visit. Imagine this as a wave expanding outwards from the starting point, exploring all nearby options first.