Wednesday, February 26, 2014

Week 6


This week, we learned an object called Tree. In the lecture, the professor taught us some terminologies like nodes, leaf, height, path, length and so on. And there are three ways to go through the Tree without missing any nodes. The first method is called pre-order traversal. Take the following tree list as an example, then the path is [5, 4, 3, 2, 1]. For the same example, in-order traversal will generate the path in a different way, which is [4, 5, 2, 3, 1]. The third approach is called post-order traversal and its path is [4, 2, 1, 3, 5]. Actually a tree list is has something to do with recursion. The reason for this is that a tree list is consisting of nodes and subtrees of those nodes. And the subtree itself is also a tree list. This forms a recursion structure.


Another thing I learned this week is that method __repr__() is used to return a string representation for the object but in a more useful way. The reason for this is that when we copy and paste what __repr__() returns, a same object will be produced. This is what's different from.

No comments:

Post a Comment