Graph/mst_prim library

🌿 Prim's Algorithm (Minimum Spanning Tree/Forest)

Builds an MST using a Min-Heap for efficient frontier management.

  • Input: undirected weighted graph adjacency list
  • Time complexity (with Min-Heap): O(E log V)
  • Space complexity: O(V + E)

Returns a list of edges in the MST (or MSF for disconnected graphs).

Functions

primMST<T>(Map<T, List<WeightedEdge<T>>> graph) → List<WeightedEdge<T>>