Week Four - Recursions
This week we talked about recursions in class, in recursions, big problem can always be broken down into smaller version of the same problem. If a problem can be broken into the smaller version of the small probably, recursion is probably the best algorithm to use. Recursion always has a base case, which is the simplest form that problem can get. Recursions are extremely useful when working with nested list (like the sum and nested_depth function discussed in class). I found recursion very similar to math induction where you keep going back to the simpler version of the same problem. I found tracing a recursive function is relative easy as long as you start with the simplest case (i.e. the base case) and work your way towards more complicated cases. At the end, it is very likely that you can even predict what the recursive function does without any more tracing. Take the class Tree_brust we learned in lecture as an example, after level 2, we basically can predicate what level three will do without evening going through the whole tracing process again.
However, I am still having some difficulties in writing recursive functions myself, I can't think recursively and put a function in recursive format. I guess I need to do some more practice on recursive in order to master the material.
The lab this week is easier than the lab last week, it also involved some material in CSC108 (i.e. how to use a unittest class and how to choose good test cases). I also learned the SetUp and TearDown functions in unittest, I think it is brilliant that the unittest class has those two functions, where the SetUp method will set every thing up before the testing, and TearDown will clean everything up after the testing. So it would not create any problems in the test class below. This week, I managed to finish the lab early and had a chance to look at the property function and how to make a attributes "private". I am still kind of annoyed by the fact that python can't set an attributes as "private". Assignment one is also posted, I am planning to start working on it tomorrow.