Usage scenarios for recursive functions

Source: Internet
Author: User

1. Complete recursion with recursion
Method:
1) The result of placing the focus on the target of the desired solution, i.e. i=n
2) to find the relationship between the nth time and the first n-1;
3) Determine the return result for the 1th time
Example of a cut cake

where n is the number of knives to be cut, Q (n) is the number of pieces of pie
Code implementation

int get_cake_number (int  cutnum) {    if0)    {          return1;    }     Else     {        return1));}    }

2, recursive simulation of the continuous occurrence of the action
Method:
1) Figure out what the continuous action is.
2) Figuring out the relationship between the different actions
3) Figuring out what the boundary conditions are

Example: binary number of an output integer
Code implementation

void CONVERT (int  x) {    if20)    {        CONVERT (x /2);         << x2;    }     Else     {        2;    }}

Usage scenarios for recursive functions

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.