Re:How recursion got into programming: a comedy of errors
by to3m on Wednesday July 23, 2014 @04:37PM
(#8076821)
You're usually better off with manual recursion, if you're concerned about running out of space, for the simple reason that it's far easier in practice to back out of an out-of-memory situation than from a stack overflow.
Re:How recursion got into programming: a comedy of errors
by Retric on Wednesday July 23, 2014 @01:03PM
(#8075470)
Optimal loops don't use more memory than recursion and generally significantly less. Though if you can find an counter example in a common programming language I would love to see it.
However, we are talking about the automotive and aerospace industry so recursion overhead is often a deal breaker even if there are no other issues.
If the algorithm is tail-recursive, this will use constant stack space and memory, just like tail-call optimisation. If the algorithm's not tail-recursive, it will use constant stack space but large (potentially exponential) amounts of memory.
There's no way around this. The only solution is to come up with a different algorithm (eg. using an accumulator).