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.