skip to content

Permutations and Combinations

Counting arrangements with and without replacement, factorials, n-choose-k and stars-and-bars, applied to card hands and the birthday problem. These decide most dice-and-cards brainteasers.

on this pageshow

questions

6

What is the difference between a permutation and a combination?

level: juniorimportance: must knowfreq 82%

answer

  1. does swapping two picks matter?
  2. ordered arrangements versus unordered selections
  3. one formula is the other divided
  4. divide out the k! orderings

basics

~10 s

A permutation counts ordered arrangements; a combination counts unordered selections. Taking k items from n gives n!/(n-k)! permutations and n!/(k!(n-k)!) combinations. The extra k! divides out the orderings of each selected group.

solid answer

~40 s

The single deciding question is: if I swap two of my picks, do I get a different outcome? If yes, order matters and you count permutations: `P(n, k) = n!/(n-k)!`, which is the product `n x (n-1) x ... x (n-k+1)`. If no, order does not matter and you count combinations: `C(n, k) = n!/(k!(n-k)!)`, usually read as "n choose k". The two are linked by exactly one factor: every unordered group of k items can be arranged in `k!` ways, so `C(n, k) = P(n, k)/k!`. Concretely, ranking 3 finishers out of 10 runners gives `10 x 9 x 8 = 720` outcomes, while picking 3 people out of 10 for an unranked committee gives `720/6 = 120`. Same pool, same k, different question.

go deeper

for a junior

Be ready to state both formulas from memory and apply the swap test out loud on a small example. Interviewers at this level mostly want to see that you do not confuse a ranked podium with an unranked committee.

for a middle

Explain where the k! division comes from rather than reciting it, and be able to derive n!/(n-k)! from the multiplication rule stage by stage. Expect to combine several counts inside one problem.

for a senior

Show that you decompose a messy count into independent stages and sanity-check the result against a small case you can enumerate by hand. Catching your own double-counting before the interviewer does is the signal here.

for a principal

Own the framing question: is the count even the right model? Be ready to say when a closed-form count is fragile - dependent choices, indistinguishable items, constraints - and when simulation or an approximation is the defensible answer instead.

## The one question that decides it Every counting problem in this family reduces to a single test: **if I swap two of the things I picked, is that a different outcome?** - "Gold, silver, bronze from 10 runners" - swapping two medallists changes the result, so order matters. Count **permutations**. - "A 3-person committee from 10 people" - swapping two members changes nothing, so order does not matter. Count **combinations**. Everything else is bookkeeping. ## Factorials and the product rule `n!` ("n factorial") is `n x (n-1) x (n-2) x ... x 2 x 1`. So `5! = 120`. By convention `0! = 1`, because it is the empty product and because that convention is what makes the formulas below behave at their edges. The engine underneath is the **multiplication rule**: if a choice is made in stages and stage 1 has `a` outcomes, stage 2 has `b` outcomes for each of those, and so on, the total is `a x b x ...`. ## Permutations: n!/(n-k)! Arrange `k` of `n` distinct items in order. The first slot has `n` candidates, the second has `n-1` (one is used up), the third `n-2`, down to `n-k+1` for the last slot. Multiplying: ``` P(n, k) = n x (n-1) x ... x (n-k+1) = n!/(n-k)! ``` The `(n-k)!` in the denominator simply cancels the tail of `n!` you never used. Two edge cases fall out for free: `P(n, n) = n!/0! = n!` (arrange everything), and `P(n, 0) = 1` (there is exactly one way to arrange nothing). ## Combinations: divide out the orderings Now suppose only the *set* of chosen items matters. Each set of `k` items was counted once for every way of ordering it, and there are `k!` such orderings. So the ordered count overcounts by a factor of exactly `k!`: ``` C(n, k) = P(n, k)/k! = n!/(k!(n-k)!) ``` That single division is the whole difference between the two formulas. It is also the source of the most common error in interviews: dividing by `k!` in a problem where order genuinely does matter, or forgetting to divide when it does not. ## Useful properties - **Symmetry:** `C(n, k) = C(n, n-k)`. Choosing which `k` items to take is the same act as choosing which `n-k` items to leave behind, so the two counts must be equal. This is a bijection argument, not algebra, and interviewers like hearing it that way. It is also a computational shortcut: `C(50, 48)` is `C(50, 2) = 1225`. - **Boundaries:** `C(n, 0) = C(n, n) = 1`, and `C(n, 1) = n`. - **Pascal's rule:** `C(n, k) = C(n-1, k-1) + C(n-1, k)` - split on whether a particular item is in the group or not. ## Computing without exploding Never expand large factorials. Use the multiplicative form and cancel as you go: ``` C(52, 5) = (52 x 51 x 50 x 49 x 48)/(5 x 4 x 3 x 2 x 1) = 2,598,960 ``` That is the number of distinct 5-card hands from a standard 52-card deck, and it is the denominator of essentially every card-probability question. Because order does not matter in a hand, it is a combination. The numerator of such a question is usually a product of smaller combinations - for example, a full house is "pick the rank that appears three times (13 ways), pick 3 of its 4 suits, pick a different rank for the pair (12 ways), pick 2 of its 4 suits": `13 x C(4,3) x 12 x C(4,2) = 13 x 4 x 12 x 6 = 3744`. ## Where candidates go wrong 1. **Keying off the word "choose" in the prompt.** English is not the specification; the swap test is. 2. **Mixing the two inside one problem.** It is normal for a single count to use permutations at one stage and combinations at another - decide stage by stage. 3. **Double counting ranks.** In the full-house count, `13 x 12` is deliberately ordered (three-of-a-kind rank first, pair rank second) because those two roles are different. Using `C(13, 2)` there would halve the answer incorrectly. 4. **Assuming items are distinct.** Both formulas assume `n` distinguishable items drawn without repetition. Repeated letters or repeated draws need a different tool. ## The 15-second version Order matters: `n!/(n-k)!`. Order does not: divide that by `k!`. If you can state the swap test and then write both formulas, you have answered the question completely.

  • Why does n choose k equal n choose (n-k)?
    Because picking the k items you take is the same decision as picking the n-k items you leave behind. Every selection of size k pairs with exactly one complementary selection of size n-k, so the two collections have the same size. It is also a handy shortcut: C(50, 48) is easier evaluated as C(50, 2) = 1225.
  • How many five-card poker hands are a full house?
    3744. Pick the rank that appears three times (13 ways), pick 3 of its 4 suits (C(4,3) = 4), pick a different rank for the pair (12 ways), pick 2 of its 4 suits (C(4,2) = 6): 13 x 4 x 12 x 6 = 3744. Against C(52,5) = 2,598,960 total hands that is roughly 0.144 percent.
  • Why is 0! defined as 1 rather than 0?
    It is the empty product, the multiplicative analogue of an empty sum being 0. The definition is also forced by the formulas: C(n, n) = n!/(n! x 0!) must equal 1, and P(n, n) = n!/0! must equal n!. Setting 0! = 0 would divide by zero in both.
  • In a five-card hand, how many hands contain exactly one pair?
    1,098,240. Choose the paired rank (13), choose 2 of its 4 suits (C(4,2) = 6), choose 3 distinct other ranks (C(12,3) = 220), and give each of those a suit (4 x 4 x 4 = 64): 13 x 6 x 220 x 64 = 1,098,240, or about 42 percent of all hands. The three side ranks use a combination because their order is irrelevant.

