Sunday, March 2, 2014

Week 7: Recursion

This week's assigned topic is recursion! To start off: what is recursion?

From my understanding, recursion is a using method, which calls itself, to solve a particular problem by dividing the problem into smaller, simpler pieces. A recursive method includes a base case, which is the most simplest case of the problem, and the recursive part, which takes the input and calls itself on a smaller piece of the input.

Recursion can be very useful for problems that can be easily divided into smaller sub problems or simpler cases. The advantages of recursion are that it would take less lines of code to write and are sometimes easier to understand and implement. 

However, recursion isn't always the best method to solve a problem because in some cases it may be possible to use explicit formulas or loops. For example, when calculating factorials, it is possible to use recursion, however it would be more efficient to use a loop. The disadvantages are that it could take more time and memory to solve certain problems, and initially understanding how the recursion works.

From my own personal experience, while working on the Towers of Anne Hoy assignment, my partners and I encountered some difficulties such as finding the best "i" to use for a certain number of cheeses, and also encountered many bugs and errors such as the max recursion depth error. What we did which helped us throughout the assignment was to trace the recursive problems on paper as well as play around with the given gui controller to figure out the simpler cases of the problem. 

In conclusion, recursion has its advantages, such as taking less lines of code to write and being simple, and disadvantages, such as taking more time and memory for certain problems, and can be useful in cases where the problem can be divided into smaller sub problems

No comments:

Post a Comment