It is an algorithm used to find the Minimum Spanning Tree(MST) of a graph.
It is a subset of the edges of a given graph that connects all vertices in the graph, without forming any cycles, and with minimum possible total edge weight.
-
struct Edge
: It is used to represent an edge with two vertices (u
,v
) and their respectiveweight
. An overloaded operator<
is used to allow sorting of edges by their weights. -
unionSets
: Merges two disjoint sets containing verticesu
andv
using union by rank.
- Time Complexity: O(ElogE + Eα(V))
- Space Complexity: O(V + E)
E: Number of edges, V: Number of vertices, α: Inverse Ackermann Function