Sunday, February 23, 2014

Week 6: Tree

After the reading week, let me summarize what I learned from Week 6. The central topic of this week is Tree, which combines the concepts of recursion and object-orienting programming. Through Tree, we can create, store and analyze the data by categories. It is a little hard to understand "preorder":
Node is the first, then the left,  the right branch is the last
def print_tree(tree):
    if tree is None: return
    print(tree.cargo, end=" ")
    print_tree(tree.left)
    print_tree(tree.right)
"inorder"
The left branch is the first, then the node,  the right branch is the last
def print_tree_inorder(tree):
    if tree is None: return
    print_tree_inorder(tree.left)
    print(tree.cargo, end=" ")
    print_tree_inorder(tree.right)
and "postorder"
The left branch is the first, then the right,  the node is the last
def print_tree_postorder(tree):
    if tree is None: return
    print_tree_postorder(tree.left)
    print_tree_postorder(tree.right)
    print(tree.cargo, end=" ")
in its traversal as I am used to understanding the tree by preorder which I think a kind of my subconsciousness.
It is very useful in computer as I find that it can be linked with logic analysis - especially for CSC165 !. Every node has two branches as if every assumption has two opposite cases - true or false. We can conclude something from the different situations by using trees.
I have finished the part I of the assignment II. The goal of next week is to win the test!

No comments:

Post a Comment