Have seen such a question, asked, "program structured design of three kinds of infrastructure, order, selection, cycle is not necessary?" "Of course, you know such an assertion, as long as there are three of them, but can it be less?" The answer is "yes" because recursion replaces the function of a loop, such as the following function that sums the elements in an array:
float rsum (float a[], const int n)
{
if (n <= 0) return 0;
else return rsum(a, n – 1) + a[n – 1];
}
is actually:
sum = 0;
for (int i = 0; i < n; i++) sum + = A[i];
But the reality is that any language has a looping structure, but not all languages support recursion; In a sentence, recursion is omnipotent, but no recursion is not absolutely impossible. However, I see some people now, no matter what problems should be recursive, clearly cycle is the first thought of the method, but the brain to find a recursive algorithm. I really don't know what to say about it.
is recursion an algorithm?
Often see "recursive algorithm", "Non-recursive algorithm", this reference is not a semantic problem, and I also use--recursive algorithm. But it is also a statement that recursion is not an algorithm, he is a thought, precisely because the guiding ideology of an algorithm is recursive, it is called recursive algorithm, and a recursive algorithm, when you do not use recursion as the guiding ideology, so the algorithm is not recursive algorithm. In this sense, the cyclic algorithm can be called a non recursive algorithm for solving the problem of cyclic energy.
I have no other meaning in this word, just want to let you know, can write what kind of algorithm, the key is to see you write algorithms when the guiding ideology. If you think of loops and iterations from the beginning, you'll have to exhausting to find a recursive algorithm--even if you find an algorithm that looks "neat", because his inefficiency is actually a waste--what are you doing? A typical pedantic habit. If you think only of recursive methods, now you want to use the stack to eliminate recursion, the job you do is simply to do what the system does, and how much efficiency can you improve? Blind superstition to eliminate recursion can certainly improve efficiency is unfounded-you do not have the right way of doing the work, or even less than the original practice of the system.