When you execute a recursive function in Python on a large input ( > 10^4), you might encounter a “maximum recursion depth exceeded error”. This is a common error when executing algorithms such as DFS, factorial, etc. on large inputs. This is also common in competitive programming on multiple platforms when you are trying to run a recursive algorithm on various test cases.
例如:
解决方案:Using the setrecursionlimit() method, we can increase the recursion limit and the program can be executed without errors even on large inputs.
import sys
sys.setrecursionlimit(10**6)
网友评论