← Back to all activities한국어 →
🧩 Maze Generator Lab

An algorithm
creates a maze on the spot

Starting with a grid completely blocked by walls, the algorithm repeatedly “moves to a randomly chosen unvisited neighboring cell and breaks down the wall” to automatically create a perfect maze. Watch the maze take shape, then see the shortest path from the start (green) to the finish (red).

Algorithm (Depth-First Search): From the current cell, randomly choose an unvisited neighboring cell, break down the wall, and move there. If there is nowhere to go, go back to the previous cell (backtracking). Once every cell has been visited, the maze is complete — a maze made this way always has exactly one path between every pair of cells.
Maze size15 × 15
💡 In graph theory, a structure like this — “branches that split, but with no cycles” — is called a spanning tree. The same concept you saw in the Minimum Spanning Tree Lab is also used to generate mazes.