From: Robert Klemme Date: 2006-02-28T17:53:43+09:00 Subject: Re: Stack level too deep marcus wrote: > I have a tree that I do recursion over the nodes (and then some > recursion inside the nodes...). Two problems: > > 1) Stack level too deep (error message) > 2) Speed get really really lousy when the tree is deep. With a small > shallow tree the speed is nice. I get that the overall time get long > but the handling of each node is slow in a deep tree. > > Any way around these issues? I should say that it's running in a Rails > environment on Win, Ruby 1.8.2 The easiest change is to use BFS instead of DFS - if that's possible in your scenario. Alternatives: - implement a DFS with your own kind of stack - change the way you store things to avoid such a deep recursion Also, I guess you made sure that there is no loop, i.e. the structure is actually a tree... Kind regards robert