The Induced Subgraph algorithm extracts the subgraph formed by a given set of nodes and all edges between them. This enables focused analysis on a subset of the graph, revealing local structure and connectivity patterns among selected nodes.
An induced subgraph includes only the nodes from the given set and all edges that have both endpoints in that set.

As this example shows, when specifying node set S = {A, B, I, K, L, M, N}, the induced subgraph is the graph whose node set is S and whose edge set contains all edges that have both endpoints in S.
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"}), (G:default {_id: "G"}), (H:default {_id: "H"}), (I:default {_id: "I"}), (A)-[:default]->(B), (C)-[:default]->(A), (E)-[:default]->(C), (E)-[:default]->(A), (C)-[:default]->(D), (D)-[:default]->(A), (D)-[:default]->(A), (F)-[:default]->(G), (G)-[:default]->(G), (F)-[:default]->(I), (H)-[:default]->(G)
| Name | Type | Default | Description |
|---|---|---|---|
nodes | STRING | / | Required. Comma-separated node _id values specifying the node set for the induced subgraph. |
Returns:
| Column | Type | Description |
|---|---|---|
sourceId | STRING | Source node identifier (_id) |
targetId | STRING | Target node identifier (_id) |
edgeExists | INT | Edge existence indicator (always 1) |
GQLCALL algo.inducedsubgraph({ nodes: ["A,C,D,G"] }) YIELD sourceId, targetId, edgeExists
Result:
| sourceId | targetId | edgeExists |
|---|---|---|
| C | D | 1 |
| C | A | 1 |
| D | A | 1 |
| D | A | 1 |
| G | G | 1 |
Returns the same columns as run mode, streamed for memory efficiency.
GQLCALL algo.inducedsubgraph.stream({ nodes: "A,C,D,G" }) YIELD sourceId, targetId RETURN sourceId, targetId
Result:
| sourceId | targetId |
|---|---|
| C | D |
| C | A |
| D | A |
| D | A |
| G | G |
Returns:
| Column | Type | Description |
|---|---|---|
nodeCount | INT | Number of nodes in the induced subgraph |
edgeCount | INT | Number of edges in the induced subgraph |
density | FLOAT | Graph density: edgeCount / (nodeCount * (nodeCount - 1)) for directed graphs |
GQLCALL algo.inducedsubgraph.stats({ nodes: "A,C,D,G" }) YIELD nodeCount, edgeCount, density
Result:
| nodeCount | edgeCount | density |
|---|---|---|
| 4 | 5 | 0.4166666666666667 |