Algorithms

Recursion

When a function solves a problem by calling itself with a smaller version of the same problem, until it reaches a case it knows how to solve.

Example

The sum from 1 to 4 is 4 + the sum from 1 to 3, which is 3 + the sum from 1 to 2... down to the sum from 1 to 1, which is 1. Result: 10.

Test yourself: Recursion

Iteration and recursion

How does recursion approach a problem?

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.