LYCOS RETRIEVER
Recursion
built 657 days ago
Recursion is a programming technique that allows the programmer to express operations in terms of themselves. In C++, this takes the form of a function that calls itself. A useful way to think of recursive functions is to imagine them as a process being performed where one of the instructions is to "repeat the process". This makes it sound very similar to a loop because it repeats the same code, and in some ways it is similar to looping. On the other hand, recursion makes it easier to express ideas in which the result of the recursive call is necessary to complete the task. Of course, it must be possible for the "process" to sometimes be completed without the recursive call. One simple example is the idea of building a wall that is ten feet high; if I want to build a ten foot high wall, then I will first build a 9 foot high wall, and then add an extra foot of bricks.
Source:
Recursion, in mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own definition. The term is ... used more generally to describe a process of repeating objects in a self-similar way. For instance, when the surfaces of two mirrors are almost parallel with each other the nested images that occur are a form of recursion.
Source:
Recursion has a very important rule in AI. It makes things much easier using recursion while the tedious loops. Prolog a very popular AI programming language is basically based on Recursion programming. Also most of data structures eg Decision Trees, Graphs etc which are used in AI for extensively are represented easily with recursion.
Source:
Recursion is used to define nearly all functions to do with lists and numbers. The next time you need a list-based algorithm, start with a case for the empty list and a case for the non-empty list and see if your algorithm is recursive.
Source:
Recursion makes debugging programs with interactive debuggers more difficult. The reason is that the relevant state is spread out over multiple stack frames. A single conceptual variable, say n, is often replicated as a parameter in each recursive call. The nonrecursive alternatives to be discussed tend to encapsulate the relevant state in a single object that can be inspected more easily.
Source:
Recursion might not be the most efficient way to implement an algorithm. Each time a function is called, there is a certain amount of "overhead" that takes up memory and system resources. When a function is called from another function, all the information about the first function must be stored so that the computer can return to it after executing the new function.
Source: