Saturday, April 4, 2015

Week #12: Last impressions

Week #12: Last impressions

-- looking back over

After 3 months csc148 classes, I have really received quite much.

I first experienced labs of computer science. I first wrote recursions. I first designed a game and built a strategy. I harvest so many first times that I can never ever forget my amazing journey at the beginning of my python career.

Firstly, I want to simply summarize what we have learned in last three weeks. In week 10, we learned unittests and assertions. Telling the truth, unittests cannot said to be a new concept to me, for I have learned it in csc108, so the most important thing I got from the course was that both unittests and assertions were used for finding bug in our functions. Unittests help us make sure what kinds of condition we have not considered in our function, while assertions help us locate where the bugs are. In week 11, we learned about sort algorithm including bubble sort, insertion sort and selection sort and etc. It is related to big-O characteristic of an algorithm which was introduced in week 12. These were also simply introduced in csc108, but we only talked about linear and quadratic growth. This time we learned about O(1) for constants, O(n) for linear, O(n^2) for quadratic, and O(n^k). I found that big-O needed us to focus on the nested loops in the functions. We need to tell whether the loop is constant running time or linear increasing running time or something more complicated. Although during the strike we had no TAs and no tutorials, I could handle the concepts discussing in the lecture for they were all friends to me.

Secondly, I want to emphasize again the key concepts and core ideas we need to comprehend thoroughly. First is ADTs and O-O programming. This is used in nearly all the course material. We build tree structure by creating a new class. Also we make linked list structure by O-O programming. That is really basic but important in our course. Second is Tree structure. This leads to recursion that we can use to implement the tree related functions. Again we use recursion for we want the computer to inherit that instinct. The code we write is an extension of our mind, a baby of our mind, or even a clone of our mind! So 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. We need to remember that and then we can utilize tree structures and recursions when solving problems related to analyze the situation by analyzing a more original one. Third is binary trees and binary search trees. The latter one is much more important for it introduce the properties that we can used to avoid unnecessary step in our recursions by comparing data with the requirements. Fourth is the Linked List structure. I think that this is the most difficult topic in the whole course. But what we only need to do sometimes is just drawing pictures!!!

Finally, I want to talk about our 3 assignments. I am quite into these three assignments for they are based on games! I can nearly see the future that I will create my own game and design a strong strategy to fight and beat other players! How amazing it is! Assignment 1 is used to training us design new classes representing a game and form a simple strategy for the game. Assignment 2 makes us examine the game much deeper to find a best winning strategy for this game. Assignment 3 reminds us that when we face a much more complicated game, we need to avoid redundancy to reduce the time running a strategy. So these three assignments are quite interesting and make me learn a lot in process of implementing and debugging.

At the end of the slog, the slog of these course, I want to say that this is not the end of my slog, but only a beginning! 

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.

Saturday, February 28, 2015

Week #7: Summary on Recursion

Week #7: Summary on Recursion


Now I will summarize on tracing the recursive functions, writing recursive functions and  talking about 'Tree'.

Firstly, let us think about what we should do in tracing the recursive functions. As we discussed in week 5, the most important thing is not what the answer your get by tracing a single case, but what the function wants to do with the attribute. We may easily trace a function case by case by using the result we have get in previous cases, for it is an instinct that using old tools to fix new problems. I think that we use recursion for we want the computer to inherit that instinct. The code we write is an extension of our mind, a baby of our mind, or even a clone of our mind! So 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.


Secondly, what I have learned in the lecture and tutorial is to write my own recursive functions. At the beginning of writing recursive function, I find it really hard to write the code dealing with much harder cases by using the function itself again and again. For sometimes, we may find it difficult to decide whether to use sum() or max() or all() or any() or adding 1 to sum(), to max() or something even more stranger. How do we know what built-in function do we need to use for recursion? It depends on the purpose we write the recursion, that is I emphasize in the previous paragraph-- what the function wants to do with the attribute. As for the example count_list(), by the docstring, we know that we are going to count the number of lists in a possibly-nested list. So what built-in do we need to use? Apparently, it is 1 + sum() for the words: 'the number of'. Another situation, if we want to compare something, we may use max() or min() instead. Or we want to return a boolean, we may use all() or any() representing 'and' or 'or'.




