Maze Generator

Build a perfect maze (one path between any two cells, no loops) on a rectangular grid, with one of three classical algorithms. Recursive backtracker produces long winding corridors, Prim's produces a bushier branching tree, Kruskal's produces a balanced tree with roughly uniform branch lengths everywhere. Optional seed for a reproducible maze, optional solution overlay, and SVG / PNG download. All math runs in your browser — nothing is uploaded.

Cells
Standing walls
Solution length
Solution / max
About the algorithms

A perfect maze is a spanning tree on the grid graph: every cell is reachable from every other, and there is exactly one path between any two cells — so the maze has no loops. The three algorithms differ in the "shape" of that tree.

Recursive backtracker is depth-first: from a starting cell it walks to a random unvisited neighbour, recurses, and backtracks when stuck. The result is long, snaking corridors with occasional sharp turns.

Prim’s is breadth-first with a random frontier: it tracks the set of walls that could be knocked down next, picks one at random, and grows the maze radially. The result is bushier, with shorter branches.

Kruskal’s iterates over a shuffled list of every interior wall and knocks it down if it would join two previously-disconnected regions. The result is a balanced tree where every branch is roughly the same length.

The same seed always produces the same maze, so you can pin a favourite seed and rebuild the same puzzle. The solution is a BFS from the top-left cell to the bottom-right cell.