Trees#
- class data_structures.trees.binary_tree.BinaryTree(value)[source]#
Bases:
objectIn computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child…
- static create_example_tree()[source]#
Build and return a complete binary tree with 15 nodes for testing.
- pre_order() List[source]#
>>> root = BinaryTree.create_example_tree() >>> root.pre_order() [1, 2, 4, 8, 9, 5, 10, 11, 3, 6, 12, 13, 7, 14, 15]
- pre_order_iterative() List[source]#
>>> root = BinaryTree.create_example_tree() >>> root.pre_order_iterative() [1, 2, 4, 8, 9, 5, 10, 11, 3, 6, 12, 13, 7, 14, 15]
- in_order() List[source]#
>>> root = BinaryTree.create_example_tree() >>> root.in_order() [8, 4, 9, 2, 10, 5, 11, 1, 12, 6, 13, 3, 14, 7, 15]
- in_order_iterative() List[source]#
>>> root = BinaryTree.create_example_tree() >>> root.in_order_iterative() [8, 4, 9, 2, 10, 5, 11, 1, 12, 6, 13, 3, 14, 7, 15]
- post_order() List[source]#
>>> root = BinaryTree.create_example_tree() >>> root.post_order() [8, 9, 4, 10, 11, 5, 2, 12, 13, 6, 14, 15, 7, 3, 1]
- post_order_iterative() List[source]#
>>> root = BinaryTree.create_example_tree() >>> root.post_order_iterative() [8, 9, 4, 10, 11, 5, 2, 12, 13, 6, 14, 15, 7, 3, 1]