A permutation is a race podium: gold, silver and bronze are three different outcomes for the same three runners. A combination is the guest list: whoever shows up, the list is the same.

saying these in an interview costs you the question

  • Picks the formula from the word 'choose' in the prompt
  • Treats permutations and combinations as interchangeable
  • Forgets to divide by k! when order does not matter
  • Divides by k! in a problem where order does matter
  • Claims 0! equals 0
  • Expands full factorials instead of cancelling terms

context

open as a page

In counting problems, how do you decide between n^k, n!/(n-k)! and n choose k?

level: middleimportance: must knowfreq 67%

basics

~10 s

Answer two yes/no questions: does order matter, and may items repeat? Ordered with repeats is n^k; ordered without repeats is n!/(n-k)!; unordered without repeats is n choose k; unordered with repeats is C(n+k-1, k).

open as a page

Why is the chance of at least one six in four dice rolls not 4/6?

level: juniorimportance: should knowfreq 56%

basics

~20 s

Adding 1/6 four times double-counts rolls containing more than one six, and would give a probability above 1 for seven rolls. Use the complement: P(no six) = (5/6)^4, so P(at least one six) is about 0.518.

open as a page

In a room of 23 people, why is a shared birthday about 50% likely?

level: middleimportance: should knowfreq 47%

basics

~20 s

Because 23 people form C(23,2) = 253 pairs, not 23 comparisons. The probability that all 23 birthdays differ is (365 x 364 x ... x 343)/365^23, about 0.493, so at least one shared birthday has probability about 0.507.

open as a page

How do you size collision risk for randomly generated 64-bit identifiers?

level: seniorimportance: should knowfreq 33%

basics

~20 s

Use the birthday bound, not 1/N per identifier. With n values drawn uniformly from N possibilities, collision probability is roughly n^2/(2N), reaching 50% near 1.18 x sqrt(N) - about 5 billion values for 64 bits.

open as a page

How many ways can 10 identical tickets be assigned to 4 named engineers?

level: middleimportance: nice to knowfreq 22%

basics

~20 s

286, by stars and bars: line up 10 identical tickets and 3 dividers, then choose which 3 of the 13 positions are dividers, giving C(13,3) = 286. Requiring every engineer to get at least one ticket gives C(9,3) = 84.

open as a page