networkx.algorithms.traversal.depth_first_search.dfs_postorder_nodes

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

Generate nodes in a depth-first-search post-ordering starting at source.

Parameters
  • G (NetworkX graph)

  • source (node, optional) – Specify starting node for depth-first search.

  • depth_limit (int, optional (default=len(G))) – Specify the maximum search depth.

Returns

nodes – A generator of nodes in a depth-first-search post-ordering.

Return type

generator

Examples

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

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”.

See also

dfs_edges(), dfs_preorder_nodes(), dfs_labeled_edges(), edge_dfs(), bfs_tree()