Skip to content

[FEATURE REQUEST] Add Kruskal’s algorithm #7067

@guillermolara01

Description

@guillermolara01

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions