Recursion depth

Hi,
I am in the process of developing a c++ software and one of the requirements is to build a tree type data structure. I have been able to do this without problem. However there are some functions for which things are lot easier if i use recursion.

What is the legal depth in c++ ? If i have a very large data structure would my program crash or slow down ? I have not yet been able to test the recursive functions on large data structures. It works great for smaller problems though.

Should recursion in general be avoided for serious applications ?
The standard doesn't define any minimum depth for the stack. Exactly how deep you can recurse depends on the size of your stack, and how much data each stack frame holds. In my experience, you can recurse up to about 1000 levels without overflowing the stack, but take this as a very rough estimate.
Generally speaking, any application built for robustness should avoid recursive algorithms whenever possible, unless it's known in advance how deep it'll go.
Thanks helios,
It is certainly helpful to know that i could go that deep without crashing the code. I will try to rewrite those functions for future applications.
Last edited on
Topic archived. No new replies allowed.