Visualizing Prim's Algorithm
X

About


Prim's algorithm creates a minimum spanning tree on a weighted graph. Here we use it to make a maze.


After choosing a starting cell, we add all of the cell's neighbor's to a queue. Cells in the queue are shown in green. As cells are added to the queue, the "cost" of connecting them to the maze is assigned a random number.


At each iteration, the cell with the lowest "cost" is added to the maze, its neighbors added to the queue. This process continues until the queue is empty.



Instructions


Click inside the black box to choose a starting cell for your maze. Or click the Random Start button to select a random starting cell.