Saturday, March 28, 2015

Week 7 impression

    The introduction of binary tree node (BTNode) seemed a little irrelevant to the topic. What's more bizarre was the pre-, post-, and inorder.
    BTNode is a tree similar to a normal tree. The difference is that in BTNode, The root has three attributes defined in the __init__ method: data, left, and right. Data is similar to the "value" in a normal tree, left is a subtree that has all the value that is smaller than the "data", and right is a subtree that contains all values larger than the "data". In a sense, BTNode is a sorted tree.
    The pre-, post-, and inorder seems complicated.
        Preorder:
            (root)->(left)->(right)
        Inorder
            (left)->(root)->(right)
        Postorder
            (left)->(right)->(root)
    The above is the way nodes of a tree is orderly visited.
    For example, if we have a tree like this:

                    Root
                   /       \
                A         B
              /    \       /    \    
             C   D     E    F
    Preorder would visit the tree in an order of: root, A, C, D, B, E, F
    Inorder: C, A, D, Root, E, B, F
    Postorder: C, D, A, E, F, B, Root

    However, in the assignment, we needed a tree to create all the possible next moves. What is showed in class seemed to be irrelevant. I can understand what BTNode and those orders are, but no idea where it may be useful.

No comments:

Post a Comment