Hướng dẫn non binary tree traversal python - python - cây nhị phân không phải cây nhị phân

Tôi đã tạo lớp tùy chỉnh cho các nút

class NodeTree[object]:
    def __init__[self, name = None, children = None]:
        self.name = name
        self.children = children

và xác định một chức năng tạo ra một cây [một nút chứa các nút con cái của nó]

def create_tree[d]:
    x = NodeTree[]
    for a in d.keys[]:
        if type[d[a]] == str:
            x.name = d[a]
        if type[d[a]] == list:
            if d[a] != []:
                for b in d[a]:
                    x.add_child[create_tree[b]]
    return x

Đầu vào là một dict với một đối số cho tên nút và danh sách với con của nó ở cùng một hình thức với cha mẹ. Chức năng hoạt động tốt và tôi đã tạo ra phương pháp chứng minh điều đó nhưng tôi không thể tìm ra cách để vượt qua nó ngay và có được chiều cao của cây. Tôi không biết liệu "chiều cao" đó là thuật ngữ đúng vì tôi biết nó có thể là mơ hồ, tôi cần coi nút là một đơn vị đo lường, như thế này:

                                      parent
                                         |
                                         |
                                     ---------
                                     |       |
                                    child   child

Chiều cao của cây này là 2, tôi đã thử tất cả mọi thứ, từ quầy đến thẻ trong lớp, mọi thứ dường như thoái hóa tôi không bao giờ có được chiều cao phù hợp. Làm thế nào tôi nên tiếp cận điều đó?

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Examples:    

    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9

    Bàn luận
    Iterative Preorder Traversal of Binary Tree.

    Cho một cây K-ary. Nhiệm vụ là viết một chương trình lặp đi lặp lại để thực hiện giao dịch trước của cây n-ary đã cho. Two Cases have been taken care of in this Iterative Preorder Traversal Algorithm: 

    1. Truyền hàng trước của một cây n-ary tương tự như đường truyền trước của cây tìm kiếm nhị phân hoặc cây nhị phân với sự khác biệt duy nhất là, tất cả các nút con của cha mẹ đều đi từ trái sang phải trong một chuỗi. Cây nhị phân.
    2. Các trường hợp cần xử lý trong quá trình truyền tải: Hai trường hợp đã được chăm sóc trong thuật toán truyền tải trước lần lặp đi lặp lại này: & nbsp;

    Bật nút trên cùng từ ngăn xếp - trên cùng từ ngăn xếp và chèn nó vào danh sách các nút đã truy cập.: In the below python implementation, a “dequeue” is used to implement the stack instead of a list because of its efficient append and pop operations.

    Đẩy tất cả các nút trẻ của đỉnh vào ngăn xếp từ phải sang trái vì đường truyền từ ngăn xếp sẽ được thực hiện theo thứ tự ngược lại. Kết quả là, Traversal đặt hàng chính xác đạt được.

    C++

    #include

    LƯU Ý: Trong triển khai Python dưới đây, một dequeue trực tiếp được sử dụng để thực hiện ngăn xếp thay vì một danh sách vì các hoạt động tăng thêm hiệu quả của nó.

    Dưới đây là việc thực hiện phương pháp trên: & nbsp; & nbsp;

    using namespace std;

    class

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    0

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    7

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    1
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    2

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    3

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    5

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    7

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    8

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    4
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    5

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    5

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    3

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    5
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    4
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    7

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    9

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    4
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    1

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    1 2 5 10 6 11 12 13 3 4 7 8 9 
    4

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    1 2 5 10 6 11 12 13 3 4 7 8 9 
    6

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    1 2 5 10 6 11 12 13 3 4 7 8 9 
    8

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    9
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    0

    #include 4#include 5

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    1 2 5 10 6 11 12 13 3 4 7 8 9 
    1
    1 2 5 10 6 11 12 13 3 4 7 8 9 
    2

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    7

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2#include 0 #include 1
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    4 #include 3

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2using6using7using8

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    7

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3namespace2

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    7

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    22

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    5

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3#include 0 #include 1using3 using4

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    4 namespace5

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3namespace8namespace9 std;0

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3std;2namespace9 std;4

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3std;2namespace9 std;8

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3class8

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3std;2namespace9 class2

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3class4namespace9 class6

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    07

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    01

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    07

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3class4namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    05

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    07

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    10

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    15

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    20

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    222namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    24

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    34

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    7

    Python3

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    222namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    28

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    222namespace9
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    32

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    36
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    37
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    38
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    39

    class

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    41

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    45
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    54
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    56

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    43
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    44
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    45
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    46

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    45
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    49
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    51

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    64
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    56

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    68

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    70

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    43
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    58

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    60
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    62

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
    1 2 5 10 6 11 12 13 3 4 7 8 9 
    1
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    73
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    74
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    2

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    78
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    99
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    2

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    82
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    73
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    84
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    73__

    #include 4

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    95
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    97

    #include 4

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    02
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    04
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    73
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    86
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    87
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    88
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    09

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2#include 0
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    1212____213
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    14#include 1
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    17
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    73
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    19

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    26
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    31

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    26
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    33

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    26
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    35using8

    #include 4

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    82
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2222223
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    13
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    25

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    26
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    78
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    88

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    3
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    47
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    48

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    2
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    82
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    78
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    50
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    2

    #include 4

    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    97

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    60
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    61
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    60
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    64
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    60
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    67
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    72
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    76
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    79
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    84
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    76
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    88
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    91
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    76
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    88
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    98
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    75
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    76
    def create_tree[d]:
        x = NodeTree[]
        for a in d.keys[]:
            if type[d[a]] == str:
                x.name = d[a]
            if type[d[a]] == list:
                if d[a] != []:
                    for b in d[a]:
                        x.add_child[create_tree[b]]
        return x
    
    88
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    05
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    61
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    10
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    61
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    15
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    69
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    61
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    71
    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    20
                                          parent
                                             |
                                             |
                                         ---------
                                         |       |
                                        child   child
    
    62

    Input: 3-Array Tree  
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
               /   / | \ 
              10  11 12 13
    
    Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
    
    Input:  3-Array Tree
                       1
                     / | \
                    /  |   \
                  2    3     4
                 / \       / | \
                5    6    7  8  9
    
    Output: 1 2 5 6 3 4 7 8 9
    22

    Đầu ra

    1 2 5 10 6 11 12 13 3 4 7 8 9 

    Phân tích độ phức tạp:

    • Độ phức tạp về thời gian: O [n], trong đó n là tổng số nút trong cây đã cho. Where n is the total number of nodes in the given tree.
    • Không gian phụ trợ: O [h], trong đó h là chiều cao của cây đã cho O[h], Where h is the height of the given tree

    Làm thế nào để bạn đi qua một cái cây trong Python?

    Traversal đặt hàng trước Trong phương thức truyền tải này, nút gốc được truy cập trước, sau đó là cây con bên trái và cuối cùng là cây con bên phải. Trong chương trình Python dưới đây, chúng tôi sử dụng lớp nút để tạo chủ sở hữu vị trí cho nút gốc cũng như các nút trái và bên phải. Sau đó, chúng tôi tạo một chức năng chèn để thêm dữ liệu vào cây.the root node is visited first, then the left subtree and finally the right subtree. In the below python program, we use the Node class to create place holders for the root node as well as the left and right nodes. Then we create a insert function to add data to the tree.

    Làm thế nào để bạn tạo ra một cây n ary trong Python?

    Khoa học dữ liệu thực tế sử dụng Python..
    Nếu root không trống, thì. trả lại gốc ..
    Đầu: = một nút mới với giá trị của root ..
    Q: = Một deque mới chứa các phần tử gốc và đầu ..
    Trong khi Q không trống, hãy làm. Nút: = Pop phần tử đầu tiên từ q. nhân bản: = pop phần tử đầu tiên từ q. ....
    trở lại đầu ..

    3 cách để đi qua một cây nhị phân là gì?

    Nói chung, chúng tôi đi qua một cây để tìm kiếm hoặc xác định vị trí một mục hoặc chìa khóa nhất định trong cây hoặc để in tất cả các giá trị mà nó chứa ...
    Theo đơn đặt hàng.Trong phương pháp truyền tải này, cây con bên trái được truy cập trước, sau đó là gốc và sau đó là cây con bên phải.....
    Traversal đặt hàng trước.....
    Traversal sau đơn đặt hàng ..

    Làm thế nào để bạn lặp lại một cây nhị phân trong Python?

    Một cách lặp đi lặp lại dễ dàng để có được tất cả các nút trong cây của bạn là sử dụng tìm kiếm đầu tiên [BFS].Bạn có thể sử dụng hàng đợi [danh sách Python đơn giản] cho việc này.use breadth first search [BFS]. You can use a queue [a simple python list] for this.

    Bài Viết Liên Quan

    Chủ Đề