Lably
Skip to content

Recursion

Process of repeating items in a self-similar way

  • 11 min read
  • 9 chapters
Very old product that is not produced and not sold any more. Note that some tins may look the same, but when looked for carefully there are some slight differences! Photographed at a collector of Dros
Alf van Beem · CC0

Learn it on Lably

A process that exhibits recursion is recursive. Video feedback displays recursive images, as does an infinity mirror.

Formal definitions

In mathematics and computer science, a class of objects or methods exhibits recursive behavior when it can be defined by two properties:

  • A simple base case (or cases) — a terminating scenario that does not use recursion to produce an answer
  • A recursive step — a set of rules that reduces all successive cases toward the base case.

For example, the following is a recursive definition of a person's ancestor. One's ancestor is either:

  • One's parent (base case), or
  • One's parent's ancestor (recursive step).

The Fibonacci sequence is another classic example of recursion:

Fib(0) = 0 as base case 1,
Fib(1) = 1 as base case 2,
For all integers n > 1, Fib(n) = Fib(n − 1) + Fib(n − 2).

Many mathematical axioms are based upon recursive rules. For example, the formal definition of the natural numbers by the Peano axioms can be described as: "Zero is a natural number, and each natural number has a successor, which is also a natural number." By this base case and recursive rule, one can generate the set of all natural numbers.

Other recursively defined mathematical objects include factorials, functions (e.g., recurrence relations), sets (e.g., Cantor ternary set), and fractals.

There are various more tongue-in-cheek definitions of recursion; see recursive humor.

Sign in to keep reading

8 more chapters are free with a Lably account.

More in Basics