def main(): root = BinaryTreeNode(1) root.left = BinaryTreeNode(2) root.right = BinaryTreeNode(3) root.left.left = BinaryTreeNode(4) root.left.right = BinaryTreeNode(5) root.right.left = BinaryTreeNode(6) root.right.right = BinaryTreeNode(7) root.left.left.right = BinaryTreeNode(101) root.right.left.left = BinaryTreeNode(102) print(Tree(root)) mirror(root) print(Tree(root))
def main(): root = BinaryTreeNode(1) root.left = BinaryTreeNode(2) root.right = BinaryTreeNode(3) print(Tree(root)) print(get_max_path(root))
def main(): root = BinaryTreeNode(1) root.left = BinaryTreeNode(2) root.right = BinaryTreeNode(3) root.left.left = BinaryTreeNode(4) root.left.right = BinaryTreeNode(5) root.right.left = BinaryTreeNode(6) root.right.right = BinaryTreeNode(7) root.left.left.right = BinaryTreeNode(101) root.right.left.left = BinaryTreeNode(102) tree1 = Tree(root) print(tree1) print(tree1.size())
def main(): root = BinaryTreeNode(1) root.left = BinaryTreeNode(2) root.right = BinaryTreeNode(3) root2 = BinaryTreeNode(100) root2.left = root print(Tree(root2)) print(get_max_path_leaves(root2))
def main(): root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root.right.left = Node(6) root.right.right = Node(7) root.left.left.right = Node(101) root.right.left.left = Node(102) print(Tree(root)) arr = [] serialize_tree(root, arr) print(arr) root, idx = deserialize_tree(arr) print(Tree(root))
def main(): root = BinaryTreeNode(20) root.left = BinaryTreeNode(10) root.left.left = BinaryTreeNode(5) root.left.left.left = BinaryTreeNode(1) root.left.left.left.right = BinaryTreeNode(50) root = BinaryTreeNode(1) root.left = BinaryTreeNode(3) root.right = BinaryTreeNode(2) print(Tree(root)) print(isBST_direct(root))
def main(): root = BinaryTreeNode(1) root.left = BinaryTreeNode(2) root.right = BinaryTreeNode(3) root.left.left = BinaryTreeNode(4) root.left.right = BinaryTreeNode(5) root.right.left = BinaryTreeNode(6) root.right.right = BinaryTreeNode(7) root.left.left.right = BinaryTreeNode(101) root.right.left.left = BinaryTreeNode(102) print(Tree(root)) print(get_diameter(root))
def main(): root = BinaryTreeNode(1) root.left = BinaryTreeNode(2) root.right = BinaryTreeNode(3) root.left.left = BinaryTreeNode(4) root.left.right = BinaryTreeNode(5) root.right.left = BinaryTreeNode(6) root.right.right = BinaryTreeNode(7) root.left.left.right = BinaryTreeNode(101) root.right.left.left = BinaryTreeNode(102) print(Tree(root)) print(are_isomorphic(root, root))
def main(): root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root.right.left = Node(6) root.right.right = Node(7) root.left.left.right = Node(101) root.right.left.left = Node(102) print(Tree(root)) root2 = root.left.left ans = is_subtree(root, root2) print(ans)
def main(): root = Node(1) root.left = Node(2) root.right = Node(3) print(Tree(root))
def main(): root = Node(1) root.left = Node(2) root.right = Node(3) print(Tree(root)) print((get_lca(root, 20, 10)))