The perfect maze
A perfect maze is a maze without loops and without unreachable areas. From every place in it there is exactly one path to any other place. Walter Pullen also calls such mazes simply connected.
The word “perfect” says nothing about beauty or difficulty. A perfect maze can be easy or very hard; it only has to follow these two rules. How to put a number on that is the subject of Measuring a maze.
A maze is a graph
Take a rectangular grid of cells. Every cell is a vertex of a graph. Every place where a wall could stand between two neighbouring cells is a possible edge. Removing a wall turns that possible edge into a real one: a passage.
A maze is then the set of passages, a subgraph of the full grid graph.
A perfect maze is a spanning tree
A spanning tree of a graph is a subgraph that is a tree and includes all of the vertices. “Includes all vertices” is the rule “no unreachable areas”. “Is a tree” is the rule “no loops”. So a perfect maze on a grid is exactly a spanning tree of the grid graph, and maze generation is often described as building a random spanning tree.
Counting passages
A spanning tree of a connected graph with V vertices always has V - 1 edges. For a maze this means:
- a perfect maze of 5 by 5 cells has 24 passages
- a perfect maze of 15 by 15 cells has 224 passages
- a perfect maze of W by H cells has W times H minus 1 passages
The count does not depend on how the maze looks. Whether it has long corridors or many short dead ends, the number of passages is the same.
One more passage, one less passage
Adding just one edge to a spanning tree creates a cycle. In a maze, opening one more wall creates a loop, and the maze is no longer perfect.
Removing any edge from a tree splits it into two parts. In a maze, closing one passage cuts the maze into two parts that can no longer reach each other.
What it means when you walk it
There is exactly one route from the start to the exit, so there is exactly one solution. Any other path ends in a dead end sooner or later.
A perfect maze has no loops of passages, so no wall stands alone as an island: every wall is connected to the outer wall. For such mazes a simple trick works: keep one hand on a wall and walk. You are guaranteed not to get lost and to reach a different exit on the outer wall, if there is one. In a maze with loops, for example with the goal in the centre surrounded by a loop, the same trick can lead you around in circles.
Every maze you can walk on mazeness is perfect, and its start and exit lie on the outer wall. So the hand-on-wall trick always works. It is rarely the fastest way, though.
Count the 24 passages of a 5 by 5 maze