2015年3月1日星期日

What did we do in week 4.

In week 4, we learned about recursion.
In a recursion, first of all we have a base case. Base cases are always very simple, and most of time they can be testified  within a few lines of code.
Besides the base case, a recursion also have constructor cases. When a recursive program with a given input failed to be testified as one of the base cases of such program, the program would call on itself with some new input which are decided by the original input. Then the program go through the same process of testifying whether the new input belong to the base cases. Hopefully, the program will finally reach the base case and then it will return the output value all the way back to the program with the starting input.

When writing recursive functions, we should be aware that our program will reach the base case gradually, otherwise the function would go into an infinite loop.

没有评论:

发表评论