2015年3月17日星期二

Slog for week 5 & week 8

Since we had a test on week 8, we didn’t move further on the topic of link list on that week. Thus I decide to combine the slogs for week 5 and week 8.

What’s New?

Link list is a new topic in this course.  It is like making connection between nodes and number, in a format like:

 _________       _________       _________
|_1_|_next_|--->|_2_|_next_|--->|_3_|_next_|


Each node includes an initial value and next value. Initial value could be a number or None, and the next value must be LinkList Node or None.

Connection between LLNode, LinkedList

In the previous lecture, we were talking about Binary Tree. I think the code of LinkedList is very similar to the Binary Tree. (Well, indeed, they are sharing the same data structure but different idea) First, every LinkedList can be broken down into two parts: value and NEXT. NEXT is the next node in this list after the value. Corresponding to these, Binary Tree also has its leading value which called data (it is the ‘root’ of the tree) and left and right children (containing other Binary Tree or None).  However, Binary has its specific rule about putting the number on the root circle and children circle, that is: the value in left children must be less than the number in root circle, while left children is bigger than the root circle. However, LinkedList doesn’t have such a strict rules. Different from Binary Tree, LinkedList focuses more on the feature of linking states (or we usually call it a LinkedList Node, instead of searching and comparing the number in the state.

Difficulties and Challenge

I’m quite confusing on the concept of lnk.front and lnk.back. I know usually lnk.front will represent the whole linkedlist, but what about lnk.back? Under what situation the value of lnk.back changes and what doesn’t?

Furthermore, when I want to insert a value inside a given LinkList, I will record the previous_node first, then move current_node to current_node.nxt and make my target value and current_node.nxt into a new LLNode. After that we need this new node to substitute the previous_node.nxt. So what’s happening on the part before the pervious_node? I’m kind of confusing about the logic here. 

2015年3月2日星期一

Week 7 - Recursion


Recursion is a new but interesting topic for me. Recursion is very similar to what we called sequence in Math, or like cell division in Bio. It’s like designing the program to following a particular pattern, and more importantly, to reusing the program itself and solve some difficult problem. At first we knew about recursion on the lecture, through exercises to trace the program step by step, in order to understand what happening inside the program and how recursion works.
Soon, we were going further, trying to implement a specific program.  The first easy recursion program is depth, which is an extremely basic example of recursion. We are following a pattern that first determine input is list or not, if yes then execute the first way which reuse the program itself; if no then return something. After the basic case, then we found a short cut.  That's every time we write a recursion function, we can first implement the easy case(base case), usually it's like if some situation happen, then directly return a number or something simple. Then we could implement the more difficult cases. Thus, I think this style to design a function is very similar to the Induction method, which we've learnt in CSC165 and also Math course.
 At the end, I want to mention some confusion in this chapter’s exercises.  First, I’m not comfortable with the concept of node. What is Binary tree node? I’m not 100% sure, but according to my understanding, we can image node as a triangle model, which has root at the very top, or we call it self.data in the exercise. Then it’s not necessary, but usually node has left leaf and right leaf. And we can combine many nodes to a Binary Tree. Second, can self.data be anything, not only to be number? Since in the exercise, function ‘evaluate’ uses operation symbol as its self.data.