Thursday, February 27, 2014

Week 4 - Recursion

This week of class focused on learning to solve problems using recursive functions.  That is to say, a function that calls itself under specific circumstances.  Deciding when to use a recursive function, as well as how to write it, was pretty tricky at first, especially since it was a very minor part of my high school course, but I was able to get a good grasp on how to work with them.  In a recursive function, you need a general case, and at least one base case.  Recursive functions necessarily take the form of conditional statements, since if there was no condition for the recursive call, the function would repeat itself indefinitely.  The base cases serve as the stopping points for the function, and returning a value instead of repeating the recursion.  The first assignment was talked about, with it being noted that recursion would be necessary in writing the program, so it was good that I had the chance to practice recursion to a level I was comfortable with before I started.

I didn't have any real difficulties with the work this week.  The lab was pretty simple for me and my partner, and the exercise on raising exceptions was straightforward.  There was one thing that was in the lecture that would have been useful in my code for Assignment 1:  The fact that a set of tuples is a valid argument for min.  I ended up using a different approach to the problem that may not have been ideal, but I'll just have to remember that information for the future.

No comments:

Post a Comment