Finally, I want to talk about stack, queue and Tree. Stack and queue are just like a pair of brothers. Stack is to remove the last element in the list, while queue is to remove the first one in the list. But when adding a new element to the list, they both add it to the end of the list. As for Tree data structure, we have introduced both Tree and binary Tree. We can see the concept of a Tree in the picture. I think that the Tree class is not only designed to practice writing recursions, but to build a mind of thinking problems using the Tree data structure. Just like what we do in assignment 2. We analyze the minimax strategy by dividing each possibility of next state to a child node of the root node. And we just need to analyze the leaf node, that is a win state or a tie state. That helps us to determine the current score of each player and help the players to decide which is the best move they should take in order to win the game.

In conclusion, recursive functions and Tree data structure is what we focus on in the previous weeks, and we need to keep them in mind when solving problems related to analyze the situation by analyzing a more original one.

Saturday, February 14, 2015

Week #6: Summary of Object-Oriented Programming concepts

Week #6: Summary of Object-Oriented Programming concepts


So now I want do a summary of O-O programming.In Wikipedia and our lecture, It is defined as a programming paradigm based on the concept of 'object', which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. In python it is class-based, meaning that objects are instances of classes, which typically also determined their type. We use the object-oriented programming while dealing with a specific situation in our lives. 

One of the most important concepts is ADT (Abstract Data Types), i.e. creating our own type by implementing classes. ADT helps us to specify the intended meaning stored in the data, and the operations it provides in the data. In python, we use classes to specify that kind of data. Attributes and behaviors are the important part of a class. We implement the class by methods of __init__,  __str__,  __repr__ and so on. 



Just like what we do in assignment 1-- creating a class representing a game state when we play a simple game, a class representing a move made by a player, and a class representing a strategy the computer use to fight with players. By doing so, we can just create a game view class to do the work running the game, by dealing with each game state by prompting the player to enter their move or using the strategy the computer use to make a move. During the work of assignment, we need to find how to take moves and how to do the move to the state, for when the computer use the strategy we set, it need to know what moves it can take and when running the game, we need to know how to change the state. To solve the problem, we need to write the method 'possible next moves' and 'change the current state to next state', which is used to find what moves can we do in the current state and after the move what will the next state be. When doing the possible next moves, we are just to find the square that is less than the current value. When doing the change state, we are just to change the player to the opponent and make move to the current value, that is subtract the move to the value. And also, we need to judge whether either player is win when a new state come out. In the subtract square game, to judge the game over state is quite easy. We just need to make sure whether the square is 0.

Recommend:http://computersciencemaggie.blogspot.ca/2015/03/summary-of-object-oriented-programming.html?showComment=1428298896513 
This is a quite specific and comprehensive and thorough explanation of O-O programming. Good slog to review and comprehend the concepts.

To see slog week 3-8 http://148wuboyangw3.blogspot.ca/search?updated-max=2015-03-08T22:46:00-07:00&max-results=7

Saturday, February 7, 2015

Week #5: Tracing recursion

Week #5: Tracing recursion


We have just learned how to trace recursive functions and write simple recursive function by ourselves in week 4. It is very interesting to trace a recursive function. In the procedure, we need to trace the recursion from the simplest case. And what cases we have trace before can be used as results in the new and harder cases. 

Just like the example in the lab:

I think that one of the difficulty in my lab is to find the function want to do with the attribute. We may easily trace a function case by case by using the result we have get in previous cases. But how can we know what the function want to do? I think we need to focus on what we need to do with the next case in the tracing. For example, we have traced the first 3 cases: nd('ox'), nd([]), and nd([1, 2, 3]). Now for nd([1, [2, 3], 4]), we use the result that  a int is just to return 0 and a list without elements of lists is just to return 1, and we find the max of the nd(elements in the list), and then + 1 at the end.  It is surprising to find that we just to add one if there is a '[]'. So we find the purpose of the function is just to find the number of nest in a nested-list.


