Thursday, February 5, 2015

Week5:Tracing recursion from week4

Recursion is a kind of very computational programming style that is recalling the function itself. For example it is like dividing 10 by 3, and each digit is 3 because we are dividing 10 by 3 recursively. However, in a recursion there is a base case which  tells when the recursion should stop. Since we can use only one recursion function, which is always short, to deal with huge algorithm, recursion makes our coding easier. Once we think it recursively, we can finish it in fewer lines of codes. Otherwise, I believe it should be several "for loop" with a lot of if statements.
    To master recursion, I have two steps and one strategy. At first, you should always find out the base case. The base case does not only ensure the ending of the recursion, but also give you a primary understanding of the algorithm. After that, normally, you can just move one step up, and think about the situation which has only one recursive step. If you can deal with that, you are done with your recursion problem. The strategy I really love to use is list comprehension. I believe this is a very useful way to right the recursion function. For instance, when I come up with a recursion idea, I will describe it in  English. Since python is a pretty readable programming language, my description can always be easily transfer to a list comprehension format. For example,  my description is like do something when balabla, otherwise, I will do something else, for every item in the list.  SEE! This is almost a list comprehension format, and I am almost done with the recursion problem.

No comments:

Post a Comment