instagram

Prim’s Minimum Spanning Tree (MST)

This algorithm to create MST using Prim’s algorithm

See graph related utility and classes here

Algorithm

In Below algorithm we are taking Edge weight using sum of two NodeIds like as per below.

e.setWeight(this.getNodeId() + node.getNodeId());

Output :

Share