The MFSET of section 10.2 engineered, beyond the book.
More...
|
| file | ADS/mfset/UnionFind.h |
| | The MFSET of section 10.2 engineered, beyond the book [see MFSet.h]: the forest of the parents in one vector of integers, where a root keeps minus the size of its tree instead of a parent, so that the union by size needs no second vector and a find() touches one array; find() halves the path (every other node on the way is made a child of its grandparent), which needs a single pass, no recursion and no stack, and keeps the bound of the compression with the union by size (Tarjan and van Leeuwen): a sequence of \( m \geq n \) operations on \( n \) elements takes.
|
The MFSET of section 10.2 engineered, beyond the book.
The definitions, the invariants and the costs of the area are in Theory of merge-find sets.
◆ UnionFind
the union by size with path halving
◆ Compression
how find() shortens the path: halving it (every other node on the way made a child of its grandparent, one pass), or compressing it (all the nodes on the way made children of the root, two passes)
| Enumerator |
|---|
| HALVING | half the path under grandparents
|
| FULL | each node under the root
|
◆ Union
how the roots of two trees are joined: the smaller tree under the root of the larger, or the lower rank under the higher
| Enumerator |
|---|
| SIZE | the smaller tree under the root of the larger
|
| RANK | the lower rank under the higher
|