Say you want a simple maze on an N by M grid, with one path through, and a good number of dead ends, but that looks "right" (i.e. like someone made it by hand without too many little tiny dead ends and all that). Is there a known way to do this?

# What’s a good algorithm to generate a maze?

algorithmmaze

###### Related Question

- .net – the best algorithm for overriding GetHashCode
- Java – How to detect a loop in a linked list
- Programming theory: Solve a maze
- Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missing
- Generate an integer that is not among four billion given ones
- Ukkonen’s suffix tree algorithm in plain English
- C++ – Image Processing: Algorithm Improvement for ‘Coca-Cola Can’ Recognition
- How to find time complexity of an algorithm
- Python – Representing and solving a maze given an image
- The optimal algorithm for the game 2048

## Best Solution

It turns out there are 11 classic algorithms to generate "perfect" mazes. A maze is perfect if it has one, and only one, solution. Here are some links to each algorithm, in rough order of my preference.

For more info, check out mazelib on GitHub, a Python library implementing all the standard maze generating/solving algorithms.