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.

No comments:

Post a Comment