Java icon indicating copy to clipboard operation
Java copied to clipboard

Feature/kruskal mst

Open prasanth-30011 opened this issue 3 months ago • 1 comments

This PR adds an implementation of Kruskal’s Algorithm for computing the Minimum Spanning Tree (MST) of a weighted undirected graph, addressing Issue #7067.

✔ What’s Included

  • Added KruskalMST.java under com.thealgorithms.greedyalgorithms
  • Added a clean and efficient implementation using:
    • Greedy approach
    • Disjoint Set Union (Union-Find) with path compression
    • Edge class with comparable interface for sorting
  • Added unit tests KruskalMSTTest.java that verify:
    • Correct MST weight for a sample connected graph
    • Correct handling of disconnected graphs (returns -1)

✔ Why This is Useful

  • Kruskal’s Algorithm is a core greedy technique frequently used in:
    • Competitive programming
    • Graph theory education
    • Interview preparation
  • Adds missing MST support to the greedy algorithms library
  • Completes the request made in Issue #7067

🧪 Tests

All tests pass successfully using:

prasanth-30011 avatar Nov 21 '25 06:11 prasanth-30011

Codecov Report

:x: Patch coverage is 96.49123% with 2 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 78.52%. Comparing base (e6c576c) to head (bf8b2d3).

Files with missing lines Patch % Lines
...com/thealgorithms/greedyalgorithms/KruskalMST.java 95.45% 1 Missing and 1 partial :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7088      +/-   ##
============================================
+ Coverage     78.46%   78.52%   +0.05%     
+ Complexity     6746     6744       -2     
============================================
  Files           758      759       +1     
  Lines         22339    22368      +29     
  Branches       4384     4389       +5     
============================================
+ Hits          17528    17564      +36     
+ Misses         4107     4099       -8     
- Partials        704      705       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Nov 21 '25 06:11 codecov-commenter

This pull request has been automatically closed because its workflows or checks failed and it has been inactive for more than 14 days. Please fix the workflows and reopen if you'd like to continue. Merging from main/master alone does not count as activity.

github-actions[bot] avatar Dec 06 '25 03:12 github-actions[bot]