O'Reilly logo

Mazes for Programmers by Jamis Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing Randomized Kruskal’s Algorithm

To implement this, we’re going to create a new class to represent the state of the algorithm—the collection of information that it will use internally. Once we’ve got this State class written, the rest of Kruskal’s algorithm becomes almost trivial to implement. Don’t take my word for it, though. Watch and see!

As you saw in the previous section, Kruskal’s initially requires that each cell be associated with a unique set. This suggests that, at a minimum, our State class is going to need to track that association. We’ll need a way to query the set that a particular cell belongs to, as well as the list of cells that belong to a given set. Also, the algorithm wants to select random pairs of neighboring ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required