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

The MFSET of section 10.2 with the undo of its merges, beyond the book, 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...

Files

file  ADS/mfset/RollbackUnionFind.h
 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).

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...

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, 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).

The definitions, the invariants and the costs of the area are in Theory of merge-find sets.

Function documentation

◆ offlineConnectivity()

std::vector< int > ADS::offlineConnectivity ( int n,
const std::vector< ConnectivityOp > & ops )
inlinenodiscard

the answers to the questions of ops on \( n \) nodes, in their order: 1 or 0 for CONNECTED, the number of components for COMPONENTS

In pseudocode (the divide and conquer of Eppstein on the times, beyond the book; it is correct by Lemma 4 of Undo of the merges and offline connectivity), with \( q( t ) \) the number of the questions before the time \( t \) and \( L( x ) \) the edges of the node \( x \) of the segment tree:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{offlineConnectivity}( n , \mathit{ops} ) \cr 2 & \quad \textbf{foreach}\ \text{edge } e \text{ alive on } [ s , t ) \ \textbf{do}\ \mathrm{add}( 1 , [ 0 , q ) , [ q( s ) , q( t ) ) , e ) \cr 3 & \quad \mathrm{visit}( 1 , [ 0 , q ) );\ \textbf{return} \ \text{the answers} \cr 4 & \textbf{procedure}\ \mathrm{add}( x , [ a , b ) , [ s , t ) , e ) \cr 5 & \quad \textbf{if}\ [ s , t ) \cap [ a , b ) = \emptyset \ \textbf{then}\ \textbf{return} \cr 6 & \quad \textbf{if}\ [ a , b ) \subseteq [ s , t )\ \textbf{then} \ L( x ) \gets L( x ) \cup \{ e \};\ \textbf{return} \cr 7 & \quad c \gets \lfloor ( a + b ) / 2 \rfloor;\ \mathrm{add}( 2 x , [ a , c ) , [ s , t ) , e );\ \mathrm{add}( 2 x + 1 , [ c , b ) , [ s , t ) , e ) \cr 8 & \textbf{procedure}\ \mathrm{visit}( x , [ a , b ) ) \cr 9 & \quad c_0 \gets \mathrm{checkpoint}() \cr 10 & \quad \textbf{foreach}\ [ u , v ] \in L( x )\ \textbf{do} \ \mathrm{merge}( u , v ) \cr 11 & \quad \textbf{if}\ b - a = 1\ \textbf{then}\ \text{answer the} \text{ question } a \text{ by } \mathrm{find}() \cr 12 & \quad \textbf{else}\ c \gets \lfloor ( a + b ) / 2 \rfloor; \ \mathrm{visit}( 2 x , [ a , c ) );\ \mathrm{visit}( 2 x + 1 , [ c , b ) ) \cr 13 & \quad \mathrm{rollback}( c_0 ) \end{array}} \]

Precondition
\( n \ge 0 \), the nodes of every operation but COMPONENTS in \( [ 0 , n ) \), each DELETE of an edge alive