+ 1

Recursion

What disadvantages are in using recursion?

6th Feb 2020, 8:29 AM
Igor Olkhin
Igor Olkhin - avatar
11 Answers
+ 3
There is solution for problems with stack memory in Python. From functools import lru-cache and from sys import setrecursionlimit.
6th Feb 2020, 8:43 AM
Igor Olkhin
Igor Olkhin - avatar
+ 3
If you mess up the base case, you get infinite recursion and a stack overflow.
6th Feb 2020, 10:20 AM
Sonic
Sonic - avatar
+ 2
What about it's understanding, you're right)
6th Feb 2020, 8:45 AM
Igor Olkhin
Igor Olkhin - avatar
+ 2
Thank you for answer) Recursion is the one thing that was making me problems during my learning.
6th Feb 2020, 8:59 AM
Igor Olkhin
Igor Olkhin - avatar
+ 1
Reduce wastage of time for writing the code
6th Feb 2020, 7:55 PM
Mohammad Shafi
Mohammad Shafi - avatar
+ 1
From my experience as ~ swim ~ said it can be difficult to understand especially if not written properly also the maximum recursion depth (1000 in python by default) is reached very quickly. But there are problems that have a recursive nature embedded in their cores that they can only be solved using recursion or otherwise are very very difficult to impliment using loops. For exemple solving a Hanoi tower in recursion is suprisingly easy compared to loops (and i don't even know if it can be done that way). So, i recommend using loops if possible and use recursion when the solution necessits it.
8th Feb 2020, 8:43 AM
MedG
MedG - avatar
+ 1
I tried to find the solution of Tower by using loops, and also didn't find it. Usually I use recursion if there's really necessary.
8th Feb 2020, 1:24 PM
Igor Olkhin
Igor Olkhin - avatar
+ 1
The major disadvantage is complexity of program..and the stack size
27th Apr 2020, 9:21 AM
Sachin Waghmare
Sachin Waghmare - avatar
0
Don't forget about the base case - is just very important rule, not disadvantage, I think.. It's like a situation in infinite loops.
6th Feb 2020, 8:52 PM
Igor Olkhin
Igor Olkhin - avatar