Friday, 20 February 2015

Recursion Take Two

Even though I've practiced it a couple of times, recursion is a challenge I continue to hate. In Assignment 2 I was forced to implement a recursive function but I'm still a bit iffy about it. Its not impossible to write a recursive function because of the steps that have been nailed into my mind; Step 1- What is the base case?, and step 2- Take the base case and make it recursive. As simple as that may sound, writing a recursive function is a bit tricky.

I love to trace a recursive function, I can do that in my sleep haha, but the thought of writing a recursive function is a challenge that I don't want to face, even though i know it will reappear on the second midterm.

The base case if you didn't know by now, is the simplest case that doesn't require recursion, it usually will be part of an if statement, that returns a generic statement such as; Return False, or Return 1; and after that the 'else' statement is the recursing one. Through my experiences when writing a recursive method on trees, the recursive part is usually [ method name (x) for x in [child or node...etc]]. As struggling as a recursive method may be and the fact that I haven't really used it unless told too, I fell recursion is a tool I should wield in my computer science tool belt.

No comments:

Post a Comment