Sunday, March 2, 2014

Week 7: Recursion

Recursion is the definition of a function in terms of itself, usually in term of smaller values. A recursive function calls itself in the definition of the function; meaning in order to solve a complicated problem, a program could break it down into smaller problems, sometimes making a near impossible function easy to interpret. This method of defining a function has been greatly influential to the way computer science thinks and the construction of larger scaled programs. A recursive function always has a base case, this is the basis of any recursive function; a function is usually broken down all the way to the base case where the result is defined with a return statement, any value other than the base case will use the base case as a stepping stone in the evaluation of the function.
My first experience with recursion comes from high school computer science club. Preparing for programming competitions, we started off the year with topics on recursion; it was pretty daunting at the time as I have just started to learn Java. The concept itself was hard to handle at first; we started with the usual Fibonacci sequence, defining base case and the rest as the sum of its previous terms. As with OOP which I discussed in my first post, I initially disliked recursion because for many cases, a function can be done without it, and the way without recursion was more appealing to me for its easiness of understanding, and that I was able to follow it without any problem. Now with larger assignments in university, I have really come to appreciate recursion when an answer is returned within seconds instead of minutes, or even hours, the efficiency of a recursive function is really why it is so important to computer scientists. With recursion, however, I find tracing to be very difficult at first, not only was it hard to track the steps in the function; it was a mess trying to keep track of the previous results. It have gotten easier as I was exposed to more examples, specifically those that I traced by paper over the years. Now I feel very comfortable with recursion, in fact, recursion is always one of the first things in my mind at the start of a problem. Recursion opens up a lot of options in problem-solving and it is something I definitely look forward to more in the future.

No comments:

Post a Comment