0
0
DSA Cprogramming~20 mins

Minimum Spanning Tree Kruskal's Algorithm in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kruskal MST Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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.
A(0-2:3), (1-2:1), (1-3:2), (3-4:2), (4-5:6)
B(1-2:1), (0-1:4), (1-3:2), (3-4:2), (4-5:6)
C(1-3:2), (3-4:2), (0-2:3), (1-2:1), (4-5:6)
D(1-2:1), (1-3:2), (3-4:2), (0-2:3), (4-5:6)
Attempts:
2 left
💡 Hint
Sort edges by weight and pick edges that don't form cycles.
🧠 Conceptual
intermediate
1: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?
ATo find the shortest path between two vertices
BTo store the graph adjacency list
CTo quickly check if adding an edge creates a cycle
DTo sort edges by their weights efficiently
Attempts:
2 left
💡 Hint
Think about how Kruskal avoids cycles when adding edges.
🔧 Debug
advanced
2: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.
AThe code may create cycles because it unions without checking if sets are different
BStack overflow due to infinite recursion in find function
CCompilation error due to missing return type in union_set
DArray index out of bounds accessing parent array
Attempts:
2 left
💡 Hint
Check if union is done only when sets are different.
Predict Output
advanced
2: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)
A25
B19
C20
D15
Attempts:
2 left
💡 Hint
Add weights of edges selected by Kruskal's MST.
🚀 Application
expert
2: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?
AIt will produce a Minimum Spanning Forest containing MSTs for each component
BIt will fail with an error because the graph is not connected
CIt will produce a single MST connecting all vertices including disconnected ones
DIt will only process the first component and ignore the second
Attempts:
2 left
💡 Hint
Think about how MST applies to disconnected graphs.