← Quiz: Union-Find (Disjoint Set Union): all 10 questions
Quiz: Union-Find (Disjoint Set Union) · Question 4 of 10
What does union by rank (or size) prevent?
What does union by rank (or size) prevent?
- A.Trees growing into long chains, which would make find O(n)
- B.Two sets from ever being merged
- C.Path compression from working
- D.Duplicate elements
Answer & explanation
Correct answer: Trees growing into long chains, which would make find O(n)
Attaching the shorter tree under the taller keeps the height logarithmic even without compression.
Can you get the rest right without peeking?
Take the timed Quiz: Union-Find (Disjoint Set Union) quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →