Iteration to recursion?

Here's one way you could do it. Basically you start in the 0,0 corner and set it to the value. Then you do 0,1 and 1,0.0,1 will set, and do 1,1 and 1,2.1,0 will set and do 2,0 and 1,1.

Note that 1,1 just got hit twice - that's fine because it's overwriting what it did before. When it hits a 'wall' it stops (this means if the 3 array was null, 4 wouldn't get hit) but that isn't a problem for arrays allocated with new intxy notation class Sandbox { public static void main(String args) { int test = new int55; recursiveAssign(test,10); int numThatAreTen = 0; for(int I = 0; I javac Sandbox. Java C:\Documents and Settings\glowcoder\My Documents>java Sandbox 25 C:\Documents and Settings\glowcoder\My Documents.

Here's one way you could do it. Basically you start in the 0,0 corner and set it to the value. Then you do 0,1 and 1,0.0,1 will set, and do 1,1 and 1,2.1,0 will set and do 2,0 and 1,1.

Note that 1,1 just got hit twice - that's fine because it's overwriting what it did before. When it hits a 'wall' it stops (this means if the 3 array was null, 4 wouldn't get hit) but that isn't a problem for arrays allocated with new intxy notation. Class Sandbox { public static void main(String args) { int test = new int55; recursiveAssign(test,10); int numThatAreTen = 0; for(int I = 0; I javac Sandbox.

Java C:\Documents and Settings\glowcoder\My Documents>java Sandbox 25 C:\Documents and Settings\glowcoder\My Documents.

And turning a simple seven lines of iterative code into a recursive behemoth like that is exactly why you shouldn't do it :-) I rest my case, your Honour. – paxdiablo Sep 1 at 3:36.

Yes, you can. However, you shouldn't want to. I can write all my applications in assembly code but that doesn't make it a good idea :-) There are a few algorithms that lend themselves naturally to recursion, those whose operations can be expressed in terms of the same operation on a smaller data set or lesser value (tree traversal, factorials, that sort of thing).

Initialising an array to all zeros is not one of those things.

O – Alxandr Aug 31 at 23:46 2 .. but probably not the time. – filip-fku Aug 31 at 23:52 2 A loop does not incur the stack frame overhead of a recursive call. They are not the same thing.

– Perception Sep 1 at 0:16 1 @Alxandr it actually doesn't take all that much knowledge and skill to write applications in assembly. I mean you have to memorize all the op-codes, or at least have the ability to look them up, but I don't see this as any different than picking up any other new framework or language.It does take considerable amounts of patience and time, which most people do not have. – glowcoder Sep 1 at 15:59 1 @Nath Absolutely there are.

The key is this isn't really one of them. Now if you're looking exclusively for "I want to train my brain to recognize how to turn iterative processes to recursive ones" then it's not that bad. In fact, a very good exercise in understanding recursion might be to take what I wrote and optimize it to not overlap on spreading.

:) – glowcoder Sep 2 at 16:36.

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.

Related Questions