Week 4: Introduction to Recursion

Class this week revolved around the questions of what recursion was and in what scenarios it would be applicable. 

Recursion, to the unacquainted, can be mystifying.  Code that is often no longer than a line long can handle convoluted entities like multidimensional lists.  But recursion embodies the principle strategy that underlies all programming - breaking down large problems into smaller problems to render them more pliable.

For recursion in particular, this involves breaking down the problem into a base case and a general case.  Recursion is applied to our input repeatedly until the base case is encountered, from which point we work backwards, applying the general case. Returning to our aforementioned application of multi-dimensional lists, we see that the base case is a non-list element in a 'flat' or one-dimensional list and the general case is a list element.   Though difficult to conceptualize, what this process does is break down the multidimensional lists into workable flat lists.  More on recursion next week!

No comments:

Post a Comment