Saturday, 21 February 2015

slog for week 7

    This is reading week!
    Looking back on week 6, I have learned some interesting but also difficult things about tree.
 I have learned a lot of terminology. As a reminder, a tree has root, nodes, edges, leaves and subtree.

A path is a sequence of nodes n1, n2,..., nk, where there is an edge from ni to ni+1. The length of a path is the number of edges in it. The path is unique and it has no cycles.

The height is 1 + the maximum path length in a tree. A node also has a height, which is 1 + the maximum path length of the tree rooted at that node.

The depth is the height of the entire tree minus the height of a node is the depth of the node.

The arity or branching factor is the maximum number of children for any node.

After learning the terminology, I was taught to design codes to count leaves, count nodes, calculate the height and so on. An important method we used was recursion. First detect the base case, and then write the code for general case involving recursion. I could understand the code if it was already written, but it was hard for me to write recursion myself. In the practical this week, my partner and I only worked a few out with the help of our TA and piazza, which was so sad. Understanding what we should do was not the hard part, it was how we should do it that mattered. I think I still need some time to think about this carefully and try to catch up. If I could get the access to the answer to the practical after the every practical is done, that would be of great help to my study. After all, we first learn to imitate and then to think independently. I still need some more examples to grasp the clue of doing this.

Also I learned a format:
self.children = children.copy() if children else []
This is a functional 'if'. it means copy children if not none. The reason why we need to copy children 
is that we don't want to make change on the original data so that our counting method will not affect 
anything. 

I will work on recursion more and get a thorough understanding. I believe I can make it!~

Ciao my friend,
Dark Fox

No comments:

Post a Comment