Friday, 27 February 2015

Week 5: Recursion

ThisView blog is the fifth week of CSC148 and this week we covered recursion in our lecture. When Professor Heap first introduced the idea in class I was extremely happy to note that I had knowledge about this topic before hand. Factorials had been a common high school topic and I was easily able to translate the ideas into code. In my mind, recursion was simply a form of python script that called itself repeatably until it reaches the deepest element. Here is my implementation of factorial:


What I didn't know about recursion was that it is a extremely repetitive process. I noticed this after I can it through the python visualizer and noticed the amount of calls to line 2 and 4 that were made. Basically every time the function called itself, python had to determine whether the n-1 was equal to 1 or not. In addition, I gave myself a simple example and traced the code by hand when n = 4.


Summarizing my thoughts on tracing recursion, I found that I must first locate the recursive function and then use this code and apply it to each element of the object. Then making my way to unravel each of the calls to the lowest element. 

During the lab, I found that my understanding of recursion made it easy to do the lab material and quiz as I only thought of the questions presented as an onion that has multiple layers, slowly unwrapping until I reached the core.

I also found this video extremely helpful with my understanding of recursion:

https://www.youtube.com/watch?v=s12IdMeVpw0


No comments:

Post a Comment