About recursion
We have been learning recursion for several weeks. Actually, I think it does show the strong power of the computer. In recursion, we need to trace the process from top to bottom(like popping the item from a stack) and then return the result back from bottom to top(like re-pushing the item to a stack). For us, it is an extremely tedious and error-prone process but for computers, it can be done in a short time.
The computer science version of "series"
I think it efficiently takes advantage of computers' characteristics. A computer can repeat and memorize the function call and its corresponding result or another function call through many unique addresses whatever the number of iteration is. For example, it is very hard to trace a complex series for us (we may make some mistakes in calculation or forget the results) but it would be just several-time iterations for only one function call(i.e. the formula) for the computer.
Loop & Recursion
Recursion is very similar with a loop. Both of them need to repeat one or several functions. However, I think there are several obvious differences between them. First, a loop needs a condition to judge whether it has finished(i.e. a boolean sentence in 'while' or a range in 'for'), whereas a recursion needs a bases case and could be done when the result can be obtained by computer itself. Second, for the recursion we need to conceive how to make sure the result from an iteration can be applied in the next iteration, whereas for the loop, the result of every iteration can be independent. Therefore, when we know a base case and how to apply the result in new iterations but don't know the condition to judge the process, we'd better use a recursion.
Challenge
In my view, recursion is a relatively abstract concept in programming. Sometimes it is like a "magic". For example, in the assignment 1, when we consider how to move n cheeses in 3 stools, we wrote a function and told the computer step1, step2 and step3(As in the lecture). For us, it is really difficult because the indexes which the"source", the "intermediate" and the "destination" stool refer to will be exchanged in every iteration and in the meantime we need to calculate and memorize the result of every combination. We tell the approach and the starting point then the computer shows us the result but we don't know what happened in the process.
Achievement
Although it is not easy, I think I have learned the crucial conception of recursion. Assignment 1, readings and labs and test( I just got the score of test1! lol!) help me comprehend the recursion totally. For instance, in the lab5, I learned some useful built-in functions in python such as filter, all and any. Then I can save much time and space in programming! Now, we have begun to learn tree and linked list. I hope I can successfully use the power of recursion to win in the following challenges!
No comments:
Post a Comment