Thursday, February 27, 2014
Friday, February 14, 2014
Week 6
We finished Assignment 1 this week. Finally!!! It was a great practice on recursion and it was actually a lot of fun working on this assignment.
So this week we started a new class of object that seems to deal with a great amount of recursion --- the binary tree. We first look at 3 different traversals --- the pre-order, in-order and post-order. In all these three ways of traversals, we need to use recursion to complete the code. It is actually quite straightforward to write these traversal codes. The other functions are a little bit more complicated, including 'height', 'count', 'leaf_count', 'arity'. List comprehension was so useful in writing these functions, along with the use of built-in functions like 'sum' and 'max'. I found that it is very important to consider the base case in a recursion code. For example, in 'count' function, we need to have a '+1' at the beginning so that a node without children would count.
The lab this week is on converting 'tenary if' into regular if statements. In general, the tasks are easier than any other previous labs. We finished quite early. Moreover, we got to practice on 'any' and 'all'. These two are very efficient ways along with the use of list comprehensions. They check each condition in the list comprehension -- 'any' returns True if any one is true; 'all' returns True if all are true. It would've taken a lot more work to check the conditions one by one.
Sunday, February 9, 2014
Week 5
The midterms are coming. I just started working on Assignment 1 this week. It is really hard to understand the assignment at first. So I spent time discussing with my partner to make things clear. Then it took us not long to finish the first four steps. It is really cool to see the console controller working. I played the game over and over again to double check and have some fun with it. However, I'm stuck on Step 5 now because the recursion involved is kind of complicated. Professor Heap gave us quite clear explanation on the recursion though. It is still challenging to imagine the simple recursion codes working on this complicated Tour of Hanoi model. Comparing to the easier recursion codes we've dealt with in the lab, this recursion assignment is much harder to trace. Besides the recursion, the most difficult part turns out to be how to deal with the "i" involved. We are still in the way of figuring it out.
We practiced a lot of recursions in this week's lab. Most problems of the lab were fine, but the optional ones were extremely challenging for me. We didn't manage to finish them in the lab so I might need to work on them later when I have time. This week we also talked about "scope" and unittest. The scope part is pretty straightforward. Python looks from local -> nonlocal -> global -> built-in. We looked into some code showing the results with different scopes. Python gives different outputs with assignments to a same variable under different scopes.
Subscribe to:
Posts (Atom)