Wednesday, April 8, 2015

Week9 Slog

This week Binary Search Tree is introduced to us. Compare to a Tree, BST is easier to use and understand. It compares each nodes with the root and put the smaller ones on the left tree and the larger ones on the right tree. Then it keep compares everything and do the same. It decreases the working time compare to Tree.
Also, When I'm trying to do implement on BST, it's a lot easier than a Tree. I need to compare the value I'm gonna work with with the root of the BST, after that, I only need to deal with one side of the tree depends on the value is larger or smaller than the value of the root. This way it is a lot faster.

Week8 Slog

This week we have learned linked list. This is a linear sequence of nodes. It has two variables which is a front or head, and a back or a tail. Usually, the back of one front is also a front of the other back. This way, nodes are linked together to form a linked list.
The hardest part of linked list for me is to understand how it works. It is called a "list" but it's nothing like a list other than it's shape. It is formed by several nodes. So for sure you can't get any specific nodes but calling the index. It took me a long time to figure how to call a node by recursion. So it is fine for me now.

Week6 Slog

This week we have learned about tree. This is a type of python codes. It has a root as the start and several leaf nodes assigned below the root. The most confusing part for me is that the nodes are not int or float or strings along. If I want to use the nodes, I have to say node.value to use it to either compare to print. Otherwise, it will print out an error. Otherwise, Tree is not hard to understand for me.

Week7 - Recursion

     Recursion is similar to a circle. Usually, programmers write the complete functions before using it, but in Recursion, functions can be used inside themselves before they are completed.
     Recursion is a way of programming or coding a function, in which a function calls itself one or more times in its body. It appears to me difficult to understand at the beginning. Thinking recursively is very important to this part. First of all, you need to make sure you have a start case which tells python what to do recursively. The start case is really important because it decides how the entire function works. 
     The start case usually claim the condition of where the variable is None or 0. Then it claims what will happen if the variable is not None. One example can be:


def node_count(root):
    if not root:
        return 0
    else:
        return 1 + sum([node_count(child) for child in root.children])

where it shows if root is None, the function returns the value "0" so every time when it runs to get to the end of the tree, it doesn't add another value to the answer.

Recursion is one of the best way to write functions so far. By writing codes recursively, it reduces a lot of work. It's also the fastest way to write.