Skip to content
UniKit

Permutations & combinations

Compute P(n,r), C(n,r), permutations with repetition, circular permutations, derangements D(n), Stirling numbers of both kinds and Catalan numbers — each formula explained.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Result

Permutations P(n, k)20
P(n, k) = n! / (n − k)!
Arrange k of n distinct items in a row; a different order counts as a different arrangement.
Combinations C(n, k)10
C(n, k) = n! / (k! · (n − k)!)
Choose k of n distinct items as a set — only which items were picked matters, not the order.
Permutations with repetition n^k25
n^k
Pick k times from n kinds of items, repetition allowed, and the order matters.
Combinations with repetition C(n + k − 1, k)15
C(n + k − 1, k)
Pick k items from n kinds with repetition allowed, counting only how many of each kind you took.
Circular permutations (n − 1)!24
(n − 1)!
Arrange n distinct items around a circle: rotations count as the same arrangement, so one item is fixed first.
Derangements D(n)44
D(n) = (n − 1) · (D(n − 1) + D(n − 2))
Permutations of n items in which no item stays in its original position (the hat-check problem).
Stirling numbers of the first kind c(n, k)50
c(n, k) = c(n − 1, k − 1) + (n − 1) · c(n − 1, k)
Ways to arrange n distinct items into k non-empty cycles — also the coefficients of the rising factorial.
Stirling numbers of the second kind S(n, k)15
S(n, k) = S(n − 1, k − 1) + k · S(n − 1, k)
Ways to partition n distinct items into k non-empty subsets, where the subsets are unordered.
Catalan numbers Cₙ42
Cₙ = C(2n, n) / (n + 1)
The number of valid bracket sequences of length 2n, and the number of distinct binary search trees on n nodes.

What this tool does

  • Statistics and probability homework: every common counting formula — P(n,k), C(n,k), permutations with repetition — in one place, so you cannot mix them up.
  • Word problems about arrangements: derangements, circular seating and group splits map to D(n), (n−1)! and Stirling numbers of the second kind.
  • Competitive programming and algorithms: Catalan numbers show up in bracket matching, binary tree counting and stack permutations — check the first terms here.
  • Teaching: each formula comes with a one-line explanation, which makes it easy to explain why a problem needs combinations rather than permutations.

Example

Input

n = 5, k = 2

Output

P(5, 2) = 20, C(5, 2) = 10, 5^2 = 25, C(6, 2) = 15, circular 4! = 24, derangements D(5) = 44, c(5, 2) = 50, S(5, 2) = 15, Catalan C₅ = 42

When k is larger than n the permutation and combination rows show 0 by convention, and the Stirling rows show “—”.

Frequently asked questions

How do I tell permutations and combinations apart?

Ask whether the order matters. Queues, passwords and rankings need permutations P(n,k); picking people, raffles and groups need combinations C(n,k). The two differ by exactly k!: P(n,k) = C(n,k) × k!.

Why is the derangement count not just slightly below n!?

A derangement requires that nothing stays in place, which inclusion–exclusion turns into D(n) = n!·Σ(−1)^i/i!. The ratio D(n)/n! quickly approaches 1/e ≈ 0.3679, so after a random shuffle there is roughly a 37% chance nobody is back in their original seat.

What separates the two kinds of Stirling numbers?

The first kind c(n,k) counts ways to arrange n items into k cycles, which is an arrangement problem. The second kind S(n,k) counts ways to split n items into k non-empty subsets, where the subsets are unordered — a partition problem.

Where do Catalan numbers appear?

Anywhere a count must never go negative: valid sequences of n bracket pairs, binary search trees with n nodes, stack permutations of n elements and triangulations of a convex polygon are all Cₙ = C(2n,n)/(n+1).

What are the limits?

Factorial-based formulas accept n up to 1000; the Stirling numbers use dynamic programming and stop at n = 200. A formula outside its range shows “—” instead of failing, and the other rows keep working.

Keywords:permutationcombinationderangementstirling numberscatalan numbercircular permutation排列组合错排斯特林数卡特兰数圆排列

Related tools