Sunday, 8 February 2015

Impression of recursion

    In the last few weeks, we learned about recursion. Actually when I saw this word, things that came to my mind first are 'for loop' and 'while loop'. After the lecture, I found that in fact, it's more concise and, even beautiful!
    Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially. Usually recursion involves a function calling itself. While it may not seem like much on the surface, recursion allows us to write elegant solutions to problems that may otherwise be very difficult to program. Instead of writing several lines of 'for loop' and 'while loop', recursion can just solve the problem in much fewer codes, which is absolutely its advantage. However, I also came up with the problem that sometimes it may take more time to work out a recursion than just to use a for loop or while loop. Anyways, it's a great way to solve big problems and I'm sure it'll be useful in our future learning.

No comments:

Post a Comment