Recursion means an item repeats in a self-similar way.
A mathematical function made with recursion, also called induction, involves defining some values with one or more base cases and defining the rest in terms of other values of the same function. For example, the factorial function x! is defined with the following rules:
- 0! = 1
- x! = x * (x - 1)!, that is, a number's factorial is the number times the previous number's factorial.
Recursion in computer science involves a method, function, or subroutine calling itself. For example, a "flood fill" or "paint bucket" tool fills matching pixels to the left and to the right and then applies the tool to the pixels above and below the pixels that were changed. Programs written in languages descended from Lisp make heavy use of recursion.