harbor run -t openthoughts/tasktrove-exp-rpt-curriculum-medium-curriculum-medium-0480harbor download openthoughts/tasktrove-exp-rpt-curriculum-medium-curriculum-medium-0480You will implement a small tree module in Python with three components: Node, BinaryTree, and BinarySearchTree. The tests exercise specific behaviors and edge cases, so aim for robust, well-documented implementations that gracefully handle empty or near-empty trees.
Create a single Python file at:
Provide the following classes and methods exactly as described:
class Node
Node(value=None, left=None, right=None)value, left, right (both left and right default to None)class BinaryTree
__init__():
self.root as a Node(None) so tests can assign root.left, root.right, etc.breath_frist(self) -> list (note the spelling; tests expect this exact name)
root.left and root.right, then their children, and so on.None and a complete level beneath, return [root.left.value, root.right.value, root.left.left.value, root.left.right.value, root.right.left.value, root.right.right.value, ...].class BinarySearchTree
__init__():
Node(None) (the root remains a Node instance even before insertions).add(value) -> None
value into the BST following standard rules:
None or root.value is None), set the root’s value to value (do not replace the root object itself to preserve the invariant that root is a Node instance).value < current.value, go left; if the left child is missing, insert a new Node(value) there.value >= current.value, go right; if the right child is missing, insert a new Node(value) there.pre_order() -> list
None or root.value is None), return [].in_order() -> list
[].post_order() -> list
[].find_maximum_value() -> int
None or raise an exception, but ensure tests for non-empty trees pass.class Node:
__init__(self, value=None, left=None, right=None)class BinaryTree:
def __init__(self) -> Nonedef breath_frist(self) -> listclass BinarySearchTree:
def __init__(self) -> Nonedef add(self, value) -> Nonedef pre_order(self) -> listdef in_order(self) -> listdef post_order(self) -> listdef find_maximum_value(self) (return type may be int or None if empty)BinaryTree
None and no children)BinarySearchTree
None)< and >=). If a non-comparable value is used, raise a reasonable exception (TypeError or custom) to aid debugging.Follow these constraints closely to ensure compatibility with the tests and the project structure.