Thursday, February 5, 2015

Week 5: impressions of tracing recursion from week 4



The main topic of week4 is recursion, as mentioned before in my week4 SLOG. Recursion means using the function itself in a particular function as a helper function. In the lecture section, practices were done to give me a straightforward understanding of recursion.

After tracing a list with depth of 1, we believe that the function works well on this kind of list. So we won’t bother tracing the list with depth 1 in other lists afterwards. Then we can work on lists with depth 2, 3, 4 and so on. This is the concept of recursion. Proving the former one also proves the next step. Recursion in programming is like complete induction in math. This is where I feel csc148 is related to other course tightly—being thoughtful and organized is required in these courses.

In last week’s lab, we were assigned to trace some codes and design a recursive function by ourselves. It is not very difficult to trace the code, however, I felt challenged to write the recursive code. At first, I did the same way as what I did in the lecture. Unfortunately, it couldn’t work properly. Then I decided to create a variable to store the value which would change in next step and add it to the result at the end. This solution works perfectly in my several trials. To be honest, introducing a new variable isn’t new knowledge for me, but I can’t come up with the idea to apply it to my code at first. Last week’s experience teaches me that I’m supposed to integrate my learnings into new knowledge. 

No comments:

Post a Comment