Sunday, February 16, 2014

SLOG-Week Six

We covered binary tree in the lecture this week, and to be honest, I was completely lost during the lecture because I did not understand the binary tree terms well. Hopefully, I can understand them all while I write the slog about it. (http://lianglcsc148slogw14.blogspot.ca/2014/02/week-6-i-see-trees.html
thanks to this slogger, after reading the material on Tree list, I gain a better understanding what a tree list should look like.)

So, this is a binary tree from the lecture


  • Look at topmost of this binary tree, the topmost node is distinguished as the root node which is a node that has no parent. In this case, the root node is the topmost node containing value 2. 
  • The root node can have a child node or children nodes(left child node and right child node), and each of these child or children can have their own child node or children nodes. In this case, node with value 7 has left child node with value 2 and right child node with value 6.
  • These child node and children nodes have exactly one parent. In this case, node with value 7 is the parent of left child node with value 2 and right child node with value 6.
  • each node that does not have a child or children is consider a leaf node.
  • each node that has one or more children is considered an internal node. In this case, node with value 7 is an internal node, node with value 5 is also considered an internal node, etc. 
  • Arity is maximum number of children for any node. In this case, the arity of this tree is 2 since it is a binary tree.
  • The height of a tree is the maximum path in the tree. A path is where there is an edge between nodes. In this case, the height of this tree is 4, since maximum number edge between nodes is 4. 






Sunday, February 9, 2014

SLOG-Week Five

I have been working on assignment 1 on this week, and I spent a lot of time on it. For class TOAHModel, I made a small mistake in the method number_of_cheeses and it causes my string representation to represent cheeses on a stool, but with one less cheese. Fortunately, I managed to find out what the mistake is, I wrote some redundant codes that causes the the method number_of_cheeses to count one less cheese. Overall, by writing the code for class TOAHModel, I am now more familiar with attributes, which are instance variable that can be used throughout the class.

Sunday, February 2, 2014

SLOG-Week Four

In week 4, I learned about recursion. I was impressed by the magic of recursion for solving a difficult problem in just few steps. In class, we were introduced two  examples of recursion, which are counting the depth of a list, and drawing turtles on the screen. The code showed by professor is extremely short, with most of it being just a single line. However, I find it very difficult to comprehend the concept without being able to know the mechanics that makes it work. With such an difficulty, I have a lot of trouble understanding how the recursive code actually works. So in order to help me get a better understanding, I have used the visualizer and a pen to help me to trace down every single step of the recursion code. Although this process is frustrating, it allow me to gain a better understanding with the recursion codes. After I went through all  the process, I can now write recursive code more efficiently, especially the code in A1 step 5.