Java icon indicating copy to clipboard operation
Java copied to clipboard

[FEATURE REQUEST] Add Kruskal’s algorithm

Open guillermolara01 opened this issue 3 weeks ago • 1 comments

What would you like to Propose?

Add Kruskal’s algorithm to the Greedy section of the algorithms.

About the idea:

Kruskal’s algorithm finds a Minimum Spanning Tree (MST) by building it edge by edge, always choosing the cheapest edge that doesn’t create a cycle.

How it works:

  • Sorting all edges in the graph from smallest weight to largest.
  • Starting with an empty set of edges for the MST.
  • Going through the sorted edges one by one:
    • Adding the edge if it connects two nodes that aren’t already connected (i.e., it doesn’t form a cycle).
    • Skipping it if it would create a cycle. The loop continues until we've added (V − 1) edges, where V is the number of vertices.

Implementation Details

  • Directory: src/main/java/com/thealgorithms/greedyalgorithms/
  • Filename: KruskalAlgorithm.java
  • Unit tests using JUnit

Issue details

Name: Kruskal's Algorithm

Description:

Kruskal’s algorithm finds a Minimum Spanning Tree (MST) by building it edge by edge, always choosing the cheapest edge that doesn’t create a cycle.

Additional Information

I will work on this and have it delivered soon!

guillermolara01 avatar Nov 14 '25 01:11 guillermolara01