Friday, April 3, 2015

week12: last impression

I touched on some of the biggest hurdles for me in this course in my previous SLOG post, but I will do my best to reiterate some of them here. One of the major ones was certainly recursion. The whole idea of a function calling itself in its own definition is still rather confusing, but I found that it helps to think of it as solving a large problem by breaking it down into smaller and smaller problems until solving it becomes trivially easy. For instance, in all recursive problems on assignment 3, one has to take care of the special case in which the tree is one node long, and in all other cases the function can recursively call itself over and over until the problem is sufficiently broken down. Other difficulties for me were with understanding all the proper syntax that was needed for object oriented programming with classes. This problem was a lot less specific than the recursion problem. All I can really say about this one is that many times I would read implementation of code for certain functions and have no idea what I was looking at, only to find out that what it was was a very simple concept masked behind some syntax that I couldn't quite decipher.

To prepare for the final exam, I will have to go over all the labs that I missed due to the TA strike, as well as option A for the third assignment, since although we only technically had to do one of those options, I'm guessing knowing how to do both would be helpful. In any case, I've got lots of studying to do and am hoping for the best on the final exam.

Monday, March 30, 2015

week 11: revist

For this week's slog, we are required to revisit earlier posts that we wrote ourselves, and see whether I agree or disagree with our own opinions at past, then compare it to our classmates.

As I revisit my own slog, there was some posts I agree but some that I disagree too.

At first few weeks' slogs, I wrote I am confusing about str and repr method, and I did not clearly
write down their differences, but now I can confidently say that their differences: while __str__ method is used for printing out the state, __repr__ method returns a string representation of state.

For example,
__repr__ method is used as
       >>> s = SubtractSquareState('p1', current_total = 17)
        >>> s
        SubtractSquareState('p1', False, 17)
while __str__ method is used like
       >>> s = SubtractSquareState('p1', current_total=17)
        >>> print(s)
        Current total: 17; next player: p1

The big difference between them is when we simply write s, it returns string representation by __repr__method, but when we print s, it returns string representation by __str__method.

Other than this, I mostly agree with previous posts.
(The way I explain how to approach to recursive functions, the explanation of btnode, etc)

As I visited several classmates' slogs and compared what I and they have similar difficulties,
I realized that most of my classmates experienced the difficulties on LinkedLists, and LinkedList question on term test 2's just like me. And mostly almost all classmates feel uncomfortable about strike we have, because of cancellation of labs. This point is what I mostly agreed with, since I really have difficulty to finish lab myself.

I strongly impressed with this classmate's slog. (http://dottoripy.blogspot.ca/)
He writes down every week's slog with details including numerous codes we did on lecture, and adds explanations of terms from other sources.(for example, Object Oriented Programming on week 6) I thought I would be better if i also add definitions or principals like him, to clarify the terms.

Sunday, March 22, 2015

week10: impression of week 9

In this week, we learned about another data structure called binary search tree.A binary search tree is basically a linked list but contains two children nodes. I learned that there exists some special rule for storing data in binary search tree. Also, the lecture covered the material about measuring the performance of algorithms which was once dealt in the previous course CSC108.

    As I mentioned above, the binary tree seems to be an extension of linked list that can have maximum of 2 children for each node. There are some important rules involved in inserting and deleting nodes. 
  • When you are inserting an item to the BST, the position of an item depends on how big it is. If the item is bigger than the root, it must be placed on the right side of root. 
  • When you are deleting an item from the BST, it is a little bit more complicated but boils down to three rules. The three rules refer to deleting nodes without any children, nodes with one child, and nodes with two children. If a node has no children, then the node is simply deleted. If the node has one child, then the node is deleted and the child node is brought forward to link to the parent. The complication occurs when a node has two children. However, even here, the rules are straightforward when stated. To delete a node with two children, the next node on the right branch is used to replaced the deleted node. The successive node is then deleted. The successive node will always be the left most node on the right branch.


from http://www.codeproject.com/KB/recipes/BinarySearchTree/treeDelete1.gif

Friday, March 13, 2015

Week 9: impression of week 8

last week we were introduced to the concept of linked lists. Linked lists are kind of similar to trees as they have a value while referencing another list. Trees hold a value and reference its "children" thus making these two things similar. Linked lists are important data structures that can be very important in many fields of computer science.

