Kruskal
com.phasmidsoftware.gryphon.traverse.Kruskal
object Kruskal
Computes the minimum spanning tree of an undirected weighted graph using Kruskal's algorithm. See Krusal's Algorithm.
The complexity of this implementation is O(E log E), where E is the number of edges because the time is dominated by the sorting step.
The algorithm:
- Sort all edges by weight (ascending).
- Iterate through edges; for each edge (u, v, w): if u and v are not yet connected, add the edge to the MST and union their components.
- Stop when N-1 edges have been added (MST is complete).
Uses WeightedUnionFind for O(log n) connectivity queries and unions. Somewhat wastefully sorts all edges before starting. A priority queue would be more efficient in the average case, but would not improve the worst case.
NOTE: intended for undirected weighted graphs only.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Kruskal.type
Members list
In this article