Wednesday, 25 March 2015

Revisiting A SLOG (Week 10)

Well, we're gonna have to revisit one of our old SLOG posts and reflect on them, so we might as well dive into them.

One of the most common concepts that we've often encountered throughout CSC148 was recursion - that is, when a function calls itself for the purpose of reducing input to the smallest base case, and working from there. Initially, I felt that recursion was something that was too overemphasized, and was less significant than the traditional iterative methods of programming. The factorial question can emphasize this; we could simply iterate through from 1 to n, multiplying each value to the total to achieve our factorial value. This was effective, correct and fast. Its recursive version was albeit a bit confusing, and its functionality was limited. So why did we even bother about recursion?

It turns out that recursion was a useful tool in the wide world of data structures - by being able to perform actions that iteration is limited in. For a challenge, we can do this by trying to implement an iterative method for binary search trees; it would be frustrating to implement. Recursion offers us a form of problem solving that is efficient in reducing the overall weight of a problem. For example, when using recursion on binary search trees, it makes sense because, for example, when we try to search for a value we would traverse through each subtree in the hopes of achieving the simplest case possible - either when the value is not found, or when the value is reached. Ultimately, the point of recursion is simple; to break down problems to simpler versions of itself, and nonetheless.

Furthermore, I would also like to add that recursive functions are, in a sense, 'cleaner' and a tad bit more 'readable' than an iterative function. Proof of this can be visualized in the form of 'for loops'. In for loops, we would iterate through n values and do stuff with them. When we have multiple statements that we would like to do inside of them, they can get messy and be difficult to read. I know because I have had some troublesome experiences reading other peoples' 'for' loops, especially when there were many statements and executions in them. Recursion, on the other hand, is simpler; just a base case, and a recursive case and that's all to it. Granted, recursion can be a bother to trace in some occasions, but compared to iterative functions, are at least a little bit more nicer to come by if implemented correctly.

In conclusion, recursion > iterative loops because they are cleaner, support a wide variety of applications that iterative functions are limited to, and are much easier to delve through than large, iterative blocks.

No comments:

Post a Comment