What is the scope of recursion? What is Recursion?

Updated on technology 2024-05-23
5 answers
  1. Anonymous users2024-02-11

    In short, recursion is a program that is directly or indirectly invoked into itself and falls within the scope of recursion.

  2. Anonymous users2024-02-10

    As long as it can be expressed in recursive form, there is a termination condition.

  3. Anonymous users2024-02-09

    Generally, it depends on the programmer's own literacy.

  4. Anonymous users2024-02-08

    Both recursion and iteration are types of loops.

    To put it simply, recursion is the repeated call of the function itself to implement the loop. The difference between iteration and ordinary loop is that the variable participating in the operation in the loop is also the variable that saves the result, and the current saved result is used as the initial value of the next loop calculation.

    In a recursive loop, when the termination condition is met, it returns layer by layer to end. The iteration uses a counter to end the loop. Of course, in many cases, it is a multi-cycle mixture, depending on the specific needs.

    An example of recursion, for example, given an array of integers, uses a halved query to return the index of the specified value in the array, assuming that the array is sorted, and for the sake of description, assuming that the elements are all positive and the length of the array is an integer multiple of 2.

    A half-split query is a type of query that is much faster than iterating through all the elements.

    int find(int *ary,int index,int len,int value)

    if(len==1) last element.

    if (ary[index]==value)return index;A successful query returns an index.

    return -1;Failed, returns -1

    If the length is greater than 1, perform a half-fold recursive query.

    int half=len/2;

    Check whether the checked value is greater than the last value in the upper half, and if so, recursively query the second half.

    if(value>ary[index+half-1])

    return find(ary,index+half,half,value);

    Otherwise, recursively query the top half.

    return find(ary,index,half,value);

    The classic example of iteration is the accumulation of real numbers, such as the sum of all real numbers from 1 to 100.

    int v=1;

    for(i=2;i<=100;i++)

    v=v+i;

  5. Anonymous users2024-02-07

    <>1. The programming technique of a program calling itself is called recursion.

    2. Recursion is widely used as an algorithm in programming languages.

    3. A process or function has a method that directly or indirectly calls itself in its definition or description, which usually transforms a large and complex problem into a smaller-scale problem similar to the original problem to solve, and the recursive strategy only needs a small number of programs to describe the multiple repeated calculations required in the solution process, which greatly reduces the amount of programs. The ability of recursion lies in defining an infinite set of objects with finite shrouded statements. In general, recursion requires boundary conditions, recursive forward segments, and recursive return segments.

    When the boundary is not satisfied, recursively advance; When the boundary conditions are satisfied, recursively returns.

Related questions
6 answers2024-05-23

Recursion, that is, calling oneself in the process of running. The conditions that constitute recursion:1 >>>More

7 answers2024-05-23

Many beginners tend to be confused about recursion and spend a lot of time on it. In fact, the example in the textbook is very classic, but it says a little nagging. Beginners will look at the big head. >>>More

6 answers2024-05-23

An algorithm used in computer programming techniques.

Tail recursion is aimed at traditional recursive algorithms. >>>More

6 answers2024-05-23

A function has arguments and a return value.

Look at a function: >>>More

9 answers2024-05-23

Article 130 of the Regulations for the Safety and Technical Supervision of Pressure Pipelines - Industrial Pipelines stipulates that the following venting or exhaust pipelines should be equipped with venting flame arresters: >>>More