Recursion is one of the most important concepts in algorithm. Once you understand it, it is quite fair to say that you may have mastered almost "half" of the algorithm.
Recursion is based one an obvious fact: computers can do repetitive operations in a much faster way than human beings. In practice, to avoid infinite loop, the terminating condition has to be clear. Thus, the size of the problem to be solved has to become smaller (Neither the same Nor larger) for every recursive call, which eventually converges to the base case.
The base cases usually have very small sizes which can return the results trivially.
To sum up, some key points:
a). base cases with trivial returns;
b). the same question but a shrinking size.
Comments
Post a Comment