2016年3月3日星期四

Week 7 thoughts on recursion.

I learned recursion this week. It is a fun but useful concept. Rather than using loop, it gives an intuitive approach to the problem. For example, solving the factorial using recursion is the same way treating it as a math problem: think from the bottom/base case and go “up”. In some way recursion is a vivid representation of math models. The Fibonacci numbers is another example of how recursion can be really useful in solving complicated math problems. Unfortunately, even though recursion is a fantastic tool, it is not applicable in some cases. Surprisingly, the Fibonacci number is one of those cases. Normal recursion algorithm would provide the correct answer, and it is intuitive and easy to understand. However, it suffers the combinatorial explosion: the runtime of the algorithm increases exponentially with the complexity of the Fibonacci Number. The actual better way to do it is to just use loops and store the values and the series in an array. This way the run time decreases dramatically and still provide the correct answer.

In summary, recursion is a very useful tool to use, but the programmer has make a clever decision on whether to implement it in certain problems.

没有评论:

发表评论