A Minimum Spanning Tree is a subset of edges in a connected, weighted graph that connects all vertices together without any cycles and with the minimum possible total edge weight.
Click to reveal answer
beginner
What is the main idea behind Kruskal's Algorithm?
Kruskal's Algorithm builds the MST by sorting all edges by weight and adding them one by one to the MST, skipping edges that would form a cycle, until all vertices are connected.
Click to reveal answer
intermediate
Why do we use a Disjoint Set (Union-Find) data structure in Kruskal's Algorithm?
The Disjoint Set helps quickly check if adding an edge will create a cycle by tracking which vertices are already connected, allowing efficient union and find operations.
Click to reveal answer
intermediate
What is the time complexity of Kruskal's Algorithm?
The time complexity is O(E log E), where E is the number of edges, mainly due to sorting edges. Union-Find operations are almost constant time.
Click to reveal answer
beginner
Show the Rust code snippet to sort edges by weight for Kruskal's Algorithm.
edges.sort_by_key(|edge| edge.weight);
This sorts the vector of edges in ascending order by their weight.
Click to reveal answer
What does Kruskal's Algorithm add to the MST first?
ARandom edges
BEdges with the smallest weight
CEdges with the largest weight
DEdges connected to the first vertex only
✗ Incorrect
Kruskal's Algorithm always picks the smallest weight edges first to ensure the total weight is minimized.
Which data structure helps Kruskal's Algorithm avoid cycles?
AStack
BQueue
CDisjoint Set (Union-Find)
DLinked List
✗ Incorrect
The Disjoint Set data structure efficiently tracks connected components to avoid cycles.
What is the stopping condition for Kruskal's Algorithm?
AWhen MST has (V-1) edges, where V is number of vertices
BWhen all edges are added
CWhen the graph is empty
DWhen all vertices have degree 2
✗ Incorrect
The MST is complete when it has exactly one less edge than the number of vertices.
If adding an edge creates a cycle, what does Kruskal's Algorithm do?
ARestarts the algorithm
BAdds the edge anyway
CRemoves a different edge
DSkips the edge
✗ Incorrect
To keep the MST cycle-free, Kruskal's Algorithm skips edges that would create a cycle.
What is the main cost in Kruskal's Algorithm?
ASorting edges
BFinding vertices
CAdding vertices
DPrinting the MST
✗ Incorrect
Sorting edges by weight is the most time-consuming step in Kruskal's Algorithm.
Explain how Kruskal's Algorithm builds a Minimum Spanning Tree step-by-step.
Think about sorting edges and checking cycles before adding.
You got /4 concepts.
Describe the role of the Disjoint Set (Union-Find) data structure in Kruskal's Algorithm.
Focus on how it helps avoid cycles.
You got /4 concepts.
Practice
(1/5)
1. What is the main goal of Kruskal's Algorithm in graph theory?
easy
A. To sort the vertices of a graph
B. To find the minimum spanning tree of a graph
C. To detect cycles in a graph
D. To find the shortest path between two nodes
Solution
Step 1: Understand the purpose of Kruskal's Algorithm
Kruskal's Algorithm is designed to find a subset of edges that connects all vertices with the minimum total edge weight and no cycles.
Step 2: Compare with other graph algorithms
Unlike shortest path algorithms or cycle detection, Kruskal's specifically builds a minimum spanning tree.
Final Answer:
To find the minimum spanning tree of a graph -> Option B
Quick Check:
Minimum Spanning Tree = Kruskal's Algorithm goal [OK]
Hint: Kruskal connects all nodes with least total edge weight [OK]
Common Mistakes:
Confusing MST with shortest path
Thinking it detects cycles only
Assuming it sorts vertices
2. Which Rust data structure is most suitable to efficiently implement the union-find (disjoint set) used in Kruskal's Algorithm?
easy
A. Vec<(usize, usize)>
B. HashMap
C. Vec<usize>
D. LinkedList<usize>
Solution
Step 1: Identify union-find structure needs
Union-find requires quick parent lookup and union operations, best done with an array-like structure where index is node and value is parent.
Step 2: Match Rust data structures
Vec<usize> is a simple array of parents, perfect for union-find. HashMap is slower, LinkedList is inefficient, Vec of tuples is not direct parent mapping.
Final Answer:
Vec<usize> -> Option C
Quick Check:
Union-find uses parent array = Vec<usize> [OK]
Hint: Use Vec for parent array in union-find [OK]
Common Mistakes:
Using HashMap instead of Vec for parent tracking
Choosing LinkedList which is slow for indexing
Using Vec of tuples which is unnecessary
3. What will be the output edges of the MST after running Kruskal's Algorithm on this graph?
Edges with weights:
Pick (1,3,15), then (0,1,10) connects 0,1,3. Next (0,2,6) connects 2. Total edges: 3 edges connecting all 4 nodes.
Step 3: Calculate total weight
Sum = 15 + 10 + 6 = 31. But (0,3,5) and (2,3,4) are skipped to avoid cycles.
Step 4: Check if cycle avoided correctly
Actually, (0,3,5) connects 0 and 3 which are already connected, so skipped. (2,3,4) connects 2 and 3, but 2 is connected to 0, and 3 is connected to 1, so adding (2,3,4) creates cycle, skipped.
Final Answer:
31 -> Option D
Quick Check:
Descending sort picks heavy edges first, total weight = 31 [OK]
Hint: Descending sort picks heavy edges, MST weight increases [OK]
Common Mistakes:
Assuming MST weight stays minimal with descending sort
Adding edges that create cycles
Confusing total weight calculation
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.