Tuesday, 10 February 2015

Tracing Recursions

So we started with tracing recursions this week and i figure i like them a lot compared to the concepts we'd been covering earlier in the course. I find it easier than Classes and more interesting too.

It gets a bit confusing sometimes, seeing how you need to exactly pinpoint what's going on. I had to remember the fact that when i write...

def blah(n)
    if isinstance(L, list):
         return sum(blah(n) for n in L)
    else:
         return 1

...blah(n) occurs inside the function itself, so there is another function running in the actual function i.e. blah(n) is running inside blah(n). However when i did more examples of these and looked at them carefully, i started getting the hang of it.


We're starting with trees on week 6 and i'm looking forward (but also slightly scared) to see where this takes us and to see what new things we're going to learn in the upcoming weeks.

Photo from: http://www.megamonalisa.com/artworks/megamonalisa_recursion.jpg

No comments:

Post a Comment