Sunday, 8 February 2015

Tracing Recursion

At first, nested functions seemed so confusing to me.  I struggled to understand how a function could use itself to retrieve an answer. Nested lists even caused me trouble; it took me a long time to find where a list started or ended. Nested "anything" was confusing, so you can imagine how terrible learning about recursion was to me.

We began tracing recursion on paper, both in lecture and in labs. I started off evaluating every single call that I could possibly do. After one question, I noticed that I took up more space than I thought, yikes! My TA even told me that I don't have to repeat every single call since apparently, "I had already solved it in a previous statement". So I began again and strangely, it didn't seem so bad. By starting off with empty lists and lists of "depth 0" (whatever that means... I'll learn what it means eventually), I began to understand that I can use the solution that I had just retrieved to find another solution for the next bigger list. Then, you do it again. I was able to evaluate a list of depth 5 without even knowing it.

And so I learned that doing things at the most basic and fundamental level would help me achieve bigger problems. Hey, that's exactly what recursion is!

No comments:

Post a Comment