Understanding the True Version of Prim's Algorithm

Learn about the true version of Prim's algorithm, which assigns weights to cells and then chooses cells based on those costs rather than assigning weights to passages.

True Prim’s algorithm

Although the algorithm we are about to implement is called a “true” Prim’s algorithm, it’s still slightly modified. Rather than assigning weights to passages, it assigns weights to cells and then chooses cells based on those costs. This gives us mazes very similar to those from a fully passage-weighted Prim’s algorithm and for significantly less effort. We'll make some changes to the same Prims class we created earlier by adding a new TruePrims class at the bottom. The TruePrims class is highlighted in the code below.

The TruePrims class

Get hands-on with 1400+ tech skills courses.