Saturday, 7 February 2015

Impressions on Recursion

I think the problem of counting the elements of a list, which are organized in varying depths, is an interesting one because it is a very simplistic problem with a very, initially, unintuitive solution. Up until now, we've been programming for very consistent and concrete parameters, so being faced with a problem involving arbitrary parameters (and I mean the depth of the list argument, not function parameters necessarily) is kind of frightening as it's not immediately clear how to approach it.

Luckily, more intelligent minds have done the work for us and thus we learned recursion. Now, different problems still require fairly differing solutions so it is not exactly a plug-in-the-numbers solution (and I assume recursion will be used for much more complex tasks). But the idea of calling a function on itself seems like cheating or rule-breaking or outside of most people's consideration. So being introduced to a new way of thinking about how functions interact was quite intriguing (and partially terrifying, thinking of the complex problems to come).

Like most logical solutions, it makes sense once you see it written down and tracing, though still confusing at first, is easy enough if you tackle it one item at a time. It'll be interesting to see what happens once we are asked to create our own, novel recursive solutions...

No comments:

Post a Comment