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.


2015年2月1日星期日

Slog for Week 4


  • What's new in this week?
This week we're moving on to another topic - recursion! It's simply like some functions use themselves as a helper function, and due with some very special situation. Like sum the list
[1, [2, [3,  [4,[5]]]]]. I think recursion is like the key to solving the puzzle. It uses some special pattern to solve the puzzle. Besides, we also learnt how to make track to the recursion function, which can help us to understand how recursion works and how to write a recursion function.


  • Challenge problem
I was wondering whether there're some trick to create a recursion function since I know how to track the function, but I have difficulties while writing some slightly complicated recursion. For example, the last question for the lab exercises in this week. I prefer some logical and detail tips like first step should do what and the second step should do what, etc.

2015年1月25日星期日

Why geek should write?

I'm not saying writing is necessary for being a geek, but we're reasonable to believe that writing is an effective way to train a good programmer. Since writing is a creative job to practice your imagination, you can train your ability to construct a good article structure, and dedicate this ability to write a readable and concise program. In writing, we usually use some basic logical words such as "first of all", "then" and "next". In programming, we also need to be so logical. We'll design the program first do what, then do what, if what condition then do what, etc. So a logical mind is essential for geek. Besides, since while a program is written, you are not only writing the code of the program, you also need some docstrings and comments, in order to make the functions understandable. I still remember that in CSC 108, our prof said, programs are designed to be read by human rather than machines. Thus, writing ability is more important than we thought in computer science.  Furthermore, I realize that in article, we have thesis, sub-thesis and statements. Their relationship just similar to superclass and subclass. This is the reason why I say constructing an article is like to constructing a program.