This content has been marked as final. Show 2 replies
Everytime you make a method call it gets placed on a stack. Make too many method calls and you run out of memory and get a stack overflow. When this occurs in conjunction with recursion it means that your case for exiting the recursion is wrong and is never reached.
N.B.: please use code tags, or the CODE button, when posting code. And please always use and review the preview pane before posting at all.
Flounder nailed it.
In particular, I would specifically focus on this part:
These recursive calls seem not to be included in a conditional branch, so I don't see what would stop the recursion (I could be more affirmative if you had properly formatted the code extract).
X1=mult(aL,bL); X2=mult(aR,bR); ... X3=mult(t1,t2);
We don't know your method SubArray(...) (by convention it should be subArray(...) instead), but please note that:
aL=SubArray(a,0,f/2); aR=SubArray(a,f/2,f); bL=SubArray(b,0,f/2); bR=SubArray(b,f/2,f);
1) the middle index at f/2 is specified in both left and right parts. This may or may not be what you expect, depending on how subArray handles the upper index (inclusive or not).
2) if the initial array length is odd, the integer division f/2 rounds down, this may or may not be what you expect
Edited by: jduprez on Jan 27, 2010 9:59 AM