This is the first time that I learn about recursion in
computer science. My first impression was that recursion seems to be like loop.
You go over a process again and again. But then I realized they are actually
very different. Recursion is not simply repeating a process, but going to a
deeper layer at the same time.
The method I follow every time I write a recursion is
basically what Danny taught us in class. The first step is to find the simplest
situation, which seems to be easy. But you have to find a return value that is
coordinate with the code you are going to write next. Then I will consider the
situation where recursion appears once and figure out the code through which I
get the right result. Last, checking with the situation where recursion appears
twice or more times is a good idea.
So far we have learnt recursions in some different scenarios
like tree, nested lists and so on. I get a rough idea when we should use
recursions. It’s when you need to apply the same thing to many layers of an
object. Peeling an onion may be a good analogy. You peel down every layer of an
onion in the same way until you get the basic layer.
No comments:
Post a Comment