On 10/20/2005 at 3:34 PM Sridhar Ayengar wrote:
Recursion makes a lot of sorting/searching algorithms
much cleaner too.
Plus, IMHO the recursive factorial (x!) algorithm looks a lot less
complicated.
Not to offend the purists, but...
From an efficiency standpoint, recursion is seldom the
best solution in the
real world as opposed to an iterative solution. With
recursion, you're
using the CALL mechanism to provide a new data frame and arguments for each
iteration. With a simple loop, an indexed array can provide the same
functionality at much lower overhead--and be more predictable as to the
amount of storage required.
Perhaps there are architectures where this is not true, but in my
production codes, I've found it more efficient to climb directory trees
with a simple loop--with an index limit check, rather than, say, throwing
an exception for stack overflow in the case of recursion.
Argumentatively,
Chuck