Combinatorics: Permutations and Combinations

Counting arrangements, counting selections, and the factorial that separates them.

Overview

The question to ask first

Does order matter?

Three medals from eight runners: gold, silver and bronze are different outcomes depending on who gets which, so order matters. That is a permutation.

Three people for a committee from eight: the same three people are the same committee however you list them. Order does not matter. That is a combination.

Everything else follows from answering that.

Combinatorics: Permutations and Combinations

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

Permutations count arrangements — order matters. n! / (n−k)!
Combinations count selections — order does not. n! / (k!(n−k)!)
The two differ by exactly k!: the number of orders each selection could have arrived in.
The bars are C(n, k) for every k. Symmetric, because choosing k to keep is choosing n−k to leave.

Combinatorics: Permutations and Combinations

The counting that probability is built on, and the one question that decides which formula to use.

The formulas

Permutations of k from n:

P(n, k)  =  n! / (n - k)!

There are n choices for the first position, n - 1 for the second, and so on for k positions. The factorial ratio is just that product written compactly.

Combinations of k from n:

C(n, k)  =  n! / ( k! (n - k)! )

Count the ordered arrangements, then divide by k! because each unordered selection was counted once for every order its members could have appeared in.

The readout makes the relationship concrete: at n = 12, k = 5 the ordered count is 95,040 and the unordered is 792, and 95,040 / 792 is exactly 120 = 5!.

Reading the shape

The bars are C(n, k) for every k from 0 to n.

Symmetric. C(n, k) = C(n, n-k), because choosing which k to keep is the same act as choosing which n - k to leave.

Largest in the middle. There are far more ways to pick half of something than to pick almost none or almost all.

Enormous quickly. Drag n to 24 and the middle bar passes two and a half million. This growth is why brute force over subsets is hopeless past small n, and why the readout switches to scientific notation.

That row of numbers is a row of Pascal's triangle, and the recurrence C(n,k) = C(n-1,k-1) + C(n-1,k) — either the last item is in your selection or it is not — is the standard dynamic-programming way to compute them without factorials.

With repetition

A third case, easy to miss. If the same item can be chosen more than once and order matters — a 4-digit PIN, where digits may repeat — the count is simply n^k. The readout gives this alongside.

At n = 10, k = 4 that is 10,000 PINs, against P(10, 4) = 5,040 if no digit could repeat.

Why it matters here

Binomial probabilities. The C(n, k) in [the binomial](bernoulli_binomial_poisson.html) is exactly this count — the number of orders in which k successes could have arrived.

Hypothesis testing. Permutation tests build a null distribution by enumerating or sampling rearrangements of the labels, and the count above says whether enumeration is feasible.

Cross-validation. The number of ways to split data into folds.

Feature selection. Choosing k features from n is C(n, k), which is why exhaustive search is abandoned almost immediately and greedy or regularised methods are used instead.

Complexity arguments. A great deal of "this is exponential" is this table growing.

Where it goes wrong

Not asking whether order matters. The commonest error, and it is a factor of k!.

Computing factorials directly. 21! overflows a 64-bit integer, and C(n, k) is usually far smaller than the factorials used to define it. Work in logarithms, or use the multiplicative recurrence, which is what this page does.

Forgetting repetition is allowed. Passwords, dice and sampling with replacement all permit it.

Double counting. When the objects are not all distinguishable the plain formulas over-count, and the multiset versions are needed instead.

Check yourself

0 of 3

Answer without scrolling back up.

  1. What separates a permutation count from a combination count?

  2. Why is C(n, k) symmetric in k?

  3. Why should you not compute C(n, k) from factorials directly?

Cheat sheet

Combinatorics: Permutations and Combinations

Three medals from eight runners: gold, silver and bronze are different outcomes depending on who gets which, so order matters. That is a permutation.

MATHS · vizlearn.in/maths/combinatorics.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.