By looking up the word Recursion in the dictionary, it means the repeated application of a recursive procedure. When I first saw the technique of using recursion, I thought it was amazing and kind of abstract. We have to break down something and go through each time the recursion works. For me, I think recursion is something we reused itself in the process. We create something while it exists in its own body. It is really hard to understand it for people who are not familiar with computer science.
I first saw this word in high school. I remembered it appeared on the math textbook in the sequence chapter. The recursion defines some kind of sequence where the sequence itself is neither arithmetic nor geometric sequence. Such sequence has the characteristic where a term is dependent on the previous term.
By using recursion, we can break down a huge problem into simpler problem and apply the same approach multiple times to ace a task. The process is going to end while the base case is reached.
For example, when we encounter a list of list, a recursive function is helpful to determine the largest value of this list of list object. Because the object is a list of list, we can crate a recursive program that works for a list and reused it for the elements within the list since those elements are just list. Here, a problem is reduced to a smaller one since the program is "recycled" and we don't need to create more steps to due with the elements inside the list. Recursion, again, suits for the big topic - laziness.
It impressed me when it is even being used in the Tower of Hanoi problem. We solve the problem quick and easy. If I were being asked to solve the problem, I think I will use much more moves to finish it, but with recursion, everything is being done in a few second. However, it is annoying when sometimes we don't recognize the situation for recursion. In the next few weeks, I must understand more about it and grab all the techniques and tricks of recursion.
See you soon!
No comments:
Post a Comment