Exemple #1
0
def test():
    top_left = Node(None, None, 2)
    top_right = Node(None, None, 7)
    top_node = Node(top_left, top_right, 5)
    display(top_node)
    print("-------------------")
    dfs_print(top_node)
def test():
    top_left_left = Node(None, None, 1)
    top_left_right = Node(None, None, 3)
    top_left = Node(top_left_left, top_left_right, 2)

    top_right_right = Node(None, None, -2)
    top_right = Node(None, top_right_right, 7)
    top_node = Node(top_left, top_right, 5)
    display(top_node)
    print("-------------------")
    paths = paths_with_sum(top_node, 10)
    print(paths)
def test():
    top_left_left = Node(None, None, 1)
    top_left_right = Node(None, None, 3)
    top_left = Node(top_left_left, top_left_right, 2)

    top_right = Node(None, None, 7)
    top_node = Node(top_left, top_right, 5)
    display(top_node)
    # print("-------------------")
    # has_path_with_sum = has_path_sum(top_node, 10)
    # print(has_path_with_sum)
    # has_path_with_sum = has_path_sum(top_node, 16)
    # print(has_path_with_sum)
    print("-------------------")
    has_path_with_sum = path_sum(top_node, 10)
    print(has_path_with_sum)
Exemple #4
0
def test():
    top_left_right = Node(None, None, 4)
    top_left = Node(None, top_left_right, 3)

    top_right_right_left = Node(None, None, 9)
    top_right_right = Node(top_right_right_left, None, 8)
    top_right_left = Node(None, None, 6)
    top_right = Node(top_right_left, top_right_right, 7)
    top_node =  Node(top_left, top_right, 5)
    display(top_node)
    print("-------------------")
    print("top down levels")

    levels = level_order_traversal(top_node)
    print(levels)

    print("-------------------")
    print("bottom up levels")

    levels = reverse_level_order_traversal(top_node)
    print(levels)
def test():
    top_left_right = Node(None, None, 4)
    top_left = Node(None, top_left_right, 3)

    top_right_right_left = Node(None, None, 9)
    top_right_right = Node(top_right_right_left, None, 8)
    top_right_left = Node(None, None, 6)
    top_right = Node(top_right_left, top_right_right, 7)
    top_node = Node(top_left, top_right, 5)
    display(top_node)
    print("-------------------")
    print("left view of tree")

    # left_most_nodes = left_most_value_at_level(top_node)
    # print(left_most_nodes)

    print("-------------------")
    print("left view of tree using DFS")
    left_most_nodes = left_view_dfs(top_node)
    print(left_most_nodes)

    print("-------------------")
    print("right view of tree")