🎉 October Learning Month — learn a new software term every day!
An interactive flashcard trainer for software engineering terms.

Recursion

In plain terms

When a function solves a problem by calling itself on a smaller piece of it.

Going deeper

A recursive function breaks a problem into a smaller version of the same problem until it hits a 'base case' that stops the calls. It's natural for things with self-similar structure like trees, file folders, or factorials, but each call uses memory, so deep recursion can overflow the stack.

Under the hood

Each call adds a stack frame, risking stack overflow on deep inputs; tail-call optimization (where supported) or converting to iteration with an explicit stack mitigates this.

Examples

Factorial, tree/graph traversal, quicksort, parsing nested JSON, Fibonacci.

Think of it like...

Like standing between two mirrors: each reflection contains a smaller version of the same scene, repeating until it's too tiny to see (the base case).

Feedback & Bug Report