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:

  1. Sort all edges by weight (ascending).
  2. 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.
  3. 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 Object
trait Matchable
class Any
Self type
Kruskal.type

Members list

Value members

Concrete methods

def mst[V, E : Ordering](graph: UndirectedGraph[V, E]): Seq[Edge[V, E]]

Computes the MST of graph using Kruskal's algorithm.

Computes the MST of graph using Kruskal's algorithm.

Type parameters

E

the edge weight type; must be Ordering.

V

the vertex attribute type.

Value parameters

graph

the undirected weighted graph.

Attributes

Returns

a TraversalResult[V, Edge[V, E]] mapping each vertex to its incident MST edge (None for isolated vertices or the arbitrary first vertex processed).