How to solve any maze

VeritasiumAbout 3 min readSep 18, 2025Watch original
THE SUMMARYAI-generated

Key Concepts:

  • Wall Following Algorithm
  • Depth-First Search (DFS)
  • Breadth-First Search (BFS)
  • Flood Fill Algorithm
  • Shortest Path Algorithms
  • Maze Solving Strategies
  • Micro Mouse Competition

Maze Solving Algorithms Explained

1. Wall Following Algorithm:

  • Description: A simple strategy where the solver keeps one hand on a wall (either left or right) and follows it.
  • Application: Effective in simple mazes without freestanding walls or goals far from the edges.
  • Example: The video mentions a "simple wall following mouse" winning a competition.
  • Limitation: Fails in mazes with detached walls or when the goal is not near the outer walls.

2. Depth-First Search (DFS):

  • Description: Explores as far as possible along each branch before backtracking.
  • Process:
    1. Choose a path at an intersection.
    2. Proceed until a dead end or loop is reached.
    3. Backtrack to the last intersection.
    4. Try a different path.
  • Analogy: Described as the strategy a "headstrong mouse" might use.
  • Advantage: Will eventually find the goal.
  • Disadvantage: May not find the shortest path.

3. Breadth-First Search (BFS):

  • Description: Explores all the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level.
  • Process:
    1. Explore one branch of an intersection to the next intersection.
    2. Go back and check the path skipped.
    3. Move on to the next layer of intersections.
  • Advantage: Guarantees finding the shortest path.
  • Disadvantage: Involves significant backtracking and re-running paths, which can be time-consuming.

4. Exhaustive Search:

  • Description: Searching every possible path in the maze.
  • Example: The video mentions searching all 256 cells of a maze.
  • Limitation: Often less efficient than other algorithms, even for relatively small mazes.

5. Flood Fill Algorithm:

  • Description: An algorithm that iteratively "fills" a maze with distance values from the goal, allowing the solver to follow the path of least resistance.
  • Process:
    1. The mouse draws the shortest path to the goal and goes.
    2. The mouse marks down the wall and updates the new shortest path to the goal when the optimistic plan hits a wall.
    3. The mouse follows the trail of decreasing numbers down to zero to travel optimistically.
    4. The mouse updates the numbers on their map to reflect the new shortest distance to the goal whenever they hit a wall.
  • Underlying Mechanism: The algorithm marks the distance from every square in the maze to the goal.
  • Analogy: Described as "flooding the maze with water."
  • Advantage: Efficient, especially when combined with the return trip.
  • Application: The most popular micro mouse strategy.
  • Optimization: The mouse treats its return trip as a new journey to further search the maze.

Micro Mouse Competition Context:

  • Micro mice need to return to the start after reaching the goal.
  • The flood fill algorithm is optimized by using the return trip to gather more information about the maze.
  • The combination of the initial run and the return trip makes it "extremely likely" that the mouse will discover the shortest path.
  • The algorithm efficiently avoids irrelevant areas of the maze.

Conclusion:

The video explains various maze-solving algorithms, highlighting their strengths and weaknesses. While simple methods like wall following have limited applicability, algorithms like depth-first search and breadth-first search offer more robust solutions. However, the flood fill algorithm, particularly when optimized for the micro mouse competition context, provides an efficient and effective approach by combining pathfinding with learning during both the initial run and the return trip.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.