py function recursion

Source: Internet
Author: User

1. There used to be a mountain, a temple in the mountains, an old monk in the temple telling a story ...

2. Recursion: The program calls itself.

3. Form: The function definition has a direct or indirect call to itself.

For example: factorial: n!= 1 x 2 x 3 x ... x n;

Consider P (n) = n * (n-1) from backs ago!, p (n-1) = (n-1) * (n-2)!

4. Initial conditions, recursive parts. Qiatouquwei stay in the middle

5. The If problem is simple enough:

Direct Problem Solving

Return solution

Else

One or more smaller issues that are isomorphic to the original problem

Solve these smaller problems one by one

Combine the results to get the final Solution

Return solution

6. Fibonacci Series: 1, 1, 2, 3

py function recursion

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.