Sunday, March 15, 2015

impressions of week 8

In week 8, I learned how to mutate binary trees. To insert nodes into a binary tree, the algorithm uses recursion. It needs to check whether if the tree is there, because if it is None, then I can just create a BTNode of that particular value to be inserted. This is the base case for recursion. If the tree is there, then I need to compare whether the value to be inserted is less than or greater than the root node. If it is greater than the root node, I can just keep calling the insert function on node.right to insert the value into its appropriate position. Likewise, if the value is less than the root node, call insert on node.left to insert the value. And if the value is the same as the root node, then there is nothing to do, because the tree already has that value. 
I also learned the algorithm of deleting a node. It is very confusing for me to understand, because nowhere do I see in the code that 'deletes' a node. 
As seen on the left, the code for delete does not have any operators like 'del'. I was confused and so I asked my friends after class and understood that the delete function 'deletes' a node by making the original memory address of the value that a node contains lost. This way, that node is deleted. 
However, I still do not really understand what does the else statement do for the delete function, so I plan to seek help in the week to come.

Sunday, March 8, 2015

impressions on week 7

This week's focus was mainly on linked lists. I learned about binary search trees and got introduced to linked lists. Unlike trees, binary trees only have 2 children. Therefore the variable self.children cannot be a list anymore, but instead, it is split to self.left and self.right. This is a lot more convenient for searching algorithms to be implemented. However, it also brought difficulty in writing code because self.children can be an empty list, which can allow programmers to still use list methods on it. But if self.left or self.right is None, then it is harder to write code without errors. 
As mentioned before, because a binary tree only has two children, it is very efficient to search for an item in the tree, if the tree is sorted. This is much like linear search, in which both cases need the data to be sorted. I learned that a binary search tree is a sorted tree, in which all the values less than the base node would be placed to its left, and all the values greater than the base node would be placed to its right. This means that to search for an item, we do not need to compare each node to the value we are searching for (in which case it would require a longer processing time), but rather, one comparison can throw away half of the tree values off (for that they are disregarded from further searching). It is a much faster and efficient way to search for values.
In the beginning, I thought that linked list is the same as nested list. However, it turned out that they are not quite the same. Linked list is also a class object, which has front, back and size. However, I'm still quite confused of the connection between class LLNode and class LinkedList. It was specially complex when involved with recursion. For example, the __getitem__ method was quite challenging to understand, because I did not know what does recursion help to increase index number. But after I asked my friends, I found out that self.size (which is positive) is added to index to keep on neutralize it to pull it towards positive. I was also confused about the else portion, because I don't understand why cur_node (which refers to self.front) has value and nxt, as these variables belong to LLNode. I hope to see more examples of linked lists to continue improve.

Sunday, March 1, 2015

Week 7 Slog

Dear marker:

I wish to have my summary on tracing recursion to be marked. The following is a link to that summary:
http://csc148experience.blogspot.ca/2015/02/impressions-of-tracing-recursion.html