def __main(): dfs() preorder() return bfs() n = short_tree(list(range(15))) print(n) return n = short_tree(7 * [1]) ll = list_of_depths(n) display(ll) print(30 * '=') print(n) print(num_paths(n, 2)) pass
def __main(): n = short_tree(list(range(15))) print(is_valid_bst(n)) end = BNode(21, BNode(22)) n.left.left.left.left = end print(is_valid_bst(n)) pass
def __main(): n = short_tree(list(range(12))) end = BNode(20, BNode(21), BNode(22)) # n.left.left.left.left = end print(is_balanced(n)) print(_height.cache_info()) pass
def preorder(): n = short_tree(list(range(15))) def _order(n): if not n: return yield from _order(n.left) yield from _order(n.right) yield n.v print(' -> '.join(map(str, _order(n))))
def bfs(): n = short_tree(list(range(15))) nodes = deque([n]) res = [] while nodes: cur = nodes.popleft() if not cur: continue res.append(cur.v) nodes.append(cur.left) nodes.append(cur.right) print(' -> '.join(map(str, res)))
def __main(): max_size = 2 ** 20 with localtimer(): n = short_tree(list(range(max_size))) print(find_common2(n, 1, max_size - 1)) pass
def __main(): t = short_tree(list(range(15))) display(list_of_depths(t))
def __main(): for size in range(4, 24): n = short_tree(list(range(1, size + 1))) print(size, len(possible_inputs(n))) if size == 11: print(possible_inputs(n))
def __main(): n1 = short_tree(list(range(31))) n2 = short_tree(list(range(15))) print(n1.v, n2.v) print(is_subtree(n1, n2))
def __main(): n = short_tree(list(range(15))) for t in n: print(t) pass