Recursion is an immensely powerful tool for a programmer. Like many abstractions, it allows us see past the weeds of a problem and strive for a more elegant understanding of the underlying logic. Unfortunately, simplifying something for a human frequently comes at the expense of the computer. In the case of recursion, your beautiful, recursive solution demands an extraordinary amount of memory.

The source of recursion’s memory woes is simple: each recursive call requires its own space in memory to maintain its own runtime environment. That environment holds crucial data, including local variables, the script itself, and, most importantly, the…

Avery Schiff

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store