I believe that all the problems that have iterative logic can be solved using iterations, but can we solve any problem using recursion? Can recursion always substitute iteration? Please provide a proof to your answer if you can. Also assume that we have an infinite stack or we run the program on a Turing machine. I don’t care if this proof is a theoretical proof. (that’s why I mentioned the Turing Machine)
Share
Yes, recursion can always substitute iteration, this has been discussed before. Quoting from the linked post:
Explaining a bit: we know that any computable problem can be solved by a Turing machine. And it’s possible to construct a programming language
Awithout recursion, that is equivalent to a Turing machine. Similarly, it’s possible to build a programming languageBwithout iteration, equal in computational power to a Turing machine.Therefore, if both
AandBare Turing-complete we can conclude that for any iterative program there must exist an equivalent recursive program, and vice versa. This is a theoretical result, in the sense that it doesn’t give you any hints on how to derive one recursive program from an arbitrary iterative program, or vice versa.