Current location - Training Enrollment Network - Mathematics courses - What problems are recursive functions usually used to solve?
What problems are recursive functions usually used to solve?
Recursive functions are usually used to solve the self-similarity problem of structures. The so-called structural self-similarity means that the sub-problems that constitute the original problem are similar in structure to the original problem and can be solved in a similar way. Specifically, the solution of the whole problem can be divided into two parts: the first part is some special cases with direct solutions; The second part is similar to the original question, but on a smaller scale. Recursion is actually to turn a big problem that can't or can't be solved well into one or several small problems, and then further decompose these small problems into smaller problems until each small problem can be solved directly. Therefore, recursion has two basic elements:

(1) Boundary condition: Determine when recursion ends, also called recursion exit.

(2) Recursive mode: How to decompose a big problem into small problems, also called recursive body. Only when the recursive function has these two elements can it get the result after a limited number of calculations.

Recursion means that a function directly or indirectly calls itself, which is called recursive call. To put it bluntly, it is still a function call. Since it is a function call, there is an unshakable principle: all called functions will create a copy, which will serve the caller alone and will not be affected by other functions.