← Quiz: Union-Find (Disjoint Set Union): all 10 questions
Quiz: Union-Find (Disjoint Set Union) · Question 6 of 10
How do you count connected components with DSU?
How do you count connected components with DSU?
- A.Count the elements with parent 0
- B.Start with n and subtract 1 for every union that actually merges two different sets
- C.Count the number of union calls
- D.Take the maximum rank
Answer & explanation
Correct answer: Start with n and subtract 1 for every union that actually merges two different sets
A union between two elements already in the same set does not change the number of groups.
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 →