Implementing the Aldous-Broder Algorithm

Learn to implement the Aldous-Broder algorithm in Ruby.

The AldousBroder class

As might be expected, the random walk forms the core of our implementation, repeatedly visiting neighboring cells until no unvisited cells remain. It comes together without any surprises, just as described.

We'll create a new file named aldous_broder.rb. As before, we’ll put the algorithm in its own class so we can reuse it more easily.

Get hands-on with 1200+ tech skills courses.