Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do these maze generation algorithms produce mazes with different properties?

I was browsing the Wikipedia entry on maze generation algorithms and found that the article strongly insinuated that different maze generation algorithms (randomized depth-first search, randomized Kruskal's, etc.) produce mazes with different characteristics. This seems to suggest that the algorithms produce random mazes with different probability distributions over the set of all single-solution mazes (spanning trees on a rectangular grid).

My questions are:

  1. Is this correct? That is, am I reading this article correctly, and is the article correct?
  2. If so, why? I don't see an intuitive reason why the different algorithms would produce different distributions.
like image 726
templatetypedef Avatar asked Apr 05 '11 01:04

templatetypedef


People also ask

How do maze generation algorithms work?

Maze Generation Based on Randomized DFSThe algorithm starts at a given cell and marks it as visited. It selects a random neighboring cell that hasn't been visited yet and makes that one the current cell, marks it as visited, and so on.

What is a perfect maze?

A perfect maze is a maze where any two cells can be joined by a unique path. In the literature, there exist eleven maze generation algorithms as compiled by Buck in 2015 in his book “Mazes for Programmers”. Each algorithm creates mazes differently. Our aim is to analyze how perfect mazes are generated.


2 Answers

Uh well I think it's pretty obvious different algorithms generate different mazes. Let's just talk about spanning trees of a grid. Suppose you have a grid G and you have two algorithms to generate a spanning tree for the grid:

Algorithm A:

  1. Pick any edge of the grid, with 99% probability choose a horizontal one, otherwise a vertical one
  2. Add the edge to the maze, unless adding it would create a cycle
  3. Stop when every vertex is connected to every other vertex (spanning tree complete)

Algorithm B:

  1. As algorithm A, but set the probability to 1% instead of 99%

"Obviously" algorithm A produces mazes with lots of horizontal passages and algorithm B mazes with lots of vertical passages. That is, there is a statistical correlation between the number of horizontal passages in a maze and the maze being produced by algorithm A.

Of course the differences between the Wikipedia algorithms are more intricate but the principle is the same. The algorithms sample the space of possible mazes for a given grid in a non-uniform, structured way.

LOL I remember a scientific conference where a researcher presented her results about her algorithm that did something "for graphs". The results were statistical and presented for "random graphs". Someone asked from the audience "which distribution of random graphs did you draw the graphs from?" The answer: "uh... they were produced by our graph generation program". Duh!

like image 86
Antti Huima Avatar answered Sep 28 '22 09:09

Antti Huima


Interesting question. Here my random 2c.

Comparing Prim's to, say, DFS, the latter seems to have a proclivity for producing deeper trees simply due to the fact that the first 'runs' have more space to create deep trees with less branches. Prim's algorithm, on the other hand, appears to create trees with more branching due to the fact that any open branch can be selected at each iteration.

One way to ask this would be to look at what is the probability that each algorithm will produce a tree of depth > N. I have a hunch that they would be different. A more formal approach to do proving this might be to assign some weights to each part of the tree and show it's more likely to be taken or attempt to characterize the space some other way, but I'll be hand wavy and guessing it's correct :). I'm interested in what lead to you think it wouldn't be, because my intuition was the opposite. And no, the Wiki article doesn't give a convincing argument.

EDIT

One simple way to see this to consider an initial tree with two children with a total of k nodes e.g.,

*---* ... *
 \--* ... *

Choose a random node as the start and end. DFS will produce one of two mazes, either the entire tree, or the part of it with the direct path from start to end. Prim's algorithm will produce the 'maze' with the direct path from start to end with secondary paths of length 1 ... k.

like image 26
dfb Avatar answered Sep 28 '22 09:09

dfb