Thursday, February 13, 2014

Week 6: Recursion Structure - Tree

       After learning how to code recursion, we learned about tree, a recursion structure, this week. It took me some time to get used to the traversals: pre-order, in-order, and post-order. It become much easier once I understood the recursion within them. For pre-order, we just need to visit root first, then pre-order (recursion) left subtree, then pre-order (recursion) right subtree. So, if left/right subtree is a leaf, then we can just return that node. If the subtree is a internal node, then we treat the subtree as a new tree, and analysis it again. In-order and post-order is very similar to pre-order. The difference is that they visit root, left-subtree, and right-subtree in different orders.

       After that, we start to learn about the coding for those traversals, but it was kind of confusing. It was quiet amazing for the code to be so short for such complicated tasks. I thought I got the code after some discussion with classmates. In this week's lab, there is a similar problem. I tried solve it in one line, but the only thing I got is a headache. On the other hand, my partner combined the use of list comprehension and ternary, and coded it in one line. That was exactly what professor told us during lecture. But I did not know how to use them properly. Hence, my plan for the reading week is to ace recursion, list comprehension, and ternary, as well as getting ready for our mid-term test.

No comments:

Post a Comment