Sunday, 8 February 2015

Week 5 -- Impression of Tracing Recursion from Week 4

In week 4 we studied some recursive functions, traced them and tried to design our own recursive functions. Personally I feel tracing recursive functions isn't hard. All we need is the ability to read the functions. Tracing it is simply plugging the arguments into the recursive function, and step by step write down the output. Just after a seeing a few examples and doing some practice exercises I was quiet adapted and rarely make mistakes.
However, tracing is of course very easy compared to actually designing a recursive function. In the end of lab#4 their were some exercises on designing our own recursive functions. It felt much more challenging. I felt it is very important to think systematically when designing such functions. The functions we ran into generally break the problem into two parts--the "if isinstance(a, b) " statement is used when the parts in the arguments needs to be plugged into the function and go into recursion; the "else" statement is usually when the some parts of the argument needs no more recursions. and after some slight modification (such as adding 2 to the number or 'ox' to a string), will be stored in a list as part of the output. So when designing recursive functions, we must decide when the function should keep on taking arguments inside arguments ; what kind of value reached would no longer need to run the recursive function, and what should we do to these values to give the correct final output. 

No comments:

Post a Comment