# `strong_components`

Graphs: | see below
Properties: | components, color, discover time, root vertex
Complexity: | O(V + E)

    (1)
    template <typename Graph, typename ComponentMap, typename RootMap,
    	  typename ColorMap, typename DiscoverTime>
    typename property_traits<ComponentMap>::value_type
    strong_components(Graph& g,
    		  ComponentMap comp,
                      RootMap root, ColorMap color, DiscoverTime d)

    (2)
    template <typename Graph, typename ComponentMap, typename RootMap,
    	  typename ColorMap, typename DiscoverTime, typename DFSVisitor>
    typename property_traits<ComponentMap>::value_type
    strong_components(Graph& g,
    		  ComponentMap comp,
    		  RootMap root, ColorMap color, DiscoverTime discover_time,
    		  DFSVisitor v)

The `strong_components()` functions compute the strongly connected components of a directed graph using Tarjan's algorithm based on DFS [41].

The output of the algorithm is recorded in the component property map `comp`, which will contain numbers giving the component ID assigned to each vertex. The number of components is the return value of the function.

The algorithm requires the use of several property maps: color, discover time, and root vertex. There are two versions of this algorithm to accommodate whether or not you wish to extend the algorithm with a DFSVisitor.

### Where Defined

`boost/graph/strong_components.hpp`

### Definitions

A strongly connected component of a directed graph G=(V,E) is a maximal set of vertices U which is in V such that for every pair of vertices u and v in U, we have both a path from u to v and path from v to u. That is to say that u and v are reachable from each other.

### Requirements on Types

- The graph type must be a model of VertexListGraph.
- `DiscoverTime` must be a model of WritablePropertyMap and their value type must be an integer type. Vertex descriptors from the graph should be usable as the key type for these maps.
- The `ColorMap` must be a ReadWritePropertyMap and the graph's vertex descriptor type should be usable as the map's key type. The value type of the map must be a model of ColorValue.
- The `RootMap` must be a ReadWritePropertyMap, where the key type and the value type are the vertex descriptor type of the graph.
- The `ComponentMap` type must be a model of ReadWritePropertyMap. The value type of the `ComponentMap` property map should be an integer type, preferably the same as the `size_type` of the graph. The key type should be the graph's vertex descriptor type.

### Complexity

The time complexity for the strongly connected components algorithm is O(V + E).

### See Also

`connected_components()` and `incremental_components()`

### Example

See `examples/strong_components.cpp`.

Copyright © 2000 | Jeremy Siek, Univ.of Notre Dame (jsiek@lsc.nd.edu)