Recursion: Python
Recursion gives you a new perspective on problem-solving by defining a problem in terms of itself.
StartKey Concepts
Review core concepts you need to learn to master this subject
Stack Overflow Error in Recursive Function
Fibonacci Sequence
Call Stack Construction in While Loop
Binary Search Tree
Recursion and Nested Lists
Fibonacci Recursion
Modeling Recursion as Call Stack
Recursion in Python
Stack Overflow Error in Recursive Function
Stack Overflow Error in Recursive Function
def myfunction(n):
if n == 0:
return n
else:
return myfunction(n-1)
myfunction(1000) #results in stack overflow error
A recursive function that is called with an input that requires too many iterations will cause the call stack to get too large, resulting in a stack overflow error. In these cases, it is more appropriate to use an iterative solution. A recursive solution is only suited for a problem that does not exceed a certain number of recursive calls.
For example, myfunction()
below throws a stack overflow error when an input of 1000 is used.
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory