Implement Union-Find and track components | Motive
|Home/Coding & Algorithms/Motive
Implement Union-Find and track components
Motive
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
0
0
Implement a Disjoint Set Union (Union-Find) data structure with union by rank and path compression. Design the API to support union(a, b), connected(a, b), and count() for the number of connected components. Given n nodes (0..n-
and a stream of operations, return the result of each connected query and the component count after each union. Analyze time and space complexity and discuss thread-safety considerations.