Saturday, 22 February 2014

Reading Week: Thoughts on Recursion!

For this past week I haven't been up to much CS on account of a significant pile of math homework.  However, I still have had time to think about the midterm as well as recursion, a rather interesting topic.

The first time I had recursion explained to me, it was somewhat confusingly done with matryoshka dolls (those russian dolls made of wood, in increasing sizes where opening one reveals another).  The second time was more concise: "A recursive function is one that calls itself."  In a computer science context, this explanation made a lot more sense.  Like induction, recursion calls for a base case: unlike induction however, it is more like a final stage instead of a first step.  In this sense, recursion takes a large problem and continues to reduce it to a slightly smaller problem, until it reaches the base case and can be solved.  There's a caveat to this however, a function which employs recursion may not be the most efficient, since it has to go through every previous case.  In our Towers of Hanoi assignment, I certainly noticed this.  Because of the degree to which Tour.py relied on recursion, its efficiency was rather questionable (this of course, may be a result of my inability to code efficiently but I'm going to attribute it to recursion for argument's sake).  Despite this, recursion certainly makes the code easy to read and to understand, and it was really the only way I could think of to code the assignment.

In my experience with math, I've seen recursion come up in the definition of some very pretty fractal pictures, I'm even guilty of making a Menger Sponge cake (second iteration, made of many tiny delicious cake cubes held together by cream cheese icing).  To learn about the use of recursion in CS has been very interesting for me.  I can appreciate its usefulness very much.

I'm (not) looking forward to the midterm this coming week and I feel totally (not) prepared!  Here's to NOT failing.

3 comments:

  1. hey I totally forgot how recursion could be inefficient in some cases. Thanks for the input.

    ReplyDelete
  2. I found some link to the time efficiency of recursion vs looping. Hope this helps. http://stackoverflow.com/questions/2651112/is-recursion-ever-faster-than-looping/2651200#2651200

    ReplyDelete
  3. Thanks for the link! That's very interesting!

    ReplyDelete