The core idea of recursive algorithm

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.