Sunday 2 March 2014

When I first learned recursion I was extremely confused. It didn’t seem to make sense to me. After all how could the function being written possibly call itself, that didn’t make sense. So when assignment 1 came around I was extremely worried and had no desire at all to do the recursion part of the formula. So, as my usual strategy to deal with difficult concepts I procrastinated quite a lot. However, when the time came I really had no idea how to deal with the concept. As a result I simply traced the function given to us in class to get a hazy idea of recursion and how to use it in the assignment. It wasn’t really until I was studying for the test that I managed to understand the concept. I figure it out by tracing functions and writing it out on a piece of paper to explain it to myself. So when the blog came around and we had to write about recursion I figured why not simply upload the piece of paper to the blog. I have done so however it’s quite messy so I figured I’d explain it as well through typing.

                So the way I learned to understand recursion was by writing out the most general case and the flow chart type which follows through. So I figured I would write it out to explain it:



def function_name(x):
               

base case: The base case typically is a bool function that calls the function again to repeat if it is true. What this does it to continually call the function until it returns false. When it returns false it gives the base or target value. It also always comes first.

General case:  This is typically the workhorse of the function.  This case calls function_name(x) on the recursive part of the function. This works on the current variable or is altered by the general case. 

The thing that really helped me fully grasp this super complicated process was by tracing which I have also uploaded an example of. Also drawing out a diagram of what happens really helped and it turned out to be in the same format as the recursive trees we’ve learned about in class although each step is thoroughly expanded upon. the picture of the diagram is on the uploaded pictures.This same process continues until each child eventually reaches the target base point. At which point it continues up to the top until the top general case is filled with base case and returns the target value. So this is how I personally understand recursion. It was an extremely difficult concept to grasp but after tracing through really basic examples and drawing out general cases I have come to truly understand recursion and I hope I have explained it to you as adequately as possible. I have attached a picture of an example of tracing through a function to help grasp the concept of recursion.


No comments:

Post a Comment