Algorithms and Data Structures · Middle · Question 34 of 75
What does a union-find (disjoint set) structure support?
- ✓Correct answer: Merging sets and checking if two items share a set
- 2Sorting elements and finding the k-th smallest
- 3Storing key-value pairs with fast range queries
Explanation
union(a, b) merges two groups and find(a) returns a group's representative. With path compression and union by rank both are nearly O(1). Typical uses: connected components, Kruskal's MST, "are these accounts the same person?"