keisoku

Stirling Numbers of the Second Kind S(n,k)

Compute the Stirling number of the second kind S(n,k), the number of ways to partition n elements into k non-empty subsets, with the related Bell number.

Input

Enter n (number of elements) and k (number of subsets) to compute the Stirling number of the second kind S(n,k): the number of ways to split n distinct elements into k non-empty subsets.

Integer from 0 to 200

Non-negative integer

Result

S(5, 2) — partitions into 2 non-empty subsets

15

Bell number B(5) (row sum)

52

Elements n

5

Subsets k

2

Row for n = 5: S(n,0) to S(n,n)

S(n, k)Value
S(5, 0)0
S(5, 1)1
S(5, 2)15
S(5, 3)25
S(5, 4)10
S(5, 5)1

How it works

  • The Stirling number of the second kind S(n,k) counts the ways to partition a set of n distinct elements into k non-empty, unlabeled subsets.
  • It is computed with the recurrence S(n,k) = k times S(n-1,k) plus S(n-1,k-1): the new element either joins one of the existing k subsets or forms a brand-new singleton subset.
  • Boundary conditions are S(0,0) = 1, S(n,0) = 0 for n greater than 0, and S(0,k) = 0 for k greater than 0. When k exceeds n the value is 0.
  • The row sum S(n,0) + S(n,1) + ... + S(n,n) equals the Bell number B(n), the total number of partitions of an n-element set.
  • Because the values grow very fast, the calculation uses arbitrary-precision integers (BigInt) for exact results, displayed as strings.

Reviews

Tell us what you think of this calculator.

Write a review

  1. Home
  2. Stirling Numbers of the Second Kind S(n,k)