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
See also
dfs_preorder_nodes
dfs_postorder_nodes
dfs_labeled_edges
edge_dfs
bfs_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)]