For tracing the recursion code, I think it is the easiest part in the study of recursion. Just plug some examples which is from easy to hard into the code step by step and finally we will get the correct result unless we are not carefully enough.
For writing the recursion codes, it is a further lever of studying the recursion. Here is the way it goes, the problem with recursion can be easily solved and will be straightforward if you get used to recursive thinking. However, you can't even write a word on it if you are not familiar with the recursive thinking. So, a recursive way of thinking is very necessary for us to learn the recursion.
So how to think like that? It is kind of different from when we do a normal code. Unlike we try to figure out the necessary code that can return the result we want when we are writing the code without recursion, we need to get the idea that what does the whole function do and think in a opposite way, which is that we assume that we've already got that function and use it as a helper function into the code. Before using that, we need to find a base case, which is the easiest possible result that it might return.
For me, although I got the idea how the recursion works, I still need more practice on that. I did the lab about recursion with some easy exercise and I got them all right. But the fact is that the recursion is weigh much harder than what we did before as we've started learning the tree which has almost every function that has to be done using recursion. I hope I can get used to that.
No comments:
Post a Comment