# factorial

(definition)

Definition: The factorial of an integer n ≥ 0, written n!, is n × n-1 × ... × 2 × 1. In particular, 0! = 1.

Generalization (I am a kind of ...)
gamma function.

Specialization (... is a kind of me.)
Stirling's approximation.

Aggregate parent (I am a part of or used in ...)
permutation, combination.

Note: For instance 5! = 120. Factorial is often used as a (poor) example of recursion, since n! = n × (n-1)! for n > 1, however a simple loop is usually faster and just as clear.

Why is 0! = 1? Using the gamma function definition, 0! = Γ(0+1) = ∫ 0 e-xx1-1dx = ∫ 0 e-xdx = 1.

Author: PEB

## Implementation

Peter Luschny's fast factorial algorithms (Java and C#) including benchmarks and advice. (Scheme).
Go to the Dictionary of Algorithms and Data Structures home page.

If you have suggestions, corrections, or comments, please get in touch with Paul E. Black.

Entry modified 28 July 2008.
HTML page formatted Tue Dec 6 16:16:32 2011.

Cite this as:
Paul E. Black, "factorial", in Dictionary of Algorithms and Data Structures [online], Paul E. Black, ed., U.S. National Institute of Standards and Technology. 28 July 2008. (accessed TODAY) Available from: http://www.nist.gov/dads/HTML/factorial.html