Mst Module
Minimum Spanning Tree (MST) algorithms for finding optimal network connections.
A Minimum Spanning Tree connects all nodes in a weighted undirected graph with the minimum possible total edge weight. MSTs have applications in network design, clustering, and optimization problems.
Available Algorithms
Algorithm |
Function |
Best For |
|---|---|---|
|
Sparse graphs, edge lists |
Properties of MSTs
- Connects all nodes with exactly
V - 1edges (for a graph with V nodes) - Contains no cycles
- Minimizes the sum of edge weights
- May not be unique if multiple edges have the same weight
Example Use Cases
- Network Design: Minimizing cable length to connect buildings
- Cluster Analysis: Hierarchical clustering via MST
- Approximation: Traveling Salesman Problem approximations
- Image Segmentation: Computer vision applications
References
Types
| Type | Description |
|
Represents an edge in the minimum spanning tree. |
Functions and values
| Function or value |
Description
|
||
|
Finds the Minimum Spanning Tree (MST) using Kruskal's algorithm. Returns a list of edges that form the MST. The total weight of these edges is minimized while ensuring all nodes are connected. Time Complexity: O(E log E) where E is the number of edges
Algorithm
Example
Use Cases
Comparison with Prim's Algorithm
Both produce optimal MSTs; choose based on graph density and implementation convenience. val mstEdges: obj
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
|
||
|
Finds the Minimum Spanning Tree (MST) using Prim's algorithm. Returns a list of edges that form the MST. Unlike Kruskal's which processes all edges globally, Prim's grows the MST from a starting node by repeatedly adding the minimum-weight edge that connects a visited node to an unvisited node. Time Complexity: O(E log V) where E is the number of edges and V is the number of vertices Disconnected Graphs: For disconnected graphs, Prim's only returns edges for the connected component containing the starting node (the first node in the graph). Use Kruskal's if you need a minimum spanning forest that covers all components.
Algorithm
Example
Use Cases
Comparison with Kruskal's Algorithm
For dense connected graphs, Prim's is often faster. For sparse graphs or graphs with multiple components, Kruskal's is preferred. val mstEdges: obj
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
|