Re: Untangling Multi-function Recursion



On Sat, 29 Dec 2007 07:36:56 -0800 (PST), Anant Narayanan
<anant@xxxxxx> wrote:

Hi,

I have a function (let's call it f) that calls 4 other functions (say
f1, f2, f3 and f4) depending on the parameters passed to it. f1, f2,
f3 and f4, call f in turn with a different set of parameters that what
it received and returns that as a value. This goes on until a
terminating condition reaches and f returns a value.

The problem with the code is that it fills up the stack space to
quickly. A typical execution sequence goes on like:
f -> f2 -> f -> f4 -> f -> f1 ..... 100 times ... -> f -> f3 -> f ->
final value

Is there a way in which I can "untangle" this recursion and not
encounter a stack overflow?

Any help would be greatly appreciated.

An obvious way to do this that works in most languages is for f1
et al to return the parameters instead of calling f.



.



Relevant Pages

  • Re: Untangling Multi-function Recursion
    ... The problem with the code is that it fills up the stack space to ... Is there a way in which I can "untangle" this recursion and not ... encounter a stack overflow? ...
    (comp.programming)
  • Untangling Multi-function Recursion
    ... The problem with the code is that it fills up the stack space to ... Is there a way in which I can "untangle" this recursion and not ... encounter a stack overflow? ...
    (comp.programming)
  • Re: Quicksort
    ... version, unless, of course you can afford order N stack space. ... trivially easy to do it yourself, ... partition, you will use no more than logstack space. ... If the compiler does tail recursion elimination, ...
    (comp.programming)
  • Re: The benefits of recursive programming
    ... programming instead of looping, even in lower-level languages like C, is beneficial for writing maintainable, verifiable code. ... Your example of using recursion to compute ... The recursive version of the report-printing procedure actually runs in constant stack space when compiled on GCC 3.4. ...
    (comp.programming)
  • Re: Increase .NET stack space?
    ... Dacon Software Consulting ... > Is there any way to increase the .NET stack space? ... I am going to suggest that he rewrite his recursion ... > there were any way to increase the .NET stack size... ...
    (microsoft.public.dotnet.framework)