know better. Recursion is simple and elegant, and has the uncanny ability to reduce the length of code significantly. This is not to say that the reduction process is easy though - it is not. So, here I would like to, like last week list down a few short points for my future reference:
- Recursion should be used when the problem cannot be, or is impractical to be solved using loops alone
- The trick to coding a recursive function is to figure out the base case(s) - there are more often than not more than one.
- If it is too difficult to figure out the base case(s), consider writing a more convoluted version of the function, and then reduce it.
- Induction thinking is generally going to help.
- Always make sure that the recursion will eventually end.
No comments:
Post a Comment