This repository contains an implementation of the Disjoint Set Union (DSU) or Union-Find data structure in C++.
- Union by Size
- Path Compression
- Nearly constant time operations - O(4(α)) α - Aplha
- Simple and clean OOP design
- Graph components
- Union-Find data structure
- Optimized merging and parent tracking
DisjoinSet ds(7);
ds.unionBySize(0, 1);
ds.unionBySize(1, 3);
if (ds.ultimateParent(4) == ds.ultimateParent(3))
cout << "Same Component";
else
cout << "Different Components";
- g++ DisjointSet.cpp -o DisjointSet
- ./DisjointSet
Author