Sunday, 15 February 2015

Week 5

Week 5

Recursion saves a lot of work for computer scientists, it's a function calls itself. We did some exercises on input and output numbers using recursion. The very basic example nested list illustrated how recursion works in a simple and elegant way. I feel that recursion is a very interesting and convenient tool compare with iteration. However, tracing recursion was a bit confusing. We must trace the function calls in order, just like trying to understand how a computer thinks when calling recursion, step by step. For example:

  1. Trace nd([5, [[1, [2, 3], [4]]]])
         nd([5, [[1, [2, 3], [4]]]])
         --> 1 + max([nd(x) for x in [5, [[1, [2, 3], [4]]], ’ox’]])
         --> 1 + max([0, 3, 0]) --> 1 + 3 --> 4
    
This was an example we did in lab. The funny thing is I always have the impulsion to just sum up all the integers in the bracket. It's kind of ridiculous, but I think it's because I'm not use to recursive functions and concatenate the sub calls of the function itself. 
    
Practice. Exercise.

No comments:

Post a Comment