Solution: Modified Prim's Algorithm
Understand the solution to the “Modified Prim's Algorithm” challenge.
We'll cover the following...
We'll cover the following...
Solution
Let's execute the following solution code and see how it works:
Press + to interact
C++
Files
class ModifiedPrimsdef self.on(grid, start: grid.random_cell)visited = Set.newfrontier = Set.new([ start ])while frontier.any?cell = frontier.entries.samplefrontier.delete(cell)visited.add(cell)in_neighbors, out_neighbors = cell.neighbors.partition { |n| visited.include?(n) }in_neighbor = in_neighbors.samplecell.link(in_neighbor) if in_neighborfrontier += out_neighborsendgridendend