OK, you're getting let's say, to the last element in the array. Way
deep.
you test it with if (a.length == 1) and yep, we're at the last element,
so you set the change to "true".
Now it's time to EXIT the program. If I understand your code, it's ONLY
designed to recurse DOWN, so
if you go back UP one level, it will just turn around and recurse back
DOWN, again.
Eventually making a stack error.
All stacks have their limits, so the recursive calls have a max
(usually greater than 600 depths, sometimes much more), but
they always have their limits. I would think it's important to only
allow for a certain size of array, or have some error checking to
"catch" and recover from, the inevitable stack error.
int recurse(low, high) {
int mid,
while (low < high) {
mid = (low + high) / 2;
recurse(mid, high);
//or to explore the bottom half,
recurse(low, mid);
}
If you just want to recurse through an array (and don't need to
actually work with each part of the array), perhaps a binary search
model would be much more on target. Something like the above, with no
test of a "match" like binary search uses, and no need for the other
half of the array. That part is just knocked off the data pool.
I'll let you work with that, but let me know if you want C code that
does part or all of it.
Adak
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---