skbio.tree.TreeNode.levelorder#
- TreeNode.levelorder(include_self=True)[source]#
Perform level order traversal over tree.
- Parameters:
- include_selfbool, optional
Include the initial node if True (default).
- Yields:
- TreeNode
Visited node.
See also
Notes
Level order traversal visits all nodes at each depth from the root before visiting nodes at the next depth. It is a breadth-first search (BFS). The overall direction of traversal is from root to tips.
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.levelorder(): ... print(node.name) g c f a b d e