3 ms·
I think it is agreed that recursion is the best approach in many cases. Many problems have a simple recursive solution, but become very complicated if solved by
by CrLf 15y ago
I think it is agreed that recursion is the best approach in many cases. Many problems have a simple recursive solution, but become very complicated if solved by iteration.
But I'm under the impression that this is seldom (if ever) the case with recursive solutions that can benefit from tail call elimination... In this case, an iterative solution is just as simple (or complicated). It is a matter of taste.
When this is not the case, you can't perform this optimization anyway. Am I wrong here?