Current location - Trademark Inquiry Complete Network - Futures platform - What is recursion? What is iteration?
What is recursion? What is iteration?
The difference between "recursion" and "iteration" is as follows:

1, the basic concept of recursion: the programming skill of the calling program itself is called recursion, that is, the function call itself. When a function directly or indirectly calls its own method in its definition, it usually turns a large complex problem into a smaller one similar to the original one to solve, which can greatly reduce the code amount. The ability of recursion lies in defining an infinite set of objects with finite sentences.

2. Iteration: Calculate the new value of a variable by using its original value. If you call yourself recursively, iteration means that A always calls B.

3. There must be iterations in recursion, but there is not necessarily recursion in iterations, and most of them can be converted to each other. If you can iterate, you don't need to recursively call the function, which wastes space. If the recursion is too deep, it will easily lead to stack overflow.

The programming skill of program calling itself is called recursion. As an algorithm, recursion is widely used in programming languages. A procedure or function has a method that directly or indirectly calls itself in its definition or description. It usually turns a big and complicated problem into a smaller one similar to the original one to solve. Recursive strategy can describe the repeated calculation in the process of solving problems with few programs, which greatly reduces the code amount of programs. The ability of recursion lies in defining an infinite set of objects with finite statements. Generally speaking, recursion requires boundary conditions, recursive forward segments and recursive return segments. When the boundary conditions are not met, recursively advance; When the boundary condition is satisfied, it returns recursively.

Recursive algorithm is inefficient compared with common algorithms such as ordinary loop. So try to avoid recursion unless there is no better algorithm or recursion is more suitable in certain circumstances. In the process of recursive call, the system opens a stack for the return points and local quantities of each layer to store. Too much recursion can easily lead to stack overflow.