dfs_successors

dfs_successors(G, source=None, depth_limit=None)[source]

Returns dictionary of successors in depth-first-search from source.

Parameters
GNetworkX graph
sourcenode, optional

Specify starting node for depth-first search.

depth_limitint, optional (default=len(G))

Specify the maximum search depth.

Returns
succ: dict

A dictionary with nodes as keys and list of successor nodes as values.

Notes

If a source is not specified then a source is chosen arbitrarily and repeatedly until all components in the graph are searched.

The implementation of this function is adapted from David Eppstein’s depth-first search function in PADS, with modifications to allow depth limits based on the Wikipedia article “Depth-limited search”.

Examples

>>> G = nx.path_graph(5)
>>> nx.dfs_successors(G, source=0)
{0: [1], 1: [2], 2: [3], 3: [4]}
>>> nx.dfs_successors(G, source=0, depth_limit=2)
{0: [1], 1: [2]}