Maze Generation Race Screensaver
The Maze Generation Race screensaver runs three real maze-generation algorithms — recursive backtracker, Prim's and Kruskal's — carving mazes into their own grids live, side by side. It is free, runs in your browser, and ESC exits.
How the Maze Generation Race screensaver works
Each of the three panels runs a real, distinct maze-generation algorithm on its own identical-size grid: recursive backtracking, randomized Prim's, and randomized Kruskal's.
The recursive backtracker carves one long, winding passage at a time, backtracking whenever it hits a dead end.
Prim's and Kruskal's instead grow the maze by repeatedly adding the cheapest available wall-breaking edge, so they fill in more evenly.
Once every cell is connected into a single maze, all three pause briefly, then fresh random mazes begin.
Spanning trees behind every maze
A perfect maze, one with no loops and no sealed-off rooms, is a spanning tree of a grid: every cell is connected to every other by exactly one path. Maze generation is often framed as producing a random spanning tree, and different algorithms are different ways of choosing one. That is why the three panels, given the same grid size, end up with such different textures.
Depth-first search with backtracking carves into a random unvisited neighbour, backtracks at dead ends, and produces mazes with many long corridors and a low branching factor. Randomized Prim’s algorithm starts from one cell and repeatedly opens a random wall on the frontier between the maze and unvisited cells; it is a minimum-spanning-tree algorithm adapted to random edges. Randomized Kruskal’s algorithm puts each cell in its own set and removes walls in random order, only when the two cells are in different sets, merging them as it goes.
Kruskal’s is usually implemented with a disjoint-set (union-find) structure, which makes each check nearly constant time. Both Prim’s and Kruskal’s mazes are biased toward many short dead ends, and Kruskal’s tends to create regular patterns that are fairly easy to solve, so the three panels look distinct even though each result is a spanning tree.
A worked example
The recursive backtracker tends to produce long, twisting corridors with few branches, while Prim's and Kruskal's produce a real, visibly bushier maze with many short dead ends.
Settings & tips
- Accent recolours the freshly carved passages.
- All three algorithms are real, correct, unmodified implementations.
- Fresh random mazes generate automatically once every panel finishes.
Frequently asked questions
- Are these real maze-generation algorithms?
- Yes — real recursive backtracker, Prim's and Kruskal's implementations, each building its own maze live.
- Why do the mazes look so different?
- Each algorithm grows the maze by a genuinely different rule, so their real structure and texture differ.
- Is a key needed?
- No — it is a pure local computation.
- Is it free?
- Yes — free, no download, in your browser.
- What makes a maze perfect?
- A perfect maze has exactly one path between any two cells, with no loops and no unreachable areas. In graph terms it is a spanning tree of the grid.
- Why does depth-first search make longer corridors?
- It keeps extending the current path as long as an unvisited neighbour exists, so it only backtracks at a dead end. The result is a maze with many long corridors and few branches.
- What is union-find and why does Kruskal's use it?
- It is a structure that tracks which cells already belong to the same connected group. Kruskal’s uses it to check quickly whether removing a wall would join two groups or just create a loop.