Saturday, March 28, 2015

Week #11: Revisiting SLOG Week #7

Week #11: Revisiting SLOG Week #7


It is nearly a month after writing Slog week 7. I have got a lot in this short month. New concepts include binary trees, binary search trees, linked structure, unittests, and assertions. Most of them are related to the simple Tree structure and recursion I talk about in that slog. I still insist that we use recursion for we want the computer to inherit that instinct and what the function wants to do is just what the programmers want to do. That is the only reason for us to trace the function and use the function-- to do what the programmers want to do. But I have something new to mention in this slog.

First is avoiding the unnecessary steps in our recursion when we implement a binary search tree structure. 

Just like the function shown above, we can see that we need to compare the data parameter in the header with the node.data to help us decide whether using recursion to the left subtree or using recursion to the right subtree. As mention in Slog week 8, we can promote the efficiency of the recursion by compare the requirement with the left nodes and right nodes, which results to a faster searching speed. Also sometimes we need to focus on the order of the items we return, just like the example shown below.
As can be seen on the left, we can see the comparison between the node.data and the requirement which is used to restrict the recursion to a efficient situation. Also the item to be returned is in the order: left -> node -> right, this is also required highly concentration!

Furthermore, I want to talk something about the option B in Assignment 3. The whole assignment 3 is talking about how to avoid redundancy, i.e. avoid revisiting the same data node(not the same node) in the tree. From each game state, we can generate a tree structure representing the following next states until the end of the game. Then we may find that when we traverse the tree we will meet a node we have seen before. So why we calculate it again with the recursion? That means a waste of time and resources. We need to make our recursive function much more efficient by avoiding visiting some node we have seen before. But to do so is not that simple as we are talking here. We may need to build a large structure to remember what nodes we have met before. Just like we implement distinct_node_count, we need remember what node we have met and we will not need to visit the same node under the node we have seen before. Then we build a set() to store them. But what about the branching_stats, outcome_counts and etc.? It will be really hard to realize avoiding redundancy! We may need to build a much larger structure -- dictionary to store the game states as keys and results as values. That is really complicated and also waste of time. So maybe we can build a database to store all the results as values in a dictionary in the future?

Hence the redundancy and efficiency are key problems that we should focus on after the lectures and assignment this month.

This time I want to introduce http://148choi.blogspot.ca/2015/03/week-11-revisiting-earlier-slog-posting.html. Choi's slog is really long, so we need more patience to read it. And I think that he/she need to compose his/her article to make it much more readable. Despite of these, his/her words 'the tracing was actually “the calm before the storm” of the actual implementation of recursion' are quite interesting and similar to my assertions mentioned time by time in my previous slogs.

Also, http://juliansongcsc148slog.blogspot.ca/ Julian's slogs are full of details of her implementations and feelings of the course. I have a lot of details for sure, but sometimes I maybe want to hide my feeling for some reasons. Good slogs to study!

Saturday, March 21, 2015

Week #10: Impression of week 9

Week #10: Impression of week 9


There is a reason why I do not use a specific topic to the title of this slog. For there is only one hour lecture and no tutorial, but an one hour test! 

First I want to talk about the lecture this week. It seems that we are still discussing the old concept Binary search tree, but we need to comprehend it deeper. In week 6, we use the binary search tree to find some data meeting the requirement we want. While in this week we are not simply using the binary search but changing and doing operations to the tree. In common, we also need to focus on avoiding the unnecessary steps when tracing the recursions. So we need to compare the data and the left subtree and the right subtree, and return a right order of the left node, root node, and the right node.

Next I want to discuss the term test 2 in last week. Telling the truth, this test is really not that difficult like we thought. The first question is just testing our comprehension of basic concepts of binary search tree and traversal order of the tree. But what I need to acknowledge is that I am not quite familiar to those concepts. I nearly wrote answers by guessing of those concepts during the test. Although I know that my answers are correct after confirming the answers after the test with classmates, this experience will always remind me that I need to comprehend all of the concepts that covered in lectures. No free riding! Comparing the first question, the last two questions are just transformations of list_between and insert_before functions I mentioned before in my slogs!!! So just imitating the function in our lab will be a good choice to implement these new problems.

Reminder: 
In-order traversal checks a node in between checking its two children
Pre-order traversal checks a node before its children
Post-order traversal checks a node after its children


Hence after this test I find that I need to focus more on the basic concepts and keep thinking of the nature of each structures and summarize the typical functions.

Recommend: http://computersciencemaggie.blogspot.ca/2015/03/summary-of-object-oriented-programming.html?showComment=1426384453547
More detail concepts on traversal order.

Saturday, March 14, 2015

Week #9: Linked Lists

Week #9: Linked Lists


In the last week, I first experienced a strike of TA, which is really a new one for me. Although there is no tutorial last week, there is a lab to train myself, which I think is really hard comparing to last all 6 labs. But the most important thing I learn from this lab is following the guide from professors, drawing pictures!

Drawing pictures really means a lot to implementing a LinkedList function. For we need to know and focus on what our linked structures should look like before, during and after operations where we change and mutate the structures. I think the function insert_before is quite important to comprehend the utility of the previous node, current node, lnk.front and drawing pictures.


First thing we need to concentrate on is setting up the prev.node and cur.node and the condition to start this function, i.e. the lnk node is not empty. After we have set the arguments, we next want to find the situation, the node starting with v2, where we want to insert our value v1. So we use while loop just like reading a file in csc108 last term. We need to notice that, every time we change the state to the next step, we are not using a new id or say a new variable. We are using the variables forming the lnk node, which means if we change the cur.node, prev.node or something related to cur.node, prev.node we are also changing the lnk node at the same time. This is the nature why we can use this type of solutions to implement the function like insert_before or some other LinkedList functions. 
   


Recommend: http://csc148slog1001429162.blogspot.ca/2015/03/linked-lists.html?showComment=1428298701184#c7835146733346258866 
Same idea as me, but much more beautiful pages design!

Saturday, March 7, 2015

Week #8: Binary Trees

Week #8: Binary Trees


We have learned binary trees in the last week lectures. Although it is a new concept we need to care about, we can see quite a lot of similarities between Trees and Binary Trees. Binary Trees are just simpler Trees, for there are at most two children from the root node. But it may be sometimes much more useful than an ordinary tree. 

First we can take the root as a operator, then we can do some calculations between operands. Second, which is more important called binary search tree,  is used to reduce the unnecessary steps in our recursions. For it has the properties that:

We can promote the efficiency of the recursion by compare the requirement with the left nodes and right nodes, which results to a faster searching speed. And also when we write the binary recursions, we need to focus on the sequence of adding the item to the result and the comparison of left and right nodes.

Just like we have done in the tutorial:
This list_between function can be considered as a typical of binary search tree recursions. As an ordinary recursion, we have both base case and recursive case to consider. The base case is sometimes simply referring to the leaf node case, which means the node has no children, while in this function a none node need also be kept in our mind. In the recursive case, we need to notice what the sample solution want to inform us. One is the utility of the properties mentioned in my last paragraph, i.e. saving time doing searching. Another is the sequence when we add up the result coming from the recursion. 

To sum up, the core idea has not changed from tree structure to binary search tree, but when we implement the binary tree functions, we need to keep an eye on the sequences and comparisons.