Incremental Connected Components

This section describes a family of functions and classes that work
together to calculate the connected components of an undirected graph.
The algorithm used here is based on the disjoint-sets (fast
union-find) data structure [8,27]
which is a good method to use for situations where the graph is
growing (edges are being added) and the connected components
information needs to be updated repeatedly. This method does not cover
the situation where edges are both added and removed from the graph,
hence it is called incremental[42] (and not
fully dynamic). The disjoint-sets class is described in Section Disjoint Sets.

The following five operations are the primary functions that you will
use to calculate and maintain the connected components. The objects
used here are a graph g, a disjoint-sets structure ds,
and vertices u and v.

initialize_incremental_components(g, ds)
Basic initialization of the disjoint-sets structure. Each
vertex in the graph g is in its own set.

incremental_components(g, ds)
The connected components are calculated based on the edges in the graph
g and the information is embedded in ds.

ds.find_set(v)
Extracts the component information for vertex v from the
disjoint-sets.

ds.union_set(u, v)
Update the disjoint-sets structure when edge (u,v) is added to the graph.

Complexity

The time complexity for the whole process is O(V + E
alpha(E,V)) where E is the total number of edges in the
graph (by the end of the process) and V is the number of
vertices. alpha is the inverse of Ackermann's function which
has explosive recursively exponential growth. Therefore its inverse
function grows very slowly. For all practical purposes
alpha(m,n) <= 4 which means the time complexity is only
slightly larger than O(V + E).

Example

Maintain the connected components of a graph while adding edges using
the disjoint-sets data structure. The full source code for this
example can be found in examples/incremental_components.cpp.

Where Defined

Requirements on Types

Vertex must be compatible with the rank and parent
property maps of the DisjointSets data structure.

component_index

component_index<Index>

The component_index class provides an STL
container-like view for the components of the graph. Each component is
a container-like object, and access is provided via
the operator[]. A component_index object is
initialized with the parents property in the disjoint-sets calculated
from the incremental_components() function. Optionally, a
vertex -> index property map is passed in
(identity_property_map is used by default).