The input directed graph to extract subgraph from
Array of node IDs representing source vertices (red set R)
Array of node IDs representing target vertices (blue set B)
A new graph containing the maximal R→B reachability subgraph with:
// Simple linear path: A → B → C
const result = incident(graph, ['node_A'], ['node_C']);
// Returns subgraph with nodes [A, B, C] and edges [A→B, B→C]
// Multiple sources and targets: A,B → ... → D,E
const result = incident(graph, ['node_A', 'node_B'], ['node_D', 'node_E']);
// Returns all vertices and edges on paths from {A,B} to {D,E}
// Disconnected components
const result = incident(graph, ['node_A'], ['node_Z']);
// Returns empty graph if no path exists from A to Z
Extracts the maximal R→B reachability subgraph from a directed graph.
This function implements the R→B Reachability Subgraph algorithm, which finds the largest subgraph where every directed path starts in the red vertex set (sources) and ends in the blue vertex set (targets). The resulting subgraph satisfies:
Algorithm Phases
Time Complexity
Edge Cases