A
athar.mirchi
..plz define it.
[email protected] said:.plz define it.
.plz define it.
RTFM !
Google is not dead !
On Jan 5, 2:17 pm, "(e-mail address removed)" <[email protected]>
Each call generates a new local stack which eventually all need to be
unwound.
So in C++, its usually replaced with better alternatives.
And neither is a little respect.
Some come here hoping others do their homework,
others prefer to ask rather than remain clueless.
Some of those know very little English.
So please: if you feel the need to reply with a patronising remark,
consider ignoring them, redirecting them to Wikipedia/Google or offer
them a link to the FAQ.
Salt_Peter said:As the English word suggests: a recursion is simply a function that
calls itself.
Which is neither efficient nor beneficial.
Tomás Ó hÉilidhe said:It's great though for template metaprogramming. For instance:
template<long unsigned x>
struct Factorial {
static long unsigned const val = x * Factorial<x-1>::val;
};
template<>
struct Factorial<1> {
static long unsigned const val = val;
};
template<>
struct Factorial<0> {
static long unsigned const val = 1;
}
As the English word suggests: a recursion is simply a function that
calls itself.
Which is neither efficient nor beneficial.
Jim said:recursion [ri-kur'zhen] - (n) see recursion
RECURSION: see RECURSION.
RECURSION: see RECURSION.
[email protected] said:.plz define it.
Error stack overflow at 1.
Recursion: if (understood) return; else see Recursion.
On Jan 5, 2:17 pm, "(e-mail address removed)"
As the English word suggests: a recursion is simply a function
that calls itself. Which is neither efficient nor beneficial.
Each call generates a new local stack which eventually all
need to be unwound. So in C++, its usually replaced with
better alternatives. An example of a preferred alternative
would then be a function object (functor).
Recursive functions have no state (what does that mean?).
To give you an example of recursion: (that incidentally
doesn't do what you'ld expect)
#include <iostream>
void recursion(int n)
{
std::cout << "n = ";
std::cout << n << std::endl;
if(n < 10)
recursion(++n);
}
int main()
{
recursion(0); // prints 11 times
}
It's beneficial when its beneficial. On most modern
architectures, it's often as efficient as the alternatives. (I
once benchmarked a recursive version of quick sort, and one
which avoided recursion. the recursive version was faster.)
How is that relevant to recursion. A functional object is still
a function, and can still be recursive or not, according to how
you write it.
I don't know? I have no idea what you're trying to say there.
And your point is?
Any iterative algorithm can be rewritten to use recursion. Some
languages don't even have looping constructions, but in C++,
using recursion to simluate iteration is poor programming
practice. On the other hand, recursion is considerably more
powerful than iteration, and not all recursive algorithms can be
rewritten in terms of pure iteration, unless you introduce a
manually managed stack, which is a lot more work for the
programmer, and typically less efficient in terms of run-time.
How would you do a depth first visit of a tree without
recursion, for example? (Or quick sort, for that matter? The
standard non-recursive iteration requires a user managed stack.)
Note that recursion is typically less efficient in terms of
memory than managing the stack yourself, so you'll normally want
to avoid recursing too deeply.
--
James Kanze (GABI Software) email:[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
I need some memory related information about recursion.
That is how it is implemented
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.