Saturday, March 1, 2014

Weekly Summary 3/1 - Recursion

For the past few weeks, we have been doing a lot of recursion exercises in class. Recursion is a function that calls itself to solve a problem more efficiently. Although recursion is a really great skill and tool to have, it requires a really clear thought process to implement. A recursion function calls itself until it exits through a base case outlined in the function. If a base case is not implemented, the recursion function will not be able to provide a valid output.

One of the key insight that I have learned from implementing recursions is that you often have to take a leap of faith. I usually think of what the function should look like under the base case. After that, I just simply fill in the codes to describe the situation recursion should occur in. Recursion functions are usually really complex to understand so it is really important to just implement it rather than making sure everything goes right in the planning process. Once a recursion function is written out, tracing it under different test cases can shed insights to any problems that the function might have.

In Assignment 1, we were given a harder recursion problem to solve, the four stool variation of tower of Hanoi. I was having a lot of trouble tackling this function at first, since I only had experience solving the simpler recursion functions such as the nested_depth in class. Although it took me some time, but I was finally able to implement the recursion function and reduce the number of moves required in comparison to the three stool tower of Hanoi. The key takeaway for me is that it is really important to break down the problem into smaller parts and solve it from there. Although I faced a lot of difficulties regarding recursion at first, but now I feel a lot more comfortable through all the exercises presented in class and lab sessions.

No comments:

Post a Comment