🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Count the elements with parent 0
  2. B.Start with n and subtract 1 for every union that actually merges two different sets
  3. C.Count the number of union calls
  4. 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 →