What we have explored in linked lists is the fact that each linked list holds a node called a cargo. This cargo is a value that is stored. The other part of the linked list is the reference to another linked list node. This other node will also hold a cargo as well as another reference until eventually the linked list references None which marks the end of the linked list. As one might predict, this type of referencing and cargo holding can be done recursively. Since the linked list can reference upon itself, recursion makes the traversal of this linked list very simple to do. Another thing to note about linked lists is that they cannot be indexed and must be iterated over in order to go through the list. This is another reason why recursion is such a good method to go about handling linked lists since recursion will iterate until you set a condition that the function must meet. Linked lists is thus interesting and very fun to learn about.

Thursday, March 5, 2015

Week8:impression of week7

The new concept of Binary Search Trees is a bit harder to understand than I thought. The structure of a BST is simple enough; it's basically a regular tree but sorted. Each value that is smaller than the root is contained in the left sub-tree while each value larger than the root is contained in the right sub-tree. Each value is automatically sorted as it is inserted into the tree so there is rarely a need to call a sort method on a BST. Since BSTs are sorted, it is an applicable class for a binary search. The binary search cuts its search query in half every time it does not find its desired value. When compared to the linear search which checks each value one by one, the binary search is more efficient. One of the concepts I'm having difficulty understanding is how some of its methods work. For example, I don't understand how a delete method deletes the root in a BST and replaces it.

Thursday, February 26, 2015

Week7:Recursion

Recursion happens in programming when the function  itself  at least once. So, a recursive function call itself until they find the base case( the value that function knows the result) and then start to close the recursive call until return something meaningful. If a function do not have at least one base, it will generate a infinitive loop, then the program will crash. So, when programmers are creating the structure of a function, they need to be aware of the advantages and consequences of using recursion.  One pro is to reduce the code. When programmers write a recursive function, they compact their code, and make it clearly . Another advantages is there are some data structure, such as binary tree or tree that use the recursion in their own concept, so to design the methods to deals with this data structure, for example, find a node in an binary tree. There are, however, some consequences, one of them is to allocate more memory to trace the code. This happens because the recursive function need to call itself until they get into the step that they know the result. Another consequence is many cases, the recursion can take more time to process than a iterative function. There are some program which takes the recursion as a solution, for example, the sum of a list, or the Fibonacci sequence, the binary search. The conclusion of recursion is that every case the programmers must decide which method is better to apply, in many cases, the best solution is recursion.

Wednesday, February 11, 2015

Week6:Object-Oriented Programming

  Last term in CSC108, I believed objected-oriented programming to be the most useless, tedious and annoying part of the course. I did not understand the purpose of classes, as they seemed to be a much more complex and inconvenient way of creating functions. While I acknowledge that I do not have a thorough understanding of object-oriented programming, I believe I have made strides in understanding its purpose. An instance of a class has specific data and attributes that are unique to that class. These features assist greatly in keeping everything organized. For example, I would imagine that Facebook performs well because of its usage of classes. A profile, for example, could possibly be a class that Facebook uses to create profiles for people that sign up for it. It would have attributes such as number of friends, age and date of birth and methods such as adding another user as a friend. I could not imagine how this would be accomplished without the usage of classes since the code would be much more complex and disorganized. This example is just to show that I have a new perspective on classes and their usefulness. I find it interesting that classes can inherit properties of other classes, although I do not understand the purpose of this since we could just have one class with all the properties of similar classes. With all the great benefits of classes, I still do believe that they are somewhat complex to develop at times. For example, I find that having to create __str__ and __eq__ methods very inconvenient and somewhat time consuming. I am also moderately uncomfortable with implementing such methods because I do not understand how they work. For example, I don't quite understand why using the == operator on two instances of a class will check if their memory addresses are equal rather than their values. This is one of the several aspects of classes that I have trouble comprehending.

      I believe I can solve my troubles with object-oriented programming by consistent practice with developing them, and by analyzing its properties thoroughly from top to bottom so that I will understand why they work the way they do. I believe that this solution is working so far because I have a thorough understanding of how some of the features in object-oriented programming works. For example, I know that the __init__ method is used to give an instance of a class its specific attributes and data, depending on the class of course. This was an example of a concept that I was struggling with before but now I am very comfortable with. I suspect that the reasons for my problems with object oriented programming are because I started working with them before really understanding why and how they work. With this post, I hope to have conveyed my thoughts on object-oriented programming rather than reiterating its several features.