What is the basic idea of implementing recursive and non recursive conversions?

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

    The basic idea of recursion is: invoke oneself on oneself.

    Recursion is a common way to solve problems, which is to simplify problems gradually. The basic idea of recursion is to "invoke yourself", and a method that uses recursive techniques will invoke itself directly or indirectly.

    Recursion can be used to solve complex problems with simple programs. For example: the calculation of the Fibonacci sequence, the Tower of Hanoi, fast row, etc.

    Recursive calls will occupy a large amount of system stack, consume a lot of memory, and the speed of recursive calls is much slower than that of loops, so you should be cautious when using recursion.

    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.

    The recursive loop is buried slowly, and 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 ease of description, assuming that the elements are all positive and the length of the array is an integer multiple of 2.

  2. Anonymous users2024-02-10

    Hello, I will answer for you about any recursive process can be converted into a non-recursive process, I believe many friends still don't know, now let's take a look! 1. Recursive work stack. <>

    1. The recursive working stack includes the return address, the local variables of this layer, and the form parameters of the recursive call instead of the actual parameters, so under normal circumstances, regardless of whether the recursive process uses local variables or not.

    2. To convert to a non-recursive process, you need to use a stack to simulate this recursive invocation processOf course, there are some special recursions that can be directly converted without a stack, such as tail recursion, constant coefficient recursion, etc.

    3. Regardless of whether there are local variables or not.

  3. Anonymous users2024-02-09

    In fact, recursive functions are often used to solve some problems.

    What if one day you have to write iterations in order to pursue efficiency?

    Consider that recursion is really letting the system do the stack operations.

    So iteration, actually, is what we do what the system is meant to do.

    What we need: data that is being manipulatedpc**, which records where the current program is running to determine what to do next.

    But often, PCs don't need to be recorded.

    Why do you not need to use a PC for pre-order and mid-order traversal??

    And then the order is required. Looking at the recursive functions of the front, middle, and back order, I don't see any difference.

    The difference is that there are several operations after that.

    The pre-order and the middle order, pop() are all printed directly, and there is only one operation in the back.

    But in the later order, pop(), there are two cases.

  4. Anonymous users2024-02-08

    a.General and basic conditions are the key to writing recursive functions.

    b.When you are able to use recursive functions, try to use recursive friends, because it can make the program concise and easy to understand.

    c.There is no limit to the number of nested calls a recursive function can have.

    d.Recursive functions perform more efficiently than non-recursive functions.

    Correct Answer: The general condition and the underlying condition are the key to writing recursive functions.

  5. Anonymous users2024-02-07

    Regarding "recursion", the following statement is correct ().

    a."Recursive and regressive" is derived from the mathematical recursive and mathematical macro argumentative induction.

    b."Recursion", like recursive, starts from the recursive basic calculation, and calculates the latter term (n-term) from the previous term (n-1) until the final result is obtained.

    c."Recursion" is to substitute the latter term (i.e., the nth term) into the previous term (n-1 term) until the result is obtained on the basis of recursion, and then the result is obtained from the calculation of the latter term until the final result of the infiltration is obtained.

    d."Recursion" is a method of calculating the nth term from the first n-1 term.

    Correct answer: ACD

Related questions
6 answers2024-05-23

A function has arguments and a return value.

Look at a function: >>>More

6 answers2024-05-23

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

6 answers2024-05-23

An algorithm used in computer programming techniques.

Tail recursion is aimed at traditional recursive algorithms. >>>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

linklist reserve_fei(linklist l,int n)

What does n do. >>>More