I was playing around with the recursive backtracking algorithm but it always produces very easy mazes. What algorithm produces the hardest mazes to solve (please include information about braids and biased directions if appropriate)?
-
7Define "hardest". – Oliver Charlesworth Feb 04 '13 at 18:12
-
1Takes the longest time to solve by a human:). – John Feb 04 '13 at 18:45
-
1Ok, but you'd need to convert that to an objective metric before you have a chance of finding an algorithm for it! – Oliver Charlesworth Feb 04 '13 at 20:14
-
1This question is both broad and subjective. There are a slew of different types of mazes. The "most difficult" mazes would be those that a human could never solve, unaided, in their lifetime (like hyper-hyper-mazes that exist in the 4th or higher dimension.) http://www.astrolog.org/labyrnth/algrithm.htm – arkon Jan 02 '16 at 00:01
5 Answers
Quantitatively defining the "difficulty" of a maze isn't easy. So let me be qualitative.
First off, Recursive Backtracker is a "perfect maze" algorithm; it generates mazes with one, and only one, solution. Most work on maze generation has to do with generating perfect mazes, so I will limit my answer to those.
There are many, many variations and off-shoots of maze algorithms. But in effect, there are only 12 basic maze algorithms. I have them listed here in the order that I personally (qualitatively and anecdotally) find to be most-to-least difficult:
- Kruskal's
- Prim's
- Recursive Backtracker
- Aldous-Broder
- Growing Tree
- Hunt-and-Kill
- Wilson's
- Eller's
- Cellular Automaton (Easy)
- Recursive Division (Very Easy)
- Sidewinder (Predictable)
- Binary Tree (Flawed)
There is not a lot of difference in the difficulty of the top four on my list. Sorry about that. Perhaps there is a flaw in your implementation. Most likely, you're just good at doing mazes. Try making them larger.

- 6,325
- 6
- 43
- 60
-
5The assumption of perfect mazes being more difficult is wrong. On a dead end you can backtrack, a maze with loops is much harder to solve if there are relatively view solutions since it will not be so obvious you are walking in circles opposed to walking into a dead end. – Madmenyo Apr 27 '14 at 11:21
-
That's an interesting point. But I have found little information on generating non-perfect mazes, so I amended my answer to show that. – john_science Apr 27 '14 at 15:54
-
Lol, i am actually looking for one. Now i am just remembering when i start to backtrack tiles and cut some walls there later. It somewhat works but it does not feel very clean. – Madmenyo Apr 27 '14 at 17:17
-
I would LOVE to hear about any success you have. Maybe try to start with Hilbert Curves: http://people.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-2_themes-hilbert-sec.html, or this person has a slow, but possibly functional approach: http://www.michaelchaney.com/2014/03/unicursal-mazes/ – john_science Apr 27 '14 at 19:23
-
1I had the same problem, I was using backtracking and kept ending up with a pretty simple maze to solve and after trying reading all the answers I tried out prims and kruskals and turns out your list is pretty correct and the kruskal implemented maze seemed to be the most challenging or "difficult" The implementations can be found here in case anyone is interested [Maze](https://github.com/abhyudayasrinet/Maze/blob/master/src/com/ggwp/maze/MazeGenerator.java) – otaku Feb 11 '15 at 15:57
-
1Aldous-Broder and Wilson's both generate uniform spanning trees, which means that their outputs are effectively identical. – Daniel M. Sep 14 '15 at 01:54
-
1@DanielM. That's an interesting point. Perhaps I've never seen an implementation of Wilson's that I thought produced particularly hard/interesting mazes. While they might both be centered around USTs, they are different algorithms and the end results I've seen seem a bit different. But I will play around with them and see if perhaps I was wrong. – john_science Sep 14 '15 at 14:46
Whilst not a direct answer, this article on visualizing maze generation algorithms is a must-watch.

- 38,490
- 8
- 97
- 133
-
1
-
3Seriously? Sum up a visualization? Would you like a text description of each visualization? – Ian Mercer Jan 04 '16 at 06:40
-
1
Depth-first search can produce very complex mazes. Here is an open-source C++ implementation: https://github.com/corporateshark/random-maze-generator
Try setting ImageSize
to 4096 and NumCells
to 2047. The result will be pretty tough.

- 24,894
- 13
- 106
- 174
flood fill algorithms is what IEEE recommend.
There are many versions of this algorithm.
I google an implemantion for the flood fill algorithm.
but I did not find implemantion

- 304
- 3
- 14