Saturday, March 28, 2015

review on a previous post

Time slipped. This term is drawing to an end. Looking back, I have learned a lot about OOP and resolved quite a few puzzles along the way. And by reviewing my slog, I could recall all these precious experiences. Here I would like to review a previous post Recursion Continued, in which I discussed about recursions used in trees and recorded my understandings and puzzles at that moment.

When I was writing the post Recursion Continued, we had just been told the concept Recursion for about 2 weeks and were still spending a long time tracing recursions. In the lab that week, it was my first time writing recursions and things didn't turn out as expected. I thought that since I understood the course materials quite well and traced recursions without much efforts(despite some careless mistakes sometimes which I could almost avoid later), the implementation shouldn't be a big problem and the idea behind those methods seemed explicit. Whereas, when it came to writing codes in the lab, I got quite stuck so I turned to my TA and he led me through the whole process with patience, from tracing the base case to completing the entire method. So next time, when I got stuck, instead of frowning, thinking hard to seek for codes that will work, I would rather start by doing easy tasks like tracing which enhances my  understandings while encourages me. As I said in the previous post, First, we need to think about the base case, that is when the case is simple enough not to require recursion. Then we need to write codes for the whole tree, going through every node and calling functions on it. 

While I was doing assignment 2 with my group mates, I remembered one of our group members came up with a solution but we didn't know how to write it down and to be honest I couldn't explain it very clear myself though I could roughly understand it. At that very moment, we started by tracing basic case, then cases a bit more complex, after some time, I felt like I could fully understand what we were doing. Once we got the full picture of the problem to be solved, the tackling of it came natural. 

Another thing to mention, when I was reading my fellow students' slogs, http://celinajiangslog148.blogspot.cahttp://egq148.blogspot.cahttp://csc148danjessicali.blogspot.ca(my favourite 3) I found their ideas quite instructive and their summary on the topics deepened my understandings on the course materials. 

Saturday, March 7, 2015

impression on week 7

This week we talked about binary search tree. It is a special kind tree in which every parent node has at most two children.
                 

’’’Binary Tree node.’’’  
    def __init__(self, data, left=None, right=None):
        ’’’ (BTNode, object, BTNode, BTNode) -> NoneType
        Create BTNode (self) with data
        and children left and right.
        ’’’
        self.data, self.left, self.right = data, left, right

We have different implementations for binary search tree which 
seems not that difficult to understand since we can always refer to a graph if feeling confused. Many things told were similar to those 
talked about in last week's lectures. The new stuffs introduced were about the travelling of trees.
There are 3 orders : inorder, preorder and postorder 

1. inorder
from left to right and recursively

if root is None:
    pass
    else:
        inorder_visit(root.left, perform)
        perform(root)
        inorder_visit(root.right, perform)

2.preorder
from the root to the leaves and recursively

perform(root) 
preorder_visit(root.left, perform)
preorder_visit(root.right, perform)

3. postorder
from leaves to the root and recursively

preorder_visit(root.left, perform)
preorder_visit(root.right, perform)
perform(root)