This week, the class revisited the topic about big-Oh to solve the best case for the binary tree. I felt no difficulty over the concept of big-Oh as I have already learnt about them in CSC 165 class. What I felt difficult or rather tough is the fact that I did not get a chance to have a tutorial session for 4 weeks which made me hard to review the course material. Not only that, my professor told the class that there is a chance that course marking scheme can be readjusted which I also think it is inevitable given the circumstances.
Unfortunately, there was no lab session which marks the end of the tutorial. I hope the class can have an extra additional review session before the final exam just to be on the safe side.
Anyway, this week, I also revisited and read my previous SLOG postings. I felt that I agree with my earlier self whether it was about the course material review or how both parties, U of T and CUPE3902 need to find a reasonable contract to each other to minimize the impact it will have on the other courses. Thankfully, both parties managed to end the strike. Thus, I can now get a help from T.A. on things that I did not understand.
Additionally, I think it was interesting for me to see what previous me have thought about the course material. Also whenever me in the previous SLOG post said what was difficult during that week, I felt that it was good idea to reflect on my weakness and improve them using my own time. Sometimes I also outlined the term to remember which I think it is a good practice before the upcoming final exam. Moreover, by reflecting on my previous SLOG entry, I thought it was interesting to see the sample problem which I posted to review that week's materials. Among all the entries, I still find Binary search tree the most challenging just like I stated on my entry.
The easiest thing I found on my previous entries is from week 5 on a simple recursion. Although I found the concept of the recursion very challenging at first, with continuous reviews, I think it was the most easiest yet the most important material which I learnt throughout this course. Even later on, I used a recursion on binary tree and binary search tree to check every possibilities in a tree.
As the end of the course approaches, I was disappointed to see how half of students stopped writing their SLOG post just because T.A won't be marking them since the first grading. I always though writing is an important element for a computer programmer as I already mentioned on my first SLOG entry on why geeks should write. Many of my friends told me they either forgot to do it, or thought that the professor won't be grading their SLOG post because of T.A. strike. Sometimes I find hard to see how students are not doing their works just because professor or T.A won't be marking their homework or assignment. I think that is an unreasonable excuse. Since coming to U of T, I always thought it was student's duty to perform their best on any works given. So I will do my best until my graduation. Now that T.A. strike is over, I hope I can get a help from T.A regarding the course material. I am also glad to hear that U of T and CUPE 3902 have managed to find a solution.
Thankfully, I could still find some earnest people's SLOG posting and could see how much effort they put into each of their post despite of the possibility of having no time. I usually write my post before I sleep which makes me to think back on what I did for the week as well as what kind of impression I had on the previous week.
These are slog which I really recommend for reading. I also commented on these site.
- http://gonicsc148.blogspot.ca/
- http://thediaryofageekykid.blogspot.ca/
- http://timothylock.me/sLOG/CSC148/
Above sites are really detailed and their entry was uploaded almost every week despite of 4 weeks long T.A. Strike.
I just realized next entry will be my final entry for CSC148 SLOG, I hope that there is a chance like this to reflect on myself and course materials in second year too. Thank you for reading!!!
Saturday, March 28, 2015
Friday, March 20, 2015
Week 10: Binary Search Tree Mutation
During week 9, I learnt more about binary search tree, mainly about its mutation. One thing that I had to take into account before going to the class BSTNode is that all data in root.left is less than root.data and all data in root.right is more than root.data. At first, binary search tree sounds really difficult for me, but soon, I realized that the concept of BST is really similar to BTNode that I went over the past two weeks.
Now, I am really good at implementing a BST mutation code such as insert and delete which the professor went over for the class because of continuous practices. Not only that, the term test 2 also covered up to BST mutation, thus I was required to learn the materials.
The below example is a basic BST mutation code that the class visited which is "insert".
Now, I am really good at implementing a BST mutation code such as insert and delete which the professor went over for the class because of continuous practices. Not only that, the term test 2 also covered up to BST mutation, thus I was required to learn the materials.
The below example is a basic BST mutation code that the class visited which is "insert".
def insert(node, data):
''' (BTNode, object) -> BTNode
Insert data in BST rooted at node if necessary, and return new root.
>>> b = BTNode(8)
>>> b = insert(b, 4)
>>> b = insert(b, 2)
>>> b = insert(b, 6)
>>> b = insert(b, 12)
>>> b = insert(b, 14)
>>> b = insert(b, 10)
>>> print(b)
14
12
10
8
6
4
2
<BLANKLINE>
'''
return_node = node #need one instance variable
if not node: #case when node is None
return_node = BTNode(data)
elif data < node.data: # case when data in parameter is smaller than BSTNode's data.
node.left = insert(node.left, data)
elif data > node.data: # case when data in parameter is bigger than BSTNode's data.
node.right = insert(node.right, data)
else: # nothing to do
pass
return return_node
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w9/bst_mutations.py)
Please see the comments which I have added for a brief instruction on insert(node, data). I actually found this exercise really helpful, as I can see how recursive code can be used differently. However, I am starting to be curious that instead of BTNode, if I had to use a Tree with three branches rooted at data, how would I approach to a new method of mutation insert? This was a question which I wanted to ask to T.A., but sadly, with strike ongoing, I was not able to ask about this question.
Lab 8 was a similar exercise to BST insert and delete code, so it was easy for me to complete it in few hours.
Because of the term test 2, I only had one class during week 9. Thus, there was not actually many things that I learnt besides BST mutation.
What I found difficult during week 9 is how for BST mutation, one needs to be able to identify every cases that can happen given the docstring and parameters.
Just as a side note, I hope everyone can resolve their problem well whether it is a strike, or exam. With so many things going on recently at the University, I just hope there is a solution which makes everyone happy. Thank you for reading!!!
Saturday, March 14, 2015
Week 9: Linked List
During a week 8 I learnt about a Linked list. Professor told the class that a linked list can be seen as a value and a sub-list. Before going into a further details about a linked list. There were some terms I had to be familiar of. These terms were front and back. The definition of front and back in a linked list is simple, it simply indicates the sequences' front or back.
Furthermore, I learnt about implying mutation on a linked structure. At first, I was having a difficulty over how to ensure that the recursive code works correctly so that my linked list code implementation works in any cases under the assumption that the parameter follows the example of class LinkedListNode. (please note that professors called this class 'LLNode'.)
As a tip to learn a linked list easily, Danny told the class to draw a picture in which how the sequence will be affected if one make a change in a linked list. The most challenging implementation for me was "insert_before" which was from lab 7.
Furthermore, I learnt about implying mutation on a linked structure. At first, I was having a difficulty over how to ensure that the recursive code works correctly so that my linked list code implementation works in any cases under the assumption that the parameter follows the example of class LinkedListNode. (please note that professors called this class 'LLNode'.)
As a tip to learn a linked list easily, Danny told the class to draw a picture in which how the sequence will be affected if one make a change in a linked list. The most challenging implementation for me was "insert_before" which was from lab 7.
def insert_before(lnk, v1, v2):
''' (LinkedList, object) -> NoneType
Insert a new node with value v1 before the first occurrence
of a node with value v2. Do nothing if no node has value
v2.
>>> lnk = LinkedList()
>>> lnk.prepend(5)
>>> insert_before(lnk, 4, 5)
>>> print(lnk.front)
4 -> 5 ->|
>>> insert_before(lnk, 3, 5)
>>> print(lnk.front)
4 -> 3 -> 5 ->|
>>> insert_before(lnk, 3, 7)
>>> print(lnk)
4 -> 3 -> 5 ->|
'''
if lnk.size > 0:
prev_node = None
cur_node = lnk.front
while cur_node and not cur_node.value == v2:
prev_node = cur_node
cur_node = cur_node.nxt
if cur_node:
cur_node = LLNode(v1, cur_node)
if prev_node is None:
lnk.front = cur_node
else:
prev_node.nxt = cur_node
lnk.size += 1
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Labs/lab07/node_sol.py)
Please see class LLNode and BTNode from lab 7 to understand how ".nxt", ".front", "lnk.size" work.
In this insert_before code, I had to make sure that there exists two variables which will constantly change as the code goes through while loop. Not to mention, it is also significant to realize that lnk.size, which indicates the sequence's index, should be increased by one to check every elements (if necessary, however in this case, once a function finds the first occurrence of a node with value v2, the function does not need to check the remaining elements in a sequence).
Things that I found easy during week 8 was the basic concept of a linked list such as implementing a function such as append and prepend which is a lot similar to stack and queue exercises I did during week 4. Nevertheless, it was still difficult for me to recognize the previous node and current node to be able to "walk two references along a list"
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w8/Linked-Lists.key.pdf).
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w8/Linked-Lists.key.pdf).
I also read required reading on a linked list in week 8 which was a good prep for me to understand about how to implement a recursion in a list. I also learnt about the fundamental ambiguity theorem which describes the ambiguity that is inherent in a reference to a node
(Source: http://openbook project.net/thinkcs/python/english3e/linked_lists.html).
(Source: http://openbook project.net/thinkcs/python/english3e/linked_lists.html).
Now I want to talk about things which happened this week. With strike ongoing, there was no lab this week as well. However, I managed to finish the lab 8 by myself since compare to previous labs, the amount of work given was relatively small.
Another thing I want to mention is about term test 2. Thanks to studying hard for the exam, I think I did pretty well on the term test. Although I am not sure when I will get it back, one thing is certain that this term test 2 was another great opportunity for me to review course materials before the final exam which will take a place in April.
Finally, I wrote some comments on other student's SLOG which I though it was really interesting and worth reading it. It was difficult for me to find many good SLOG website as not many students were willing to write their SLOG entry every week. Here are some slogs' links which were worth reading for me.
- https://nanalelfecsc148slog.wordpress.com/
- http://dominicli.blogspot.ca/2015/03/slog-7-midterm-2-and-bst-mutation.html?
- http://2015-csc148.blogspot.ca/2015/03/impression-of-week-7.html?
Finally, I wrote some comments on other student's SLOG which I though it was really interesting and worth reading it. It was difficult for me to find many good SLOG website as not many students were willing to write their SLOG entry every week. Here are some slogs' links which were worth reading for me.
- https://nanalelfecsc148slog.wordpress.com/
- http://dominicli.blogspot.ca/2015/03/slog-7-midterm-2-and-bst-mutation.html?
- http://2015-csc148.blogspot.ca/2015/03/impression-of-week-7.html?
Saturday, March 7, 2015
Week 8: Binary Tree
During week 7, I was learning about the binary tree. Throughout labs and many exercises I did, I was able to understand how I can be able to do parenthesizing of the tree as well as how to do binary search trees. Thanks to TA's assistance during the tutorial, I was able to get a sense of how different types of tree can be implemented in many different ways to find out the specific points which the user is trying to figure out. One of the most challenging problem I had during lab06 was the very first problem of implementing parenthesizing. However, when I started to think of the implementing this function by parts, I was able to easily figure out the trick to do so.
Moreover, during the lecture, with Danny, I worked on how to evaluate an arithmetic expression that is represented as a binary tree which was interesting for me to look at. After working with several problems involving binary tree, I realized that binary tree is slightly modified version of tree. One thing that caught my attention during the lecture was use of __str__ and __repr__ methods for a binary tree.
Moreover, during the lecture, with Danny, I worked on how to evaluate an arithmetic expression that is represented as a binary tree which was interesting for me to look at. After working with several problems involving binary tree, I realized that binary tree is slightly modified version of tree. One thing that caught my attention during the lecture was use of __str__ and __repr__ methods for a binary tree.
def __str__(self, indent=''): ''' (BTNode) -> str Return a user-friendly string representing BTNode (self) inorder. Indent by indent. >>> b = BTNode(1, BTNode(2, BTNode(3)), BTNode(4)) >>> print(b) 4 1 2 3 <BLANKLINE> ''' right_tree = self.right.__str__(indent + ' ') if self.right else '' left_tree = self.left.__str__(indent + ' ') if self.left else '' return right_tree + '{}{}\n'.format(indent, str(self.data)) + left_tree
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w7/btnode.py)
The above example is str method that was used by the professor to explain how we can represent a binary tree when knowing self.right and self.left. It was actually my first time seeing the use of __str__ method to show a string representation of a binary tree. From the previous CSC108 class, I already knew what was a binary tree, however, it was still interesting for me to see how use of a binary tree can be represented with some modification to __str__ method of class. Thus, this function can let the user to identify the depth of a binary tree clearly.
During week 8, I learnt about the linked list which is a linear sequence of nodes. Some term I had to familiar of with linked list is the concept of tail and head, front and back which are just explanations of how and what linked list is. However, I will go over more about linked list in detail with an example on the next SLOG entry.
Also I was busy doing my assignment 2 with my partner this week. The most challenging part in this assignment 2 was to implement minimax function (in our assignment the name of minimax function was suggest_move) in game strategy which allow the computer to pick the best move out of available moves considering all the possibilities. My partner and I knew that there has to be some recursion involved which let the minimax function to check all the possibilities of the game. Later on, I also figured out that minimax was actually the beginning of the artificial intelligence. Throughout assignment 2, it made me realize that there is no easy way when you implement the code like minimax where we have to consider all the possible outcomes and ways to find the best move. I better start studying for upcoming term test 2!
Another thing I want to comment is about TA strike. This week, all students did not get to have a tutorial on lab07. I hope T.A. strike ends soon with both parties, TA union and UofT to reach a reasonable contract.
Subscribe to:
Posts (Atom)