recursion is a programming technique that calls itself in a function or method, and the idea of recursion is to decompose large problems into small problems, further decomposing them into smaller problems, until each small problem can be solved, that is, recursion is
Describe yourself with a similar but small problem.
Three features of the recursive algorithm:
1, solving the problem of size n can be transformed into one or more structures of the same size, and then from these smaller problems can easily construct a solution of the big problem
2, the number of recursive calls must be limited
3, recursion must have an end condition to terminate recursion,
The recursive algorithm executes two stages of recursion and recursion. In the recursive phase, the solution of the problem of scale n is recursive to the problem of smaller size, and the condition of terminating recursion must be provided. In the regression stage, after the solution of the simplest problem is obtained, the solution of large scale problem is obtained in succession. Recursive algorithm, whether in space or time consumption is more than the plop algorithm, in the algorithm design often recursive algorithm into a non-recursive algorithm, the conversion method has the following 3 kinds:
1, through the analysis skip decomposition step, directly with the loop structure to evaluate
2, using the stack to save the program's running process, through the analysis to save only the information must be saved, thus using non-recursive algorithm instead of recursive algorithm
3, using the stack to save the parameters, because the stack of the last-first-out characteristics of the recursive algorithm is consistent with the execution, so the non-recursive algorithm can replace the recursive algorithm
The core idea of recursive algorithm