Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

sys.setrecursionlimit(n) ?

0 votes
asked Mar 1 by jfmaheux (150 points)
I am trying to compute gcd of relatively large integer with recursive functions, and I quickly get:

RecursionError: maximum recursion depth exceeded in comparison

is it possible to set the recursion limit to a larger value?

1 Answer

0 votes
answered Mar 7 by Peter Minarik (88,520 points)

This would typically be the error if your recursion is not set up correctly and there is no way for it to terminate. The runtime detects that there doesn't seem to be any end to this and shuts down the application.

So, I'd investigate the recursion and see if it's correctly set up.

If it is indeed correctly set up and somehow you've got a valid case with too deep recursion for the system to handle, there's still a way. Every recursion could be translated into a loop. So you'd just need to rephrase your code to be a loop instead of a recursion. Loops also run faster than recursions.

You can read more on the subject here.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.