data_structures.binary_tree.is_sum_tree¶
Is a binary tree a sum tree where the value of every non-leaf node is equal to the sum of the values of its left and right subtrees? https://www.geeksforgeeks.org/check-if-a-given-binary-tree-is-sumtree
Attributes¶
Classes¶
Module Contents¶
- class data_structures.binary_tree.is_sum_tree.BinaryTree¶
- __iter__() collections.abc.Iterator[int] ¶
>>> list(BinaryTree.build_a_tree()) [1, 2, 7, 11, 15, 29, 35, 40]
- __len__() int ¶
>>> len(BinaryTree.build_a_tree()) 8
- __str__() str ¶
Returns a string representation of the inorder traversal of the binary tree.
>>> str(list(BinaryTree.build_a_tree())) '[1, 2, 7, 11, 15, 29, 35, 40]'
- classmethod build_a_sum_tree() BinaryTree ¶
- Create a binary tree with the specified structure:
26
/
10 3
/
4 6 3 >>> list(BinaryTree.build_a_sum_tree()) [4, 10, 6, 26, 3, 3]
- classmethod build_a_tree() BinaryTree ¶
- Create a binary tree with the specified structure:
11
/
2 29
/ /
- 1 7 15 40
35
>>> list(BinaryTree.build_a_tree()) [1, 2, 7, 11, 15, 29, 35, 40]
- property is_sum_tree: bool¶
>>> BinaryTree.build_a_tree().is_sum_tree False >>> BinaryTree.build_a_sum_tree().is_sum_tree True
- class data_structures.binary_tree.is_sum_tree.Node¶
- __iter__() collections.abc.Iterator[int] ¶
>>> root = Node(2) >>> list(root) [2] >>> root.left = Node(1) >>> tuple(root) (1, 2)
- __len__() int ¶
>>> root = Node(2) >>> len(root) 1 >>> root.left = Node(1) >>> len(root) 2
- data: int¶
- property is_sum_node: bool¶
>>> root = Node(3) >>> root.is_sum_node True >>> root.left = Node(1) >>> root.is_sum_node False >>> root.right = Node(2) >>> root.is_sum_node True
- data_structures.binary_tree.is_sum_tree.tree¶