bidirectional_shortest_path#

bidirectional_shortest_path(G, source, target)[source]#

Returns a list of nodes in a shortest path between source and target.

Parameters:
GNetworkX graph
sourcenode label

starting node for path

targetnode label

ending node for path

Returns:
path: list

List of nodes in a path from source to target.

Raises:
NetworkXNoPath

If no path exists between source and target.

See also

shortest_path

Notes

This algorithm is used by shortest_path(G, source, target).

Examples

>>> G = nx.Graph()
>>> nx.add_path(G, [0, 1, 2, 3, 0, 4, 5, 6, 7, 4])
>>> nx.bidirectional_shortest_path(G, 2, 6)
[2, 1, 0, 4, 5, 6]
----

Additional backends implement this function

cugraph : GPU-accelerated backend.