The Lab
Original — built for the Lab

Labyrinth

Every maze here has exactly one path between any two cells, and exactly one fewer corridor than it has cells. Yet the generator decides everything else: the backtracker leaves about 10% dead ends and long winding rivers, Wilson's uniform maze about 30% and short stubby twigs. Watch them carve, flood them with breadth-first search, race two solvers, or walk one yourself.

Graph theorySpanning treesSearch algorithmsCanvasGame
After Kruskal (1956), Prim (1957), Moore's breadth-first search (1959), Eller (1982) and David Wilson's loop-erased random walk (1996)
Loading demo…

A maze with no loops and no sealed rooms is what mathematicians call a spanning tree of the grid: every cell connected, no cycles. That one sentence fixes more than it seems to. A tree on n cells always has exactly n − 1 corridors, there is exactly one route between any two cells, and knocking out any single wall on that route would open a second one. The Corridors tile checks the first of those claims on every maze you make, and it never misses by one.

What the definition does not fix is the maze's character, and that is the surprise. Every generator here produces a perfect maze, but each makes a different kind. The recursive backtracker digs like a mole, going as far as it can before it retreats, so it leaves long rivers and few dead ends. Prim's grows like a crystal from a seed and leaves a bramble of short spurs. Kruskal's starts with every cell its own island and joins them at random, so you can watch coloured regions merge. Wilson's sends out random walks that erase their own loops, and is the only one here that picks uniformly from every possible maze — the neutral reference. Eller's needs only one row of memory at a time. Recursive division starts from an empty hall and drops walls in.

Then light it up. Breadth-first search spreads from the entrance like a ripple, one step of distance at a time, and the colour of each cell is how far it is from the start: the rainbow is the maze's distance field. When the wave touches the goal, the shortest route is already known, and it appears as a gold ribbon. Move the goal and the ribbon re-snaps. Race A* against BFS and the heuristic saves work; race the wall follower in a braided maze with loops and it can circle an island forever.

The same structures run real systems. Spanning trees keep network switches from forwarding packets in circles, Kruskal's and Prim's algorithms lay out cheapest-possible cable and pipe networks, BFS finds the fewest hops in social graphs and routers, and A* steers characters through nearly every video game. Wilson's uniform trees turn up in statistical physics, where the same random walks describe how polymers and electrical networks behave.

Next in the Lab
No Two AlikeOpen

Snow crystals grow live from a single frozen seed — six perfect arms, no blueprint. Pick a sky on Nakaya's diagram and grow your own.