+ 1
Why are recursive functions considered slower than their iterative counterpart?
My question is from Recursion https://www.sololearn.com/discuss/1911868/?ref=app https://code.sololearn.com/cj0MOpnCtz7L/?ref=app
2 Answers
+ 2
In general recursive functions are slower, though the difference is not significant. This happens simply because a function call is more "expensive" than iterative function, which uses loop. However, the difference of how much space it takes is quite significant, since every calls need to create a new variables, if the function have any, or at least a new return address, also this is one of the reason why it is more "expensive"
+ 1
Recursive functions arnât always slower than iterative functions. I would recommend googling it, theres probaly a good comparison out there