Another problem I faced in the lab was how to write a recursion on my own. For example the length function. How to write recursion? I find it simple after analyze what need to be use time by time in our function. The simplest case in length is when L is not a list, then have: if not isinstance(L, list): return 0. Otherwise, we need to compare len(L) and length of the sublists of L, i.e. len(L) and length(x) for x in L. So we need to write the function as:else: return max(len(L), max([length(x) for x in L])). Then the recursion is written! So interesting, isn't it?

Recommend: http://computersciencemaggie.blogspot.ca/2015/03/summary-of-object-oriented-programming.html?showComment=1426384453547
Same idea as me, but much more specific processes are provided in this slog.

Saturday, January 31, 2015

Week #4: Impression of first few weeks

Week #4: Impression of first few weeks


The impression of csc148 is quite different from csc108 I took last semester. In csc108 course we need to take prepare and perform exercises every week. As in csc148, we have no prepare videos to watch, but we have one hour lab per week. I think the way to take lab is quite efficient for us to understand the topic discussed in the lecture. Exercise by ourselves and then talk with TAs will save a lot of time to comprehend what we need to learn.

I have learned two main topics from first three weeks. 


First is ADT (Abstract Data Types), i.e. creating our own type by implementing classes. ADT helps us to specify the intended meaning stored in the data, and the operations it provides in the data. In python, we use classes to specify that kind of data. Attributes and behaviors are the important part of a class. We implement the class by methods of __init__,  __str__,  __repr__ and so on.





Second is how to use general class and sub-classes to deal with different situations in our lives. We may face a lot of situations in our lives which can be classified into one situation. That is the general class we need to implement. A general class may contain the same attributes those different situations will all use, and some methods they use in the same time, too. What I like most is one sentence "raise NotImplementedError" which will be written in a method that we cannot write all situations in a general case, but we need to finish it differently in different sub-classes. Also, in a subclass, we can write less by using what we write in the general case.

In lab1 and lab2, I find it quite difficult to determine what type of attributes we may use to initialize the classes. Just like the Registry, I first thought that how can I represent the email addresses of runners and the categories of different speed runners? Then I find that I need a dictionary for the categories, otherwise I cannot find which part of the runners are fast and which are slow. Also I find that the email addresses of runners are only used to find the single runner and get him/her into his/her category of speed, so I use list to represent it.

Thursday, January 22, 2015

Week #3: Why geeks should write?

Week #3: Why geeks should write?



To see whole semester slogs, go to http://148wuboyangw3.blogspot.ca

It is very common for us to face a dilemma when we are debugging something we have debugged before. Although we have solved it several months or several days, or even hours ago, we may still forget what should we do to fix it. So that is simply why we, computer science learners, should write and record frequently.

Just as a student, a debugging journal, or say debugging log, is not only a way to be efficient when we write code for assignments or labs, but also a way to make our test review much more easier. 





One thing that stroke me so deeply last term was that the difference between the global stack and the local stack when we set new variables.  I found this problem confusing when I did my assignment of 'csc108'. After I solved the problem of why I had not change the variable in my function, I did not write this down. Then at midterm, when I was struggling working with the past tests, I failed in many problems related to when the variables would change. So I turned back to my assignment, and used visualizer to debug my code for another time. Finally, I found the difference between the global stack and the local stack, and learned this lesson.

Hence, debugging journal is a good habit to keep during our computer science learning.

Recommend: http://lhzuigao.blogspot.ca/2015/02/summary-of-object-oriented-programming.html?showComment=1428297533544#c5125539547234044692
Yue has mentioned that we have not enough prepare for the implement of classes exercises, I think that should be notice in the future courses.