Monday, March 2, 2015

Recursion



Recursion is a useful tool that we learned in CSC148 which was helpful for us to solve many complex and combinatorial problem. For instance, using a simple recursive method sum_list, we were able to solve the rather complicated problems of lists within lists.

In CSC148,we were also taught about trees, which is just an application of recursion. Trees are potentially recursive because when we solve a problem related to trees, we always try to reduce it to the root, which is potentially the base case. The tree is a perfect demonstration of the fundamental feature of recursive function .In my opinion, recursive functions have two attributes. A base case in which the recursion stops and a line of code that will operate recursively and eventually reduce the input into meeting the condition of the base case.

The most difficult part with writing recursive function actually lies on identifying the base case. This can be hard sometimes as the base case may not be that obvious. However, once we have the base case established, all we have to do is to write a recursive function that returns the input into fulfilling the condition of the base case, and we are done.

No comments:

Post a Comment