ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RollbackUnionFind.h File Reference

The MFSET of section 10.2 with the undo of its merges, beyond the book [see MFSet.h], and on it the connectivity of a graph whose edges come and go, when all the changes and the questions are known in advance (see Undo of the merges and offline connectivity). More...

#include "ADS/Contract.h"
#include <cstddef>
#include <vector>
#include "ADS/mfset/impl/RollbackUnionFind.tpp"

Go to the source code of this file.

Classes

class  ADS::RollbackUnionFind
 the union of disjoint sets of \( [ 0 , n ) \) by rank, with no compression, whose merges can be undone More...
struct  ADS::ConnectivityOp
 an operation on a graph whose edges come and go More...

Namespaces

namespace  ADS

Functions

std::vector< int > ADS::offlineConnectivity (int n, const std::vector< ConnectivityOp > &ops)
 the answers to the questions of ops on \( n \) nodes, in their order: 1 or 0 for CONNECTED, the number of components for COMPONENTS

Detailed description

The MFSET of section 10.2 with the undo of its merges, beyond the book [see MFSet.h], and on it the connectivity of a graph whose edges come and go, when all the changes and the questions are known in advance (see Undo of the merges and offline connectivity).

RollbackUnionFind is the forest of the parents with the union by rank and without any compression of the paths, so that find() costs \( O( \log n ) \) in the worst case (Lemma 2 of Unions by size and by rank); each merge() changes at most three words (a parent, a size and a rank), which a record on a stack keeps, undo() puts them back in \( O( 1 ) \), and rollback( t ) undoes the merges back to the checkpoint \( t \), the number of merges done when checkpoint() gave it (a merge of two elements already together leaves a record too, so that the checkpoints count the calls). The space is \( 12 n \) bytes and 12 bytes per record.

offlineConnectivity() answers, for a sequence of \( k \) operations on \( n \) nodes, each the insertion of an edge, its deletion or a question (whether two nodes are connected, or how many components there are), the questions in their order, by the segment tree over the times of Lemma 4 of Undo of the merges and offline connectivity, in \( O( k \log k \log n ) \) expected time (the hash table that pairs each deletion with its insertion) and \( O( k \log k ) \) space.

The contracts [see Contract.h]: \( n \ge 0 \), the elements in \( [ 0 , n ) \); a rollback goes back to a checkpoint not beyond the merges done, and an undo() needs one; a deletion in offlineConnectivity() needs the edge alive (of parallel edges, the last inserted dies first), and a loop \( [ u , u ] \) is allowed and joins nothing. The invariant is that the parents make a forest of count() trees, the rank of each root bounding its height, and that the records undo the merges. The operations are defined in RollbackUnionFind.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 10.2, https://algoritmicamente.it/materiali/libro/capitoli/cap10.pdf
H. Mannila, E. Ukkonen, The set union problem with backtracking, Proceedings of ICALP, LNCS 226, 236-243, 1986, doi:10.1007/3-540-16761-7_73
J. Westbrook, R. E. Tarjan, Amortized analysis of algorithms for set union with backtracking, SIAM Journal on Computing 18(1), 1-11, 1989, doi:10.1137/0218001
A. Apostolico, G. F. Italiano, G. Gambosi, M. Talamo, The set union problem with unlimited backtracking, SIAM Journal on Computing 23(1), 50-70, 1994, doi:10.1137/S0097539789173597
D. Eppstein, Offline algorithms for dynamic minimum spanning tree problems, Journal of Algorithms 17(2), 237-250, 1994, doi:10.1006/jagm.1994.1033
R. Peng, B. Sandlund, D. D. Sleator, Optimal offline dynamic 2,3-edge/vertex connectivity, Proceedings of WADS, LNCS 11646, 553-565, 2019, doi:10.1007/978-3-030-24766-9_40
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa