Rollback Union-Find for Offline Connectivity
Answer connectivity queries across a sequence with removals by storing reversible unions and organizing edge lifetimes.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Record the changes that must be undone
Use disjoint-set union with size-based linking and skip compression. A successful union changes one root parent and the size of the surviving root. Put the old values on a stack. A snapshot is a stack length. Reverting to it restores those values in reverse order, including all effects of nested unions. Find takes logarithmic time because sizes at least double along a newly attached component’s history.
Decompose the active times
An edge present from add time \(s\) to removal time \(t\) is active on \([s,t)\). Decompose that interval into disjoint nodes of a segment tree over operation indices. During a depth-first traversal, apply each node’s edges, answer queries at leaves and roll back when exiting the node. The unions on a root-to-leaf path represent precisely the active edges at that time. Each interval uses logarithmically many nodes. The entire sequence must be available beforehand. Segment trees explain the interval decomposition used here.[1][2]