Recursion, recursion, meaning of iterations

Source: Internet
Author: User
Tags repetition
recursion, recursion, meaning of iterations

Recursion: A program calls its own programming skill called recursion. Recursion as an algorithm is widely used in programming languages. A procedure or function in its definition

Or a method of calling itself directly or indirectly, it usually transforms a large, complex problem layer into a smaller, similar size to the original problem.

Problem to solve, recursive strategy can be described in a small number of programs to solve the process of repeated computations required, greatly reducing the code volume of the program.


Recursion: Recursive method is a method that describes complex problems with several steps of repeatable simple operations (rules). Recursion is a common calculation in sequential computers.

Method. It calculates each item in a sequence according to a certain rule, usually by some item in front of the computer to derive the value of the specified image in the sequence.


Iteration: An iteration is an activity of the repetitive feedback process, usually intended to approximate the desired goal or result. Each repetition of a procedure is called an "iteration",

The result of each iteration is the initial value of the next iteration.


The meaning of these three words is very similar, and I have been looking for a lot of explanations about these three, but it still doesn't allow me to distinguish them directly (especially

Recursion and iteration). Here I use my own understanding to distinguish them.


the difference between recursion and recursion

The recursive whole is divided into two steps: 1. Push down until the condition is restricted.

2. Backtracking results.

And recursion is starting from the initial state, constantly changing their own process.

such as: I want to let 1+2+4+ ... +64;

Recursion is passed forward by the final state, namely:

<span style= "FONT-SIZE:14PX;"    > #include <stdio.h>
int solve (int n)
{
if (n = 1) return
1;
Return N+solve (N/2);
}

int main ()
{
printf ("%d\n", solve);
return 0;
}

</span>

And if you only use recursion, you are:

<span style= "FONT-SIZE:14PX;" > #include <stdio.h>
int solve (int n)
{
    int i = 1;
    while (i <=)
    {
        n = i;
        i = i*2;
    }
    return n;
}

int main ()
{
    printf ("%d\n", Solve (0));
    return 0;
}
</span>

Recursion is the process of constantly invoking itself, finding the initial state from the final state, and then constantly backtracking.

Recursion does not backtrack on this process.


iterations and recursion are very close (even I think they are a meaning)

In foreign books iterative will be translated into iterations, that is, repeated (recursion is the process of repetition).

In English, recursion and recursion are put together. Recursion also has the argument of forward recursion and reverse recursion (recursion).


So, I think when it comes to recursion, the opposite is the same process of recursion and iteration, and in the difference between recursion and iteration, recursion can be seen as a positive

Recursion and reverse recursion.


Above pure personal opinion, if has the mistake, please pointed out in the comment area, I must reply promptly.



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.