Matrix

Saturday, 28 February 2015

Week 7: The Return of Recursion

So as reading week ends and class starts up again, we are told to write a summary about a key concept that we have learned. I chose recursion because I struggled with it in labs and on the midterm so naturally I studied it the most afterwards. 


So what is recursion exactly and why is it important to computer science? Recursion is a type of method in computer science where a function is able to call itself to solve smaller instances of the same problem. The opposite style of code to recursion is the generic iteration style that we used throughout CSC108. Iteration is looping through a block of code until it solves the problem. So recursion is sort of like a type of iteration. There is technically no real need for recursion. Everything you do with recursion can be accomplished with iteration through loops. The real benefit to recursion however, is that it simplifies things when you must run through a lot of code and it cleans it up in an "elegant" way. This makes the program run faster and becomes more easier to look at and understand. For example in class, our professor was able to cleanly go through complicated lists with many brackets by using a recursion function. This saves a lot of time and makes "traversing" through complicated code a lot easier than iteration. 


In class, there have been several examples of recursion use in Python. We have not written any of our own recursion as of yet but merely trace the code in order to understand the core idea of recursion better. Most examples include complex, nested lists and ask for the result when a recursive function is run on them. The labs offered more practice with tracing recursive functions and although tedious, they offer practice which is valuable in understanding recursion. In general, I think the concept of recursion is very hard to grasp at first. I found the entire concept behind it to be quite foreign to me. You don't understand how it works by calling itself while you run it. This is why tracing the code is so important for practice and understanding. However,with practice, it becomes second nature to simplify your code and understand how each line is being run. Ultimately, that saves a lot of time down the road when you include complicated inputs. Learning recursion is absolutely vital I think so it is great that I took the time to learn it. It will help immensely in the present and future. 

No comments:

Post a Comment

Matrix