Monday, 2 February 2015

Recursion

  Last week we moved into a new chapter: recursion. In class and in the tutorial we did several examples of tracing function that uses recursion. I find recursion a very tricky concept. I have no problem tracing the functions, however I always get stuck writing a function using recursion.

  We were introduced to recursion in three levels. First, we encountered a function using recursion including its docstring. This was simple, since we can “cheat” and know what to expect from the docstring, without perhaps a solid understanding of how the code works. Next, we did several questions in the tutorial of functions without the docstring. This is only slightly trickier, since after a few examples of tracing the code, the logic of the recursion shows up. However, I have difficulties going the opposite direction: coming up with my own code using recursion. I feel like I understand the concept of building and accumulating from the special case (since when tracing, everything eventually reduces to the special case, in most of our cases when the object is not a list), but I think I need more practice.


  It is a relief knowing that in our term test we will only need to trace recursion functions. However, I will have to catch up on implementing recursion in my own code, since it will be a very useful and necessary skill.

No comments:

Post a Comment