3 ms·
Sometimes. Very rarely. The main issue with recursion is not even speed, it's the fact the stack is not too large. As far as I remember, by default 2MB on Wind
by Const-me 4y ago
Sometimes. Very rarely.
The main issue with recursion is not even speed, it's the fact the stack is not too large. As far as I remember, by default 2MB on Windows. You can easily keep 2GB of data in std::vector or an equivalent. And if by mistake you try to put 20TB there, most languages have decent ways to handle out of memory errors.
Still, there're rare cases when recursion is good. These are the cases when performance doesn't matter, you know for sure the depth will never exceed ~200k, but recursion helps a lot with code size and readability.