|
|
|
|
|
by sltkr
4437 days ago
|
|
That code does NOT implement Prim's algorithm on a graph with randomly-weighted edges. Instead it just does a randomized breadth-first search of the area (starting from the corner), which is the same algorithm used for colouring, which is why the radial pattern occurs. For a randomized spanning tree, edges should be generated with a random weight, and Prim's algorithm extracts them from the frontier ordered by weight. This creates a very different tree structure that is much more similar to the uniform spanning tree generated by Wilson's algorithm. (This comment is based on the code from this page: http://bl.ocks.org/mbostock/11159599) |
|
http://weblog.jamisbuck.org/2011/1/10/maze-generation-prim-s...
EDIT: Looks like you’re right! It makes a huge difference if you assign each edge a random weight once, rather than simply pulling a random edge of the frontier. Seems like the reference I used has this bug? Here is a fixed version:
http://bl.ocks.org/mbostock/11159599