dfs_tree#

dfs_tree(G, source=None, depth_limit=None)[source]#

Returns oriented tree constructed from a 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:
TNetworkX DiGraph

An oriented tree

Examples

>>> G = nx.path_graph(5)
>>> T = nx.dfs_tree(G, source=0, depth_limit=2)
>>> list(T.edges())
[(0, 1), (1, 2)]
>>> T = nx.dfs_tree(G, source=0)
>>> list(T.edges())
[(0, 1), (1, 2), (2, 3), (3, 4)]