Friday, February 6, 2015

Recursion

    This past week we started to learn the basics of recursion. Although I have kind of learned recursion before, I was never really able to truly understand it. All I knew about recursion was that the function would actually call itself over and over again until it reaches a condition that makes it stop... Now that I think about it... it's kind of like inception, but instead of going deeper and deeper into dreams you're going in deeper and deeper into the layers of code every time the function calls itself.

    The work we have done so far with recursion is just tracing the code when a recursive function is called with a list and we trace the code with nested lists as well to get the final result. I guess the biggest problem I had with tracing recursion was knowing when to replace calls I've already traced with their value. So with that problem, instead of tracing something like sum_list([[1, 2, 3], [4, 5], ,8]) in 2-3 lines, I would end up tracing each call of the function so I end up with 6 or 7 lines which most of them I have already traced before.

    After doing the lab on recursion, I feel that I have a much better understanding of it and I can trace simple recursive functions without much trouble. But one of the exercises on the lab was to write a recursive function and since we never went over how to actually write a recursive function during the lectures, I had quite a bit of trouble with that. After working on it for a while, my lab partner and I were finally able to write a recursive function. Since the lab ended of with a bit of practice on writing recursive functions, I guess this weeks lectures will teach us how to actually write recursive functions!

No comments:

Post a Comment