Algorithm


Kruskal's Algorithm:

  1. Sort all the edges in non-decreasing order of their weight.
  2. Initialize an empty set to store the edges of the Minimum Spanning Tree (MST).
  3. For each edge in the sorted list:
    1. Check if adding the edge to the MST forms a cycle using a union-find data structure.
    2. If it does not form a cycle, add the edge to the MST.
  4. Repeat until the MST contains exactly (V - 1) edges, where V is the number of vertices in the graph.

Example:

Kruskal's Algorithm Example

Fig. 1: Step-by-Step Process of Kruskal's Algorithm

Note: Kruskal's Algorithm is efficient for sparse graphs and uses a union-find data structure to detect cycles.