Back to Practice Dashboard
DSA SectionEasy
Kruskal
Learn how to solve the 'Kruskal' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function kruskal_mst(V, edges) that takes the number of vertices V and a list of edges edges represented as tuples (u, v, w) where u and v are vertices and w is the edge weight. Find the Minimum Spanning Tree (MST) and return the sum of weights of the edges included in the MST using Kruskal's algorithm.
Constraints
- •1 <= V <= 500
- •0 <= len(edges) <= 1000
Examples
Example 1
Input
V = 4, edges = [(0, 1, 10), (0, 2, 6), (0, 3, 5), (1, 3, 15), (2, 3, 4)]
Output
19
Explanation
MST contains edges (2,3) wt 4, (0,3) wt 5, and (0,1) wt 10. Total weight = 19.
Need a Hint?
Represent graph node connections as an adjacency list/matrix, then use standard BFS or DFS graph traversal.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.