Skills101
← Tech dictionary

Data structures & algorithms

What is Recursion?

Recursion is when a function solves a problem by calling itself on a smaller version of the same problem, until it reaches a base case that is answered directly. Every recursive function needs a base case, or it never stops.

Example

factorial(n) = n × factorial(n − 1), with factorial(0) = 1 as the base case.

Learn it properlyDSA tutorials — free, with diagrams, quizzes and a certificate

Related terms