Try this video lecture on recursion from Stanford. academicearth.org/lectures/thinking-recu... It should give you a basic understanding of recursion.
I am assuming, you are asking about how basic recursion works and my answer here addresses that issue. – okkhoy Jan 7 at 15:12 Thank you so much for the video. Will take a look at it – user807496 Jan 7 at 17:44.
There is a special case where recursion can be "unrolled" to a while loop, this is when the last thing a function does is to call itself. Static int count(int n) { if (n==0) return 0; return count(i-1); } could be written as: static count(int i) { while (true) { if (n==0) return 0; I = i-1; } } The recipe is simple: Enclose the method body in a while loop, replace recursive calls by computing the arguments values. But note that this is a very special case, and not generally applicable.
You'll also want to educate yourself, as recursion is more or less unavoidable depending on the data structures you work with. Think trees, for example. Or suppose you parse an expression like ( e ) where e is another expression.
While it is possible to turn every recursive program to a non-recursive one it is most often not desirable, because the recursivity is the natural way to do things.
1 I don't think this answers the question. What you describe here is called tail call optimization and not "unrolling", whatever that might be. The problem is that OP said "when more than 1 recursive statement is involved" and in that case, it cannot be a tail call recursion.
– Niklas Baumstark Jan 7 at 15:02 This is almost correct, @Niclas. It is tail recursion elimination. But it's the best that can be said, no: that I can say to the question.
– Ingo Jan 7 at 15:06 I don't think that would be correct. From the top of my head, I can see two methods of "unrolling" that could be applied to a function with more than one recursive call. First, using an explicit stack data structure to transform the recursion into an iteration.
This is what I found when Googling for "recursion unrolling". Second, and this is more analogous to the method of "loop unrolling", inlining the recursive calls up to a certain depth to decrease the function call overhead to some degree. Also, the term "tail call optimization" and "tail call elimination" are synonyms.
– Niklas Baumstark Jan 7 at 15:10 @Niclas: this is just the specificum of tail recursion elimination that it does not need a stack, while for anything else you'd need one. (not counting inlining, though) – Ingo Jan 7 at 15:13 Still, if you Google for recursion unrolling, you find explanations like these. EDIT: I am now pretty sure that OP simply wants an explanation of how recursion works.
– Niklas Baumstark Jan 7 at 15:14.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.