biconnected_components

Finding biconnected components means finding a maximal biconnected subgraph. Subgraph is biconnected if:

  • it is possible to go from each node to another within a biconnected subgraph,
  • the first scenario remains true even after removing any node from the subgraph.

The algorithm works by finding articulation points, and then traversing from these articulation points toward other nodes, which all together form one biconnected component.

TraitValue
Module typealgorithm
ImplementationC++
Graph directionundirected
Edge weightsunweighted
Parallelismsequential

Procedures

get()

The procedure finds biconnected components.

Output:

  • bcc_id: integer ➡ Biconnected component identifier. There is no order of nodes within one biconnected component.
  • node_from: Vertex ➡ First node of a relationship contained in biconnected component.
  • node_to: Vertex ➡ Second node of a relationship contained in biconnected component

Usage:

To find biconnected components in the graph, use the following query:

CALL biconnected_components.get()
YIELD bcc_id, node_from, node_to;

Example

Database state

The database contains the following data:

Created with the following Cypher queries:

MERGE (a:Node {id: 0}) MERGE (b:Node {id: 1}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 3}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 3}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 4}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 4}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 5}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 6}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 5}) MERGE (b:Node {id: 6}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 5}) MERGE (b:Node {id: 7}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 5}) MERGE (b:Node {id: 8}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 7}) MERGE (b:Node {id: 8}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 8}) MERGE (b:Node {id: 9}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 10}) MERGE (b:Node {id: 11}) CREATE (a)-[:RELATION]->(b);

Find biconnected componentes

Get the values using the following query:

CALL biconnected_components.get()
YIELD bcc_id, node_from, node_to
WITH bcc_id, node_from, node_to
MATCH (node_from)-[relationship]-(node_to)
RETURN bcc_id, relationship, node_from, node_to;

Results:

+------------------+------------------+------------------+------------------+
| bcc_id           | relationship     | node_from        | node_to          |
+------------------+------------------+------------------+------------------+
| 0                | [:RELATION]      | (:Node {id: 2})  | (:Node {id: 4})  |
| 0                | [:RELATION]      | (:Node {id: 3})  | (:Node {id: 4})  |
| 0                | [:RELATION]      | (:Node {id: 1})  | (:Node {id: 3})  |
| 0                | [:RELATION]      | (:Node {id: 2})  | (:Node {id: 3})  |
| 0                | [:RELATION]      | (:Node {id: 1})  | (:Node {id: 2})  |
| 1                | [:RELATION]      | (:Node {id: 8})  | (:Node {id: 9})  |
| 2                | [:RELATION]      | (:Node {id: 5})  | (:Node {id: 8})  |
| 2                | [:RELATION]      | (:Node {id: 7})  | (:Node {id: 8})  |
| 2                | [:RELATION]      | (:Node {id: 5})  | (:Node {id: 7})  |
| 3                | [:RELATION]      | (:Node {id: 0})  | (:Node {id: 6})  |
| 3                | [:RELATION]      | (:Node {id: 5})  | (:Node {id: 6})  |
| 3                | [:RELATION]      | (:Node {id: 1})  | (:Node {id: 5})  |
| 3                | [:RELATION]      | (:Node {id: 0})  | (:Node {id: 1})  |
| 4                | [:RELATION]      | (:Node {id: 10}) | (:Node {id: 11}) |
+------------------+------------------+------------------+------------------+