Skip to content

Conversation

@ArpitaHanjagi
Copy link
Contributor

Kruskal’s Algorithm is a greedy algorithm used to find the Minimum Spanning Tree (MST) of a connected, weighted graph. It works by:

Sorting all edges in increasing order of weight.

Picking the smallest edge that doesn’t form a cycle with edges already chosen.

Repeating step 2 until all vertices are connected.

It ensures a spanning tree with minimum total weight.

@ArpitaHanjagi ArpitaHanjagi requested a review from siriak as a code owner October 20, 2025 17:39
Copilot AI review requested due to automatic review settings October 20, 2025 17:39
@ArpitaHanjagi ArpitaHanjagi requested a review from acylam as a code owner October 20, 2025 17:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an implementation of Kruskal's Minimum Spanning Tree (MST) algorithm to the graph algorithms collection. The implementation uses a Union-Find (Disjoint Set Union) data structure to efficiently detect cycles while constructing the MST by iteratively selecting the smallest edges that don't form cycles.

Key changes:

  • Implementation of Kruskal's algorithm with Union-Find optimization (path compression and union by rank)
  • Helper functions for disjoint set operations (make_set, find_set, union_sets)
  • Example usage demonstrating the algorithm on a 4-vertex weighted graph

@siriak siriak merged commit 6f2a72c into TheAlgorithms:master Oct 25, 2025
2 checks passed
Brijesh03032001 pushed a commit to Brijesh03032001/R that referenced this pull request Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants