Skip to content
uencoder

Combination

A combination counts the ways to choose k elements from n without regard to order, C(n,k)=n!/(k!(n-k)!), i.e., the binomial coefficient.

Purpose

To count unordered selections, a foundation of combinatorics and probability.

Mechanism

C(n,k) = n!/(k!(n-k)!) = C(n,n-k). Recurrence: C(n,k)=C(n-1,k-1)+C(n-1,k) (Pascal's triangle). For large numbers use logarithms or the recurrence to avoid overflow. C(n,0)=1, C(n,n)=1.

Use cases

  • Probability computation (binomial distribution)
  • Combinatorial enumeration
  • Binomial expansion coefficients
  • Hypergeometric distribution

Examples

  • Input
    C(5,2)=5!/(2!3!)=10
    Output
    10

    Choosing 2 of 5, unordered

Common errors

Computing factorials directly overflows
Use the recurrence or logarithms

Related terms

Related tools

References