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
201025152444501542What 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排列组合错排斯特林数卡特兰数圆排列