The Bridges algorithm finds bridge edges in a graph — edges whose removal would disconnect the graph (or increase the number of connected components). Bridge edges represent critical connections and potential vulnerabilities in a network.
A bridge (also called a cut edge) is an edge in an undirected graph whose removal increases the number of connected components. In other words, removing a bridge edge splits a connected part of the graph into two separate parts.
In this graph, the edge B - C is a bridge because removing it disconnects C from A and B. However, if there's also an edge A - C, then B - C is no longer a bridge since C can still reach A through the alternative path.
Bridge detection is important for:
GQLINSERT (A:default {_id: "A"}), (B:default {_id: "B"}), (C:default {_id: "C"}), (D:default {_id: "D"}), (E:default {_id: "E"}), (F:default {_id: "F"}), (A)-[:default]->(B), (B)-[:default]->(C), (C)-[:default]->(A), (C)-[:default]->(D), (D)-[:default]->(E), (E)-[:default]->(F), (F)-[:default]->(D)
Returns:
| Column | Type | Description |
|---|---|---|
sourceId | STRING | Source node identifier (_id) |
targetId | STRING | Target node identifier (_id) |
isBridge | BOOL | Whether the edge is a bridge |
Find all bridge edges:
GQLCALL algo.bridges() YIELD sourceId, targetId, isBridge
Result:
| sourceId | targetId | isBridge |
|---|---|---|
| D | C | true |
Returns the same columns as run mode, streamed for memory efficiency.
GQLCALL algo.bridges.stream() YIELD sourceId, targetId RETURN sourceId, targetId
Result:
| sourceId | targetId |
|---|---|
| D | C |
Returns:
| Column | Type | Description |
|---|---|---|
nodeCount | INT | Total number of nodes |
bridgeCount | INT | Number of bridge edges |
GQLCALL algo.bridges.stats() YIELD nodeCount, bridgeCount
Result:
| nodeCount | bridgeCount |
|---|---|
| 6 | 1 |