skbio.tree.TreeNode.postorder#
- TreeNode.postorder(include_self=True)[source]#
Perform postorder traversal over tree.
- Parameters:
- include_selfbool, optional
Include the initial node if True (default).
- Yields:
- TreeNode
Visited node.
See also
Notes
Postorder traversal traverses all children of a node in order before visiting the parent node. It is also known as LRN (left - right - node). It is a depth-first search (DFS). The overall direction of traversal is from tips to root.
Examples
>>> from skbio import TreeNode >>> tree = TreeNode.read(["((a,b)c,(d,e)f)g;"]) >>> print(tree.ascii_art()) /-a /c-------| | \-b -g-------| | /-d \f-------| \-e
>>> for node in tree.postorder(): ... print(node.name) a b c d e f g