A disjoint-set data structure is defined as one that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets.
A union-find algorithm is an algorithm that performs two useful operations on such a data structure:
- Find: Determine which subset a particular element is in. This can determine if two elements are in the same subset.
- Union: Join two subsets into a single subset. Here first we have to check if the two subsets belong to the same set. If they belong to the same set, no union is needed.
Applications of Disjoint set Union
- Kruskal's Minimum Spanning Tree
- Job Sequencing Problem.
- Cycle Detection
- Nodes between two vertices in an acyclic Graph
- Tarjan’s off-line LCA
Easy Problems
- Minimum Changes to Make Arrays Identical
- Check if one string can be converted to another
- Smallest vs Largest Component of a graph after each Query
- Equation satisfiability check
- Earliest Moment When Everyone Become Friends
- Number of pairs
- Connecting employees from different companies