Category:Recursion

From Rosetta Code
Revision as of 00:36, 28 January 2008 by rosettacode>Mwn3d (New page: '''Recursion''' is the idea that a function can come to an answer by repeatedly "calling itself" with new arguments until a "base case" is met. One good example is a factorial function. Th...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Recursion is the idea that a function can come to an answer by repeatedly "calling itself" with new arguments until a "base case" is met. One good example is a factorial function. The base case for factorial is "0!" (some people like to use 1 or 2, but for instructional purposes 0 is OK). When 5 is sent as an argument to a recursive factorial function, the function does no know the answer right away. All it knows is that 5! = 5 * 4!. so it calls itself to find out what 4! is. This process continues until it gets to 0!, which is 1. Now it has built up a train of answers: 5! = 5 * 4! = 5 * 4 * 3! etc. and it can find the answer.

Below is a list of examples of recursion in computing.