This question already has an answer here:

While reading Code Complete second edition, I came across this line:

You can do anything with stacks and iteration that you can do with recursion.

Is this true? or there are functions, that must be implemented recursively, and can't be done otherwise ?

marked as duplicate by D.W. Oct 23 '17 at 14:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

Your CPU uses stacks and iteration to run any program, including programs based on recursion.

If you are unsure how this works, I suggest picking up an appropriate textbook.

  • I'm talking at a higher level, for example, can the C language be used to implement any recursive function, in an iterative way? because recursive functions, though sometimes they look simple an elegant, they might eat a lot of memory stack, and might cause a stack overflow. – Bite Bytes Oct 23 '17 at 14:01
  • Recursive functions are implemented on actual hardware using a stack. You can't escape this. – Yuval Filmus Oct 23 '17 at 14:02
  • Also, actual computers can also run out of heap space. When we say that stacks and iteration can simulate recursion, we consider an idealized computer. – Yuval Filmus Oct 23 '17 at 14:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.