This week, we mainly learned recursion and some applications.
It firstly seemed to be magic because the function can call itself recursively as if it is already defined. But as I learned more about it, I found that it just execute many times until it gets a return value and it will put its return value to the last step until all the steps have been accomplished. It needs base class to tell when to stop.
I can understand most of the examples of recursion functions but I still have some difficulties in writing my own recursion functions. I found tracing the recursion is very useful in understanding it.
I have read the handout for assignment 1 but I haven't started coding yet.
I hope I can finally understand recursion fully.
Recursion is like induction in mathematics. You do not have to know what the function exactly do. Assuming what function you write is correct, you think about what next step do. Base case is important.
ReplyDeleteThank you for the comment. You are absolutely right!
Delete