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.

Sunday, February 9, 2014

Week 5

This week we did more recursion both in the lecture and in the labs. And I began to do the first big assignment, which was about Hanoi Tower, in CSC148H with two of my friends. At the time when we began to do the assignment, we were totally stuck and didn't even know what was the purpose of the program. And we just ignored that and keep on typing some codes. After sometime, we finally realized the purpose of the program and found lots of bugs in our codes. For example, we didn't match what we wrote and what was given by the instructors. The lesson I learned from this assignment is that we need to read through all the materials and the instructions before writing the code. Luckily, I realized this not till the end of the course.


During the process of doing assignment 1, I found that the raising error part was somehow difficult. For example, when a motion of a cheese was detected to be invalid, that cheese went into problem...that means it couldn't be moved again. We spent lot of time fixing that problem and we were now on the next step. Another problem that I found confusing was that there were too many files of codes and I thought I could achieve the same result writing codes in different files, so sometimes I got confused about how to write in a better and clearer way.

Week 4

This week, we learned something about recursion and raising exceptions. I found recursion so amazing that it could finish many surprising things. For example, in the lecture, our professor showed us how to use recursion to draw a beautiful picture. I was totally amazed by the beauty of recursion -- it could repeat what it does for several times and make a snowflake-like things. However, because I just started to learn recursion, I sometimes found it a little difficult to understand. I also reviewed how to raise errors and exceptions and learned some new stuff like try. Try clause is pretty useful since it can raise the error without stopping the program. Another thing that's new is the function object. Now I have a better understanding of what function object is. It is not the result of a function, but just an object. It can be called just by typing its name.