

A procedure is a set of steps based on a set of rules, while the running of a procedure involves actually following the rules and performing the steps. To understand recursion, one must recognize the distinction between a procedure and the running of a procedure. A procedure that goes through recursion is said to be 'recursive'. Recursion is the process a procedure goes through when one of the steps of the procedure involves invoking the procedure itself. Recently refreshed sourdough, bubbling through fermentation: the recipe calls for some sourdough left over from the last time the same recipe was made. There are various more tongue-in-cheek definitions of recursion see recursive humor. Other recursively defined mathematical objects include factorials, functions (e.g., recurrence relations), sets (e.g., Cantor ternary set), and fractals. 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. Many mathematical axioms are based upon recursive rules.

The Fibonacci sequence is another classic example of recursion:įib(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). One's parent's ancestor ( recursive step).A recursive step - a set of rules that reduces all successive cases toward the base case.įor example, the following is a recursive definition of a person's ancestor.

