minimumSpanningTree

fun minimumSpanningTree(): Pair<Double, Graph>

Computes the Minimum Spanning Tree (MST) of the graph using Prim's algorithm.

If the graph is unweighted, it is first converted to a weighted graph with default edge weights.

Return

A pair containing the total weight of the MST and the graph representing the MST.

Throws

IllegalStateException

If the graph is empty or not fully connected.