Medium Data Structures Advanced Structures
What is Union-Find (Disjoint Set Union) and its optimizations?
Answer
Union-Find tracks elements partitioned into disjoint sets, supporting union (merge sets) and find (determine set membership). Basic implementation uses parent array with tree structure. Optimizations: Path Compression (during find, make all nodes point directly to root) and Union by Rank (attach smaller tree under root of larger tree). Together, they achieve near-O(1) amortized time - specifically O(alpha(n)) where alpha is inverse Ackermann function.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Software Engineer Algorithm Developer Competitive Programmer