recursion

#cs/algorithms#cs

Recursion

Recursion is when a function calls itself.

def factorial(n: int) -> int:
    return 1 if n <= 1 else n * factorial(n - 1)

Base case always required! See Dynamic Programming · Algorithms Overview · CS Concepts Hub.

View in graph