Sunday, 2 March 2014

More on Recursion

After initially discussing recursion in lectures during Week 4, I posted a brief summary of recursion and gave the example of determinants (dated February 2 2014).  This is a continuation of that initial post.  

I won't dwell into the basic notions of Recursion again but an interesting provisional definition of Recursion may be --> Recursion:  If you don't understand Recursion, see Recursion. 

Take an example of recursion as it applies to the mathematical concept of a factorial.  For instance, 3! = 3 * 2 * 1 and 5! = 5 * 4 *3 * 2 * 1.  This leads to the following recursive definition.

0!  = 1
                     n! = n * (n - 1)! ,   for all n > 0

The first equation is the base case, and the second equation is recursive since a factorial is defined in terms of a factorial.  The python code for the factorial function can be found at the following link: http://stackoverflow.com/questions/4502429/recursive-factorial-function

Now since Week 4, we've studied Trees and Linked Lists which are recursive data structures by nature.  (Note, I discussed Trees in a previous post.)   I personally found implementing recursive code to initially be tantalizing (ok I'm exaggerating) however recursion has slowly but surely been growing on me.  I found implementing the recursive code for Linked Lists to be slightly harder than Trees, although this is probably a bias on my part.  Since the first term test, I've had minimal time to thoroughly study Linked Lists, although I hope to devote some time on Monday to mastering this concept. 

No comments:

Post a Comment