Thursday 5 December 2013

Week 10 - 12

Looks like we're already at the end of this course. This semester has really flown by! Because of the reading week (or should I say reading days), week 10 just consisted of the second term test. I thought it was pretty straightforward - three recursive functions which test your knowledge on binary trees and linked lists. The one mistake I made was assuming that a default value of None was assigned to the next attribute of a new instance of a linked node. Had I ran my code, I would have realized that the initializer took 3 arguments (self, value, next) instead of just two. I'll have to make sure to pay more attention to the code given in the question next time!

For the past two weeks (week 11 and 12), we touched briefly on a number of different concepts:

  • information hiding: 
Here we discussed python's view on the accessibility of attributes in a class and introduced the built in property(), which takes a get, a set, and a delete function as well as an optional docstring and works by setting an attribute equal to the property of any of the above functions. This allows us to vary the accessibility of users - for example, we can create the set function of property() to accept only certain values in order to restrict the possible values a user can change the attribute to. Or, we can input only a get function to property() to make an attribute read only.
  • MapReduce:
MapReduce is composed of two parts: it maps a function through an iterable which sorts or filters the values, and then it reduces it to one value. This allows more efficient processing of large data sets by allowing operations to be run in parallel. In order to reinforce our understanding, Danny introduced the reduce() function from the functools module runs a function through an iterable pairwise to reduce it to one value.
  • scopes and namespaces
I thought this part was self explanatory, but we went through an example involving local, nonlocal, and global namespaces (using nested functions) to where python checks first when a variable is called - first local, then nonlocal, then global.
  • tracing recursive function
Here the main point that Danny made was that when tracing through recursive functions, it isn't necessary to try and go through exactly what the computer is doing. You can first go through the simplest non-recursive case, then afterwards instead of repeating the process, you can just plug in the known results (being a human you don't have to recurse over again to know what the result is) and keep on going until you reach an output.
  • memoization
Danny touched briefly on how memoization works and what its benefits are with the classic fibonacci example, and then showed us an example of a memoization decorator.

Overall, I've really enjoyed the course, and I wish everyone best of luck on their exams!

No comments:

Post a Comment