NIST

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.
Go to the Dictionary of Algorithms and Data Structures home page.

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

Entry modified 2 March 2015.
HTML page formatted Wed Mar 13 12:42:45 2019.

Cite this as:
Paul E. Black, "factorial", in Dictionary of Algorithms and Data Structures [online], Paul E. Black, ed. 2 March 2015. (accessed TODAY) Available from: https://www.nist.gov/dads/HTML/factorial.html