3 ms·
> Apparently recursion takes up more memory space than nested for loops Recursion uses space on the call stack. The concern is not so much that you'll be using
by mikebenfield 4y ago
> Apparently recursion takes up more memory space than nested for loops
Recursion uses space on the call stack. The concern is not so much that you'll be using more memory, it's that the call stack has a fixed size and you might blow past that size, which will cause your program to terminate.
The comparison between recursion and "nested for loops" seems a bit off - generally it's recursion vs a single loop.
Whether it's best to avoid recursion depends on many factors. In any case, even when I do want to use iteration, it's often easiest to first formulate the algorithm as a recursive one, and then change it to use iteration.