stirlingS2

stirlingS2(n, k)

Try it yourself:

See also:

stirlingS2(): Stirling Numbers of the Second Kind

stirlingS2(n, k) counts ways to partition n labeled items into k nonempty unlabeled groups. It is a core combinatorics function used in grouping and recurrence problems.

Valid parameters

n and k should be nonnegative integers, with k no larger than n for ordinary nonzero cases. For example, stirlingS2(3, 2) is 3. Use bellNumbers() to count partitions across all possible group counts.

Compare with combinations() and permutations(): those select or order items, while Stirling numbers partition every item. Values grow quickly, so retain exact integer arithmetic where possible.

Try Stirling S2 in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions