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 the smallest edge to the tree if it doesn't create a cycle, repeating until all vertices are connected.
Click to reveal answer
intermediate
How does Kruskal's algorithm check for cycles when adding edges?
It uses a data structure called Union-Find (Disjoint Set) to efficiently check if two vertices belong to the same connected component, preventing cycles.
Click to reveal answer
beginner
Why does Kruskal's algorithm sort edges by weight first?
Sorting edges by weight ensures that the algorithm always picks the smallest available edge, which helps build the MST with the minimum total weight.
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 the edges. Union-Find operations are almost constant time.
Click to reveal answer
What does Kruskal's algorithm use to avoid cycles when adding edges?
ADepth-first search
BStack
CBreadth-first search
DUnion-Find data structure
✗ Incorrect
Kruskal's algorithm uses the Union-Find data structure to efficiently check if adding an edge creates a cycle.
What is the first step in Kruskal's algorithm?
ACreate a cycle
BPick a random vertex
CSort all edges by weight
DRemove the heaviest edge
✗ Incorrect
Kruskal's algorithm starts by sorting all edges from smallest to largest weight.
Which of the following best describes the output of Kruskal's algorithm?
AA tree connecting all vertices with minimum total edge weight
BA path visiting all vertices exactly once
CA graph with maximum number of edges
DA disconnected set of vertices
✗ Incorrect
The output is a minimum spanning tree connecting all vertices with the smallest total edge weight.
If adding an edge creates a cycle, what does Kruskal's algorithm do?
ASkips that edge
BAdds the edge anyway
CRemoves a vertex
DRestarts the algorithm
✗ Incorrect
Kruskal's algorithm skips edges that would create cycles to maintain a tree structure.
What type of algorithm is Kruskal's algorithm?
ADynamic programming
BGreedy algorithm
CDivide and conquer
DBacktracking
✗ Incorrect
Kruskal's algorithm is a greedy algorithm because it picks the smallest edge available at each step.
Explain how Kruskal's algorithm builds a minimum spanning tree step-by-step.
Think about sorting edges and avoiding cycles.
You got /4 concepts.
Describe why the Union-Find data structure is important in Kruskal's algorithm.
Consider how to know if two vertices are already connected.
You got /3 concepts.
Practice
(1/5)
1. What is the main goal of Kruskal's algorithm in graph theory?
easy
A. To detect if a graph contains cycles
B. To find the shortest path between two vertices
C. To find the minimum spanning tree connecting all vertices without cycles
D. To sort vertices by their degree
Solution
Step 1: Understand the purpose of Kruskal's algorithm
Kruskal's algorithm is designed to connect all points in a graph with the smallest total edge weight without forming any loops.
Step 2: Compare with other graph problems
Unlike shortest path or cycle detection alone, Kruskal's focuses on building a minimum spanning tree, which is a tree connecting all vertices with minimal cost.
Final Answer:
To find the minimum spanning tree connecting all vertices without cycles -> Option C
Quick Check:
Kruskal's goal = minimum spanning tree [OK]
Hint: Kruskal's connects all points cheaply without loops [OK]
Common Mistakes:
Confusing minimum spanning tree with shortest path
Thinking it detects cycles only
Assuming it sorts vertices instead of edges
2. Which of the following is the correct first step in Kruskal's algorithm?
easy
A. Pick any vertex and start a depth-first search
B. Sort all edges in increasing order of their weights
C. Remove all vertices with degree 1
D. Sort vertices by their labels alphabetically
Solution
Step 1: Identify the initial step of Kruskal's algorithm
Kruskal's algorithm begins by sorting all edges by their weight from smallest to largest to ensure the cheapest edges are considered first.
Step 2: Eliminate incorrect options
Depth-first search and vertex removal are not part of Kruskal's initial steps, and sorting vertices alphabetically is irrelevant.
Final Answer:
Sort all edges in increasing order of their weights -> Option B
Quick Check:
First step = sort edges by weight [OK]
Hint: Always start by sorting edges by weight ascending [OK]
Common Mistakes:
Sorting vertices instead of edges
Starting with a search instead of sorting
Removing vertices prematurely
3. Given the edges with weights: (A-B: 1), (B-C: 4), (A-C: 3), (C-D: 2), what edges will Kruskal's algorithm select for the minimum spanning tree?
medium
A. (A-C), (B-C), (C-D)
B. (A-B), (C-D), (B-C)
C. (A-B), (C-D), (A-C), (B-C)
D. (A-B), (C-D), (A-C)
Solution
Step 1: Sort edges by weight
Edges sorted: (A-B:1), (C-D:2), (A-C:3), (B-C:4).
Step 2: Add edges without creating cycles
Add (A-B), then (C-D). Adding (A-C) connects A and C without cycle. Adding (B-C) would create a cycle, so skip it.
Final Answer:
(A-B), (C-D), (A-C) -> Option D
Quick Check:
Edges chosen = smallest weights without cycles [OK]
Hint: Pick edges from smallest weight, skip if cycle forms [OK]
Common Mistakes:
Including all edges regardless of cycles
Choosing heavier edges before lighter ones
Not checking for cycles before adding edges
4. In Kruskal's algorithm, what is the common error if the algorithm adds an edge that creates a cycle?
medium
A. The disjoint set structure is not used or updated correctly
B. Edges are not sorted by weight
C. Vertices are not labeled properly
D. The graph is directed instead of undirected
Solution
Step 1: Understand cycle prevention in Kruskal's
Kruskal's algorithm uses a disjoint set (union-find) data structure to track connected components and avoid cycles.
Step 2: Identify the cause of cycle creation
If an edge creates a cycle, it means the disjoint set was not used or updated properly to detect that the two vertices are already connected.
Final Answer:
The disjoint set structure is not used or updated correctly -> Option A
Quick Check:
Cycle error = faulty disjoint set use [OK]
Hint: Use disjoint sets to detect cycles before adding edges [OK]
Common Mistakes:
Ignoring disjoint set updates
Assuming sorting fixes cycles
Confusing graph direction with cycle detection
5. You have a graph with edges: (X-Y: 2), (Y-Z: 2), (X-Z: 3), (Z-W: 1), (W-X: 4). Using Kruskal's algorithm, which set of edges forms the minimum spanning tree?