Wednesday, 18 February 2015

Tracing Recursion from Week 4

Tracing recursion is a very important concept for CSC148 that builds from analyzing every move a function did from CSC108. I find it very similar to debugging, however there is a different way we were taught in class to express the way we trace. In class we learned that tracing requires you to call the function on every element within the built-in function you are working with, whether it's sum(), len(), or others. With the help of my TA, I have also learned when we do "human recursion" (assuming we are the computers who hold memory), we can use a function call we traced earlier to easily compute the inner value of a function. For example, suppose we have a function called sum_list that takes in either a list of numbers and sums them or it takes in a list of integers and returns the integer value. If we know sum_list([1, 1]) is 2 and sum_list(5) is 5, then we know sum_list([[1,1], 5]) is sum([2, 5]) -> 7. Once again this is because we have seen these examples before. Recursion is a useful tool to not only shorten code, but trains your brain to effectively evaluate and use shorter steps to trace a function call.

No comments:

Post a Comment