Is there an efficient way to numerically compute Stirling numbers of the second kind?

An approximate (not exact) method would suffice. Something similar to the connection between factorials and gamma functions would work for me.

I googled it a bit and didn't find anything too helpful.


2 Answers 2


You can use the following recurrence relation


see DLMF equation 26.8.E22

and build the (triangular) table.

  • $\begingroup$ Is there some relationships between Stirling numbers of the second kind and some analytical functions? I can use an approximate value in my case. $\endgroup$ Commented Mar 8, 2012 at 23:17
  • 3
    $\begingroup$ there are asymptotics available. For these, you can also consult the DLMF or works by Nico Temme (N.M. Temme, "Asymptotic estimates of Stirling numbers", Stud. Appl. Math. 89, p233-243, 1993) $\endgroup$
    – GertVdE
    Commented Mar 9, 2012 at 8:13

The accepted answer takes $O(kn)$ multiplications and additions. There is also a method using $O(k\log n)$ additions, multiplications and divisions, using the below identity. $$ S(n,k)=\frac1{k!}\sum_{j=0}^k(-1)^j\binom{k}j(k-j)^n $$

We can use DLMF Equation 26.3.E6 as a recurrence relation to greatly reduce the amount of computation necessary to compute the binomial coefficient.

$$ \binom{m}{n} = \frac{m-n+1}{n}\binom{m}{n-1} $$


accum ← 0
k_choose_j ← 1
for j = 0,1,...,k-1:
  accum ← accum + (-1)^j * k_choose_j * (k - j)^n
  k_choose_j ← k_choose_j * (k-j) / (j+1)
return accum / factorial(k)

Note that in the above pseudocode, we update k_choose_j at the end of each iteration, so we need to substitute j + 1 for n in the above relation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.