dfs_tree#
- dfs_tree(G, source=None, depth_limit=None, *, sort_neighbors=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.
- sort_neighborsfunction (default=None)
A function that takes an iterator over nodes as the input, and returns an iterable of the same nodes with a custom ordering. For example,
sorted
will sort the nodes in increasing order.
- 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)]