Friday, 28 February 2014

Week 7 - Recursion

Over the past few weeks, this class has focused heavily on recursion and recursive solutions to problems. I've been exposed to this idea previously in high school computer science classes, but we had never really done an in-depth examination of the topic. I do remember thinking upon first encountering recursion that it really seemed quite trivial. The idea, it seemed, was simple; you have a function, and you call the same function within that function. At the time, the whole idea seemed to be purely academic in nature and of no practical purpose.

Using recursion in class and for the first assignment has necessitated developing a much more intimate acquaintance with the concept, and this has shattered many of those naive high school prejudices. First and foremost, I have been rudely awakened to the fact that, despite its deceptively simple definition, recursion is not at all a simple concept. Never have I had such difficulty wrapping my head around an idea, and what is most aggravating is that the code, on the face of it, seems so simple. Just a few lines of seemingly innocent, straightforward Python proves to be an utter headache to decipher. Honestly, even at this point, several weeks after the introduction to the topic, I still find it difficult to trace the path of the program, and I've learned there's rarely any point in doing so anymore. It seems best to take a mental leap of faith instead of troubling myself with the details, trusting the program will execute as I intend it to without fully comprehending exactly how it does that.

What has been most striking is the sheer usefulness of recursion. One of the mantras of computer science classes seems to be "there are many ways to solve a problem" - and yet many of the problems encountered in this course have no apparent solution besides a recursive one. It's difficult to accept that what appears to be such a complex problem (such as the Towers of Hanoi game given in class) can be solved with only a few lines of recursive code. I suppose this speaks to the immense usefulness of recursion to computer science. I would definitely be interested in seeing a more practical, real-world example of recursion in play.