One of the new things that has been taught to us this semester is Recursion. The definition of the word "Recursion" is "the process of repeating items in a self similar way". In Computer Science, recursion mean "to define something within itself. A recursive function would be a function that calls itself in it's definition. This is somewhat similar to an iterative function definition that has a loop. Recursion is a powerful tool because functions can call themselves multiple times in order to achieve their objective or goal. However, in order for the recursive function to know when to stop calling itself, it must have a base case. Base Case is defined as "A branch of the conditional statement in a recursive function that does not give rise to further recursive calls." Without the base case, the recursive function will not stop calling itself and will eventually result in a recursion depth exceeded error. Base case could be somewhat compared to the condition in a while loop, because the base case will stop the recursive calls once its conditions are met, just like a while loop will stop when the condition of the while statement is fulfilled. Therefore, base cases are always included in the conditional structure of a Recursive Functions. Also included in the conditional structure of a recursive function is a general case. A general case specifies how to combine recursive subcalls.
After studying recursion for a couple of weeks now, I understand why it is a very useful and powerful tool to use in Computer Science. However, I am personally having a difficult time applying the idea or concept of it into my own coding. For example, If I see a problem where I believe recursion could be used, I sometimes don't know how to code the recursive function correctly, especially for more complex problems. Also, I also have found that tracing a recursive function to be a really big challenge. I remember at the beginning of CSC108, my professor said that Computer Science is one of the courses where the time it takes people to understand and be able to solve problems varies wildly, where in some cases a problem could take one person a short amount of time to solve, and another person a very long time to solve. I think I am one of those people that take a longer time to apply the concepts we have learned to programming. I believe it will come in time and through practice.
In conclusion, I personally believe Recursion is an important aspect to learn in Computer Science since it could be used in so many ways to solve small problems and big problems. Additionally, if coded right, it will save a programmer a lot of duplicate code, which contributes to the idea of "laziness" in Computer Science. I think I have made progress since first learning Recursion since I now understand its concept and purpose a lot more than I did before, now its just a matter of being able to apply it when I have to solve problems on my own.
No comments:
Post a Comment