This guide covers 11 maze generation algorithms. The same page size can feel very different depending on the algorithm. Difficulty is scored out of 10 by solution-path complexity; higher scores usually mean a longer, more winding answer path with more turns.
Aldous-Broder
Unbiased Uses random walks to create unbiased mazes with natural texture and moderate answer complexity.
How it works
Start from any cell, randomly pick a neighbor and move there. If the neighbor is unvisited, carve a passage through the wall between them. Repeat until all cells are visited.
Characteristics
Unbiased generationNatural textureEven path distributionModerate speed
Best for
Ideal for teaching scenarios where a natural maze appearance is preferred over engineered path styles.
Recursive Division
Division Divides open space into rooms and passages, creating a geometric maze with long straight walls.
How it works
Treat the entire area as open space, then recursively add walls to divide it into smaller regions. Each wall gets a randomly placed opening to serve as a passage between rooms.
Characteristics
Strong geometric feelLong straight wallsClear regionsStructured layout
Best for
Great for architectural floor-plan style mazes and scenarios preferring regular geometric layouts.
Cellular Automaton
Organic Creates a more organic, cave-like layout with wider local spaces than traditional corridor mazes.
How it works
Start with a random pattern of walls and passages, then apply survival rules to each cell: based on the number of surrounding walls, decide whether it becomes a wall or passage. Iterate multiple times to form natural cave-like structures.
Characteristics
Organic shapesOpen spacesCave-like textureNon-traditional style
Best for
Perfect for natural cave-like mazes and irregular spatial layouts, often used in game map design.
Eller's Algorithm
Tree-based Generates row by row with efficient set tracking, producing balanced mazes at larger sizes.
How it works
Process the grid row by row, assigning set IDs to cells. Randomly merge adjacent cells of different sets within a row, then for each set randomly choose at least one cell to connect downward. The final row merges all remaining sets.
Characteristics
Row-by-rowMemory efficientBalanced textureStable speed
Best for
Ideal for generating large batches of mazes or very large grids efficiently.
Prim's Algorithm
Tree-based Creates many branches and dead ends, but the main answer path is not always the longest.
How it works
Start from a single cell and maintain a list of frontier walls. Randomly pick a wall from the frontier; if the cell on the other side is unvisited, carve through the wall and add that cell's walls to the frontier.
Characteristics
Rich branchingMany dead endsEven textureStrong randomness
Best for
Great for creating mazes with lots of branches and dead ends that look visually complex.
Wilson's Algorithm
Unbiased Uses loop-erased random walks for unbiased mazes with a naturally distributed path structure.
How it works
Pick a starting cell outside the visited region and perform a random walk. When the walk hits the visited region, carve passages along the entire walked path. If the walk self-intersects, erase the loop and continue.
Characteristics
Unbiased generationLoop-erased walksNatural pathsMathematically elegant
Best for
Suited for readers interested in the mathematical principles or when strictly unbiased mazes are needed.
Growing Tree
Tree-based Blends backtracker-like and Prim-like behavior by changing how active cells are selected.
How it works
Maintain a list of active cells. Each step, pick a cell from the list (the selection strategy is configurable: random, newest, oldest, or a mix), carve to an unvisited neighbor, and add the new cell to the active list. Stop when the list is empty.
Characteristics
Adjustable strategyVaried stylesMixed textureFlexible control
Best for
Ideal for experimenting with different maze styles by tuning the cell selection strategy.
Kruskal's Algorithm
Tree-based Keeps an even texture while often producing a moderately winding answer path.
How it works
Collect all walls into a list and shuffle them randomly. Iterate through the list; if a wall separates two cells belonging to different sets, carve through it and merge the sets. Repeat until all cells belong to the same set.
Characteristics
Even textureGlobal randomnessModerate windingUnion-find structure
Best for
Well-suited for practice scenarios requiring even texture and moderately challenging solution paths.
Hunt and Kill
Tree-based Walks until stuck, then hunts for a new entry point, often creating long and winding main paths.
How it works
Start a random walk from a cell, carving as you go. When you hit a dead end, enter 'hunt' mode: scan the grid row by row for the first unvisited cell adjacent to a visited one, then resume walking from there.
Characteristics
Long main pathWinding routesHunt after dead endsExploratory feel
Best for
Great for high-difficulty practice where long, winding answer paths are desired.
Fractal Maze
Division Builds on recursive subdivision with repeated structure, creating organized layouts with larger-scale detours.
How it works
Recursively divide a large grid into smaller sub-grids, generate a small maze inside each sub-grid independently, then carve connecting passages across sub-grid boundaries, forming a nested hierarchical structure.
Characteristics
Nested hierarchyRepeated structureLarge-scale detoursOrganized feel
Best for
Perfect for structured, hierarchical mazes where large-scale detours add extra challenge.
Recursive Backtracker
Recursive Usually creates the longest and most winding solution path, making it the hardest by answer-path complexity.
How it works
Start from the initial cell, randomly pick an unvisited neighbor, carve through the wall, and move there. Repeat until the current cell has no unvisited neighbors, then backtrack to the previous cell that still has unvisited neighbors.
Characteristics
Longest pathsMany turnsAbundant dead endsBacktracking exploration
Best for
The ultimate choice for maximum difficulty — the longest and most winding answer paths for advanced practice.