1
Data Structures for Disjoint Sets
2
Disjoint Sets Data Structure
! A dynamic collection S = {S1,S2,…,Sk}
- f disjoint sets.
! Each set Si is identified by a
representative member.
! Operations:
– Make-Set(x): create a new set in S, whose
- nly member is x (assuming x is not
already in one of the sets). – Union(x, y): replace the two sets Sx and Sy that contain x and y, by their union (assuming they are disjoint). – Find-Set(x): find and return the representative of the set containing x.
3
Application: connected components
! Given a graph G=(V,E) compute its
partitioning into connected components. Connected-Components(G=(V,E)): for each vertex v in V Make-Set(v); for each edge e in E if (Find-Set(u) != Find-Set(v)) Union(u, v); Same-Component(u, v): return (Find-Set(u) == Find-Set(v));
4