The Lab · Kruskal, 1956 · Prim, 1957 · Wilson, 1996

Making Mazes

A perfect maze has exactly one way between any two spots. There are lots of ways to carve one, and each leaves its own fingerprints.

Try this

Carve the same size maze with the recursive backtracker, then with Prim's, and look at the dead-end count each time. The backtracker makes long rivers with few branches; Prim's makes a bush full of short dead ends. Tick Colour by distance from the start to see the difference at a glance.

Watch Kruskal's knock down walls all over the grid while coloured islands grow and merge. Slow Wilson's right down and watch its wandering walk rub out every loop it makes. Try Binary tree and Sidewinder and spot the long straight corridors along the edges. Then print a big one, with the solution on a second page, and hand it to a friend. Every maze has a seed, so a link brings back exactly the same maze. Or let a computer solve it in How to Search.

Where it came from

A perfect maze is what mathematicians call a spanning tree: a set of passages that joins every cell, with no loops. So any way of building a spanning tree is a way of building a maze. Joseph Kruskal published his method in 1956 and Robert Prim his in 1957, both for finding the cheapest way to connect a network. Give every wall a random cost and they become maze makers.

Some methods are fairer than others. David Aldous and Andrei Broder showed, around 1989 and 1990, that a plain random walk builds every possible spanning tree with exactly the same chance. In 1996 David Wilson found a faster way with the same perfect fairness: loop-erased random walks. In 2015 Jamis Buck's book Mazes for Programmers brought many of these methods to a wide audience.

Computers are not the only maze makers. Dave Phillips has drawn mazes by hand for decades, for puzzle magazines and for dozens of books. For his best, try The Zen of the Labyrinth: Mazes for the Connoisseur. Signed copies of his maze books were prizes in Infinite Search Space's SameGame contest.

Links