Challenge - 5 Problems
Kruskal MST Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Kruskal's MST edges
What edges are included in the Minimum Spanning Tree (MST) after running Kruskal's algorithm on the given graph?
DSA C
Edges with weights: (0-1:4), (0-2:3), (1-2:1), (1-3:2), (2-3:4), (3-4:2), (4-5:6) Run Kruskal's MST and list edges in MST in order of selection.
Attempts:
2 left
💡 Hint
Sort edges by weight and pick edges that don't form cycles.
✗ Incorrect
Kruskal's algorithm sorts edges by weight and adds edges that connect new vertices without cycles. The edges (1-2:1), (1-3:2), (3-4:2), (0-2:3), and (4-5:6) form the MST.
🧠 Conceptual
intermediate1:30remaining
Why does Kruskal's algorithm use a disjoint set?
What is the main purpose of using a disjoint set (union-find) data structure in Kruskal's algorithm?
Attempts:
2 left
💡 Hint
Think about how Kruskal avoids cycles when adding edges.
✗ Incorrect
Disjoint set helps track which vertices are connected. It quickly checks if two vertices belong to the same set, preventing cycles.
🔧 Debug
advanced2:30remaining
Identify the error in this Kruskal's MST code snippet
What error will this code cause when running Kruskal's MST?
int parent[5] = {-1, -1, -1, -1, -1};
int find(int x) {
if (parent[x] == -1) return x;
return find(parent[x]);
}
void union_set(int x, int y) {
int xset = find(x);
int yset = find(y);
parent[xset] = yset;
}
// In main, edges are processed and union_set called without checking cycles.
Attempts:
2 left
💡 Hint
Check if union is done only when sets are different.
✗ Incorrect
Union is done without checking if x and y belong to different sets, so cycles can form.
❓ Predict Output
advanced2:00remaining
Output of MST total weight calculation
What is the total weight of the MST after running Kruskal's algorithm on this graph?
Edges:
(0-1:10), (0-2:6), (0-3:5), (1-3:15), (2-3:4)
Attempts:
2 left
💡 Hint
Add weights of edges selected by Kruskal's MST.
✗ Incorrect
Edges selected: (2-3:4), (0-3:5), (0-1:10). Total weight = 4 + 5 + 10 = 19.
🚀 Application
expert2:30remaining
Kruskal's algorithm on a disconnected graph
If Kruskal's algorithm is run on a graph with two disconnected components, what will be the result?
Attempts:
2 left
💡 Hint
Think about how MST applies to disconnected graphs.
✗ Incorrect
Kruskal's algorithm produces a Minimum Spanning Forest, which is MSTs for each disconnected component.