COSC 2306 - Recursive Function Call Stack Visualizer
Keep small (0-6) for visualization.
A recursive function is a function that calls itself to solve a smaller instance of the same problem. It consists of two main parts:
n == 0 returning 1). This prevents infinite loops.n * fact(n - 1)).Notice how the function "winds" up the stack calling itself until the base case is hit, then "unwinds" returning and multiplying the results back down!
def fact(n):
if (n == 0):
return 1
else:
return n * fact(n - 1)