data_structures.binary_tree.binary_tree_traversals¶
Classes¶
Functions¶
Returns a list of nodes value from a particular level: |
|
Returns a list of nodes value from a particular level: |
|
|
Recursive function for calculating the height of the binary tree. |
|
In-order traversal visits left subtree, root node, right subtree. |
|
Returns a list of nodes value from a whole binary tree in Level Order Traverse. |
|
|
|
The below tree |
|
Post-order traversal visits left subtree, right subtree, root node. |
|
Pre-order traversal visits root node, left subtree, right subtree. |
|
Reverse in-order traversal visits right subtree, root node, left subtree. |
|
ZigZag traverse: |
Module Contents¶
- data_structures.binary_tree.binary_tree_traversals.get_nodes_from_left_to_right(root: Node | None, level: int) collections.abc.Generator[int] ¶
Returns a list of nodes value from a particular level: Left to right direction of the binary tree. >>> list(get_nodes_from_left_to_right(make_tree(), 1)) [1] >>> list(get_nodes_from_left_to_right(make_tree(), 2)) [2, 3]
- data_structures.binary_tree.binary_tree_traversals.get_nodes_from_right_to_left(root: Node | None, level: int) collections.abc.Generator[int] ¶
Returns a list of nodes value from a particular level: Right to left direction of the binary tree. >>> list(get_nodes_from_right_to_left(make_tree(), 1)) [1] >>> list(get_nodes_from_right_to_left(make_tree(), 2)) [3, 2]
- data_structures.binary_tree.binary_tree_traversals.height(root: Node | None) int ¶
Recursive function for calculating the height of the binary tree. >>> height(None) 0 >>> height(make_tree()) 3
- data_structures.binary_tree.binary_tree_traversals.inorder(root: Node | None) collections.abc.Generator[int] ¶
In-order traversal visits left subtree, root node, right subtree. >>> list(inorder(make_tree())) [4, 2, 5, 1, 3]
- data_structures.binary_tree.binary_tree_traversals.level_order(root: Node | None) collections.abc.Generator[int] ¶
Returns a list of nodes value from a whole binary tree in Level Order Traverse. Level Order traverse: Visit nodes of the tree level-by-level. >>> list(level_order(make_tree())) [1, 2, 3, 4, 5]
- data_structures.binary_tree.binary_tree_traversals.main() None ¶
- data_structures.binary_tree.binary_tree_traversals.make_tree() Node | None ¶
- The below tree
1
/
2 3
/
4 5
- data_structures.binary_tree.binary_tree_traversals.postorder(root: Node | None) collections.abc.Generator[int] ¶
Post-order traversal visits left subtree, right subtree, root node. >>> list(postorder(make_tree())) [4, 5, 2, 3, 1]
- data_structures.binary_tree.binary_tree_traversals.preorder(root: Node | None) collections.abc.Generator[int] ¶
Pre-order traversal visits root node, left subtree, right subtree. >>> list(preorder(make_tree())) [1, 2, 4, 5, 3]