50ms
Start
End
Exploring
Visited
Solution Path
Algorithm Details
Click Depth-First Search or Breadth-First Search to watch how each algorithm explores the maze differently.
Quick Comparison
- DFS goes deep first, using a stack (LIFO)
- BFS goes wide first, using a queue (FIFO)
- BFS always finds the shortest path
- DFS uses less memory typically
Depth-First Search
DFS explores as far as possible along each branch before backtracking. It uses a stack (Last-In-First-Out) to remember which cells to visit next.
Think of it like exploring a maze by always turning right—you go deep into one path before trying others.
Stack (LIFO)
Cells Visited:
0
Path Length:
-
Stack Size:
0
Breadth-First Search
BFS explores all neighbors at the current depth before moving to cells at the next depth level. It uses a queue (First-In-First-Out).
This guarantees finding the shortest path because it explores all paths of length N before any path of length N+1.
Queue (FIFO)
Cells Visited:
0
Path Length:
-
Queue Size:
0