Kruskal’s Algorithm – Easy DSA Notes
1. What is Kruskal’s Algorithm?
Kruskal’s Algorithm is a greedy algorithm used to find the Minimum Spanning Tree (MST) of a
connected, weighted, undirected graph.
2. Minimum Spanning Tree (MST)
A spanning tree that connects all vertices with the minimum possible total edge weight and contains
no cycles.
3. Key Idea (Very Easy)
Sort all edges by increasing weight and keep adding the smallest edge that does not form a cycle.
4. Steps of Kruskal’s Algorithm
Step 1: Sort all edges in increasing order of weight.
Step 2: Pick the smallest edge and check if it forms a cycle.
Step 3: If no cycle is formed, include the edge in MST.
Step 4: Repeat until MST contains (V - 1) edges.
5. Cycle Detection
Cycle detection is done using Disjoint Set (Union-Find) data structure.
6. Data Structures Used
- Edge list
- Disjoint Set (Union-Find)
7. Time Complexity
Sorting edges: O(E log E)
Overall complexity: O(E log E)
8. Important Points
- Works on connected, undirected, weighted graphs
- Greedy algorithm
- MST contains exactly (V - 1) edges
9. Applications
- Network design (cables, pipelines)
- Road construction
- Minimum cost connections