This week's book giveaway is in the Other Languages forum.We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# recursive method

Kalabaw moo
Ranch Hand
Posts: 61
Hi here I am again, I know how recursive method works but the problem I'm facing now is analyzing this recursive method. I'm just testing the method.

The output I have is

I'm trying to analyze how did I get that output, but it seems that I'm totally lost I can only analyze the output if I only have one method calling itself once but method calling itself twice-can't discover the process. Any help would be appreciated

Himanshu Kansal
Ranch Hand
Posts: 257
Hello,

It hardly makes a difference even if a method calls itself n times.

Just imagine there is only 1 call. Resolve the complete stack flow of the that 1 call and get the result. Now for the second method, just add a call to each stack entry. Write it down and you ll get it, if not... please tell, I'll represent diagramatically.

Regards

Marcos R Oliveira
Ranch Hand
Posts: 62
1
Hi, Kalabaw.

I think you can have a better understanding of this code by drawing the stack that is formed by the calls to the checkGrid method. In each item in the stack, write the arrayLength passed to the method. Put some sysouts in the code to help you in this simulation.

Best regards,
Marcos.

Kalabaw moo
Ranch Hand
Posts: 61
I minimized the problem.

Here's the calling I created. I don't know if this is correct or not, if it's correct then the problem I have is understanding the things that the function will return to be able to see the output. I guess I'm kinda near to the light of understanding the recursion-1 function calling itself twice.

Frank Kellinghusen
Greenhorn
Posts: 11
Kalabaw,

I played with your code, so the print statements give a more visual expression. Change the level variable to make deeper recursions.

Which produces following output: