Remix.run Logo
aleph_minus_one an hour ago

> It depends on whether the limited call stack capacity will be an issue for the particular problem you’re solving.

First: that common programming languages use the limited call stack for implementing recursion is an artifact of the programming language (implementation). One can, for example, use a stack data structure for implementing DFS instead of using the call stack; it would be no problem for a programming language implementation to use a similar method for implementing recursion.

This said: there actually exist two kinds of recursion (barely every computer science textbooks at most barely mentions this):

1. "normal" recursion (with all its problems such as potential stack overflow etc.)

2. tail recursion with guaranteed tail-call elimination (TCE) in the programming language semantics; then recursion basically behaves "like loops".

I want to clarify that it is a common exercise to convert a program that uses "normal" recursion to one that uses tail-recursion, just like it is a common exercise to convert such a program to one that uses imperative style.