Union-Find (Disjoint Sets)

Danny Pham
4 min readApr 21, 2021

Scenario

Consider a social network site where people can become friends with one another. Friendship groups can be formed (person A is friends with person B, person B is friends with person C, person C is friends with person Z → the friendship group holds {A, B, C, Z}). You may want to see if you’re in the same friendship group with a specific person.

Friendship groups are basically graphs where each node represents a person and each edge represents a friendship. Each individual friendship group is basically a connected component.

--

--