Monday, March 30, 2015

Week11: revisit my previous slogs



This is the last but one week of this term. It is time to look back to my previous work and draw a conclusion. After visiting my slogs from week3 to week10, I got really amazed that I have learned so much in this course such that class, stack, tree, recursion and so on. All of these topics are based on what we learned in CSC108. However in this course we need to think more and attempt to make the code more efficient.

Here I would like to talk more about my slog of week7----recursion in trees (click here to visit). As is known to all, recursion is one of most important topics in this course. In week 7, we had got in touch with this magic recursion just for several days. I can still feel the stress I came across at that time. Some basic methods like height were done at the very beginning. What I agree with is the general method I conclude to implement recursive functions. Now that I get adequate exercises, I have a deeper understanding of recursion----“think lazy”. Let the function do most of work. Additionally, visiting my earlier posts provides me with an interesting way to reflect on myself.

What’s more, I visit some of my classmates’ slog to compare their feelings with mine. What I subscribe to is Justin Song’s view on advantages of revisiting our slogs, which merits attention. I also share the same feelings with Nadine about recursive functions. Additionally, I want to address that visiting other’s slog is a good way to communicate with classmates as well.

I also want to talk more about the materials this week. We covered the topic of efficiency of functions this week(Big-O). Do you think it sounds familiar? Yes, this is taught in CSC165 as well. However, what is different is that we focus on calculating the time of the worst case in CSC148. I think calculating the worst case’s time aims to make the code more efficient.

Tuesday, March 24, 2015

Week10: impressions of this week



In this week’s lecture, we looked back at our a2 and learned the assertion in unittest. In a2, I have learned how to deep copy a list. One of the advantages of deep–copy is that it can avoid the original list's being mutated, which may cause ugly circumstances. For example, we need to find several possible game states based on the original one. Once we get one possible game state with the original one being mutated, we can never find other possibilities using the right game state. In this case, deep-copy helps a lot. There is an easy example:
L1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
L3 = [[item for item in r] for r in L1]
Now we check the id of both L1 and L3. They have different id addresses in spite of the fact that they have the same elements. Sadly, I was unable to figure out the way to deep copy when doing a2. So this approach gives me a new idea about how to think and solve the problem. To practice it, I apply this deep copy in my a2 and this solves many problems that I couldn’t figure out at that time.

Another new thing I learned this week is assertion. We covered this stuff in testing minimax.
It is written in the form of this:
 assert <condition> , <error_string>
---> if not condition: raise AssertionError(error_string)
From slides, assertion can be used to state two things:
•what we know is true (assuming our reasoning is correct) at a crucial point in the code.
•what we assume is true at the start of a function or method
Since I haven’t got enough exercise about unittest before, I feel confused about assertion. So I reviewed the slides and worksheet after class. This helps me to some extent to get a clearer understanding of assertion. But I think knowledge about test still confuses me. I hope I can practice it more in the next week.

Sunday, March 15, 2015

Week 9: impressions of week 8 and week 9



We have our second term test on Wednesday this week and continue on the topic of binary tree. On Monday’s class, we implement some functions that mutate BSTs such as insert and delete. Again, this is all about recursion. Experiencing several weeks of practice, I have made progress in implementing recursive functions. Compared with recursion I learned in last several weeks, recursion mutating BST can rely on some specific attributes of BSTs, say, BST’s left child is always smaller than its data and the right child is larger than its data. Take insert function as an example. Here is the code: 

               def insert(node, data):
                  ‘’’(BTNode, object) -> BTNode’’’
                  return_node = need
                  if not node: 
                      return_node = BTNode(data) 
                  elif data < node.data:
                      node.left = insert(node.left, data)
                 elif data > node.data:
                      node.right = insert(node.right, data)
                 else:
                      pass

If node is none, then create a leaf. If data is smaller than node.data, we insert in node.left .  Or vice versa. We don’t need to look at the whole tree. Instead, we focus on the part that meets the requirement. And that’s why BST is more efficient.

Due to the strike, we don’t have labs this week. So I finish the task by myself. From this lab, what I learned is to draw pictures when write some recursive functions. This may seem to be useless when solving some easy problems. But when we encounter some trickier questions, it is a significant approach to the final solution as well as a good way to think about the tough questions in the correct direction.

Wednesday’s test is not very hard for me. To prepare the test, I review the slides and codes the prof uses in lecture, as what I did for test one. What’s more, I redo the labs, which is helpful as well. Also I revisit my former slogs to comb through the material I learned before. I have to say it is really helpful. Slogs reminds me of my feelings and questions about that week’s learning. As a result, I can concentrate on knowledge that I am weak in.

Week8: impressions of week 7



Week 7 is the first week after the reading week. We continued on the topics like binary trees and binary search trees (bst). Binary tree is a kind of tree which has two named children left and right, and binary search tree is a binary tree with its left child smaller than its valve and right child larger than its value. When it comes to the concept of binary tree and bst, it’s not very challenging as we have learned tree before. However, we have to write some recursive methods again using binary tree. For example, __contains__ requires us to find whether an exact value is in the tree. To solve this problem, we can depend on its own attribute such as a binary tree has only two children. In further steps, __contains__ method in bst can be more effective because we are supposed to use the attribute that left child is smaller than its value while right child is larger.

This week we learned about some new stuff—linked lists. It has two concepts, LLNode referring to a linked list and LinkedList, a wrapper class for list. At first, I got into trouble about LinkedList. I had the wrong concept that self.front just refer to the first node of LinkedList. So I can’t figure out the right methods due to this wrong concept. After reviewing the slides and looking at the code prof writes, I come to know what mistake I have made and try to redo the problem again.



This week’s lab is about binary tree. I was unable to write recursive functions at first because I didn’t know how to think the problem recursively and how to choose the base case. So I turned to TA for help. In conclusion, the first step is choosing an easiest case that doesn’t need recursion as the base case. Then call the function in more complex cases.