← Back to Examples

Kruskal's Algorithm Explained

Kruskal's builds the cheapest network by always choosing the cheapest connection.

It sorts all edges by weight and adds them one by one, skipping any that would create a loop.

Sorted Edges (by weight):

Edges will appear here after sorting
Click "Start" to see how Kruskal's algorithm works
Currently Checking
Included in MST
Rejected (Would Create Cycle)
Not Yet Processed

Minimum Spanning Tree Complete!

Total Weight: 0

Edges in MST:

Key Concept:

Kruskal's algorithm uses a Union-Find data structure to detect cycles. Think of it as building bridges between islands - we always choose the cheapest bridge that connects two separate islands.

Code Example

Loading code...