As I've taken computer science courses since grade 10, I'm no stranger to recursion. I first learned about recursion in grade 11, and to be honest it was quite a complicated concept to grasp to begin with. But with enough practice and use in practical programming, it becomes much easier to understand. Recursion can be a very effective and simple solution to many kinds of problems.
A very pleasant thing about recursion (once understood) is that recursion is always the same, in every case - stop when base case is reached, else get closer to it. Because recursion is always like this, implementing it once means you can implement it in other situations very much in a similar fashion.
For me to produce a recursive program, I start out with identifying the base case, which is usually straight forward. Standardizing a method to get closer to the base case, on the other hand, can be more difficult. A general piece of advice I would give to anyone struggling with recursive programs would be to start out with a simple example, simple enough such that one could trace it in their head. This helps find the base case, and also how to get closer to it.
No comments:
Post a Comment