What is the difference between permutations and combinations, and when does each apply?
Permutations count ordered selections, while combinations count unordered selections. Use permutations when swapping selected items changes the outcome, and combinations when it does not; with replacement, the counting formulas change.
How to think about it
Permutations count ordered selections, where changing the positions creates a new outcome. Combinations count unordered selections, where the same chosen items remain the same outcome; for n distinct items chosen k at a time without replacement, their counts are P(n,k) = n!/(n-k)! and C(n,k) = n!/[k!(n-k)!], respectively.
Why the distinction works
The interview test is simple:
If swapping two selected items changes the result, use a permutation. If swapping them changes nothing, use a combination.
Let n mean the total number of distinct items and k mean how many you choose. A factorial, written n!, means multiplying every positive integer from n down to 1. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. We also define 0! as 1.
Take ten people and two positions.
If the positions are president and secretary, order matters because Alice as president and Ben as secretary is a different assignment from Ben as president and Alice as secretary.
There are 10 choices for president. After that choice, 9 people remain for secretary:
10 × 9 = 90
That is a permutation:
P(10,2) = 10!/(10-2)! = 90
Now change the question. Choose two people for a committee, with no positions or roles. Alice and Ben form the same committee as Ben and Alice. The selection order was different, but the outcome was not.
The first calculation counted both orders separately, so divide by the number of ways to arrange the two selected people:
2! = 2
Therefore:
C(10,2) = P(10,2)/2! = 90/2 = 45
The division by k! is the mechanism behind the combination formula. Every group of k distinct people can be arranged in exactly k! orders. Those orders are meaningful for a lineup or job assignment, but duplicates for a committee.
For distinct items selected without replacement:
P(n,k) = n × (n-1) × ... × (n-k+1)C(n,k) = P(n,k)/k!
The factorial version of the permutation formula works because the terms after the first k cancel:
P(n,k) = n!/(n-k)!
The two ten-person calculations are easy to verify in Python:
from math import comb, perm
print(perm(10, 2))
print(comb(10, 2))
This prints:
90
45
Replacement changes a different axis
“Does order matter?” and “Can an item be chosen again?” are separate questions.
Without replacement means a selected item cannot appear again. Drawing two different cards from a deck is the usual example.
With replacement means the item is returned before the next draw, so it can appear again.
| Situation | Count |
|---|---|
| Without replacement, order matters | P(n,k) |
| Without replacement, order does not matter | C(n,k) |
| With replacement, order matters | n^k |
| With replacement, order does not matter | C(n+k-1,k) |
For ten numbered tokens drawn twice with replacement, there are 10 choices on the first draw and 10 choices on the second:
10^2 = 100
That is the ordered count. The sequence token 3 then token 7 differs from token 7 then token 3.
If order is ignored, there are 55 possible results:
C(10+2-1,2) = C(11,2) = 55
You can see where that comes from. There are 10 repeated pairs, such as {3,3}, plus 45 pairs containing two different tokens:
10 + C(10,2) = 10 + 45 = 55
This formula is usually called combinations with repetition. A common derivation, stars and bars, represents the k selected items as stars and uses n-1 dividers to separate the n item types. The total number of positions is n+k-1, and choosing where the k stars go gives C(n+k-1,k).
One important probability warning: with replacement, unordered outcomes are not usually equally likely. The pair {3,3} comes from one ordered sequence, while {3,7} comes from two: 3 then 7, or 7 then 3. So the formula counts possible unordered results, but you cannot automatically divide by that count to get a probability.
A probability example: five cards
A five-card hand shows why the choice must match the event being counted.
The cards are physically dealt in order. But the event “this is a five-card hand with exactly two aces” does not care which card arrived first. The sample space, meaning the complete set of outcomes being counted, should therefore be the set of unordered five-card hands.
There are:
C(52,5) = 2,598,960
possible hands.
To get exactly two aces:
- Choose 2 of the 4 aces:
C(4,2) = 6 - Choose the remaining 3 cards from the 48 non-aces:
C(48,3) = 17,296
The favorable hands number:
C(4,2) × C(48,3) = 6 × 17,296 = 103,776
So:
P(exactly 2 aces) = 103,776/2,598,960 ≈ 3.99%
You could solve the same problem using permutations, but then both parts must be ordered. The denominator would be P(52,5), the number of five-card deal sequences. The numerator would be:
C(5,2) × P(4,2) × P(48,3)
Here, C(5,2) chooses which two deal positions contain aces. The other factors fill those positions with distinct cards. This produces the same probability because every unordered hand has exactly 5! possible deal orders.
That consistency matters more than the particular formula. You may count ordered outcomes or unordered outcomes, but the numerator and denominator must use the same kind of outcome.
The nuance that earns the senior signal
“Order matters” refers to the outcome, not necessarily to the physical process.
A hand is dealt in order, but the hand itself is usually unordered. A password, race result, or sequence of API calls is ordered because changing positions changes what happened. A committee, feature subset, or five-card hand is unordered when only membership matters.
There is also a hidden assumption: the standard formulas assume the objects are distinct. If the objects include duplicates, swapping equal objects does not create a new arrangement.
For example, the word LEVEL has five letters, but the two L characters are indistinguishable from each other, as are the two E characters. The number of distinct arrangements is:
5!/(2! × 2!) = 30
It is not 5! = 120, because the repeated letters would cause each arrangement to be counted four times.
A second assumption concerns probability. Counting combinations gives a probability only when the counted outcomes are equally likely, or when you account for their different weights.
A uniformly dealt five-card hand is a good case: every unordered hand has the same probability. A with-replacement draw is different. With two fair draws from ten tokens, the ordered sequences are equally likely, but unordered outcomes are not. A repeated pair has one sequence; a pair of different tokens has two.
Do not use permutations or combinations as a substitute for probability modeling when draws have unequal weights, stopping rules, or complicated dependencies. If one product is recommended 90 percent of the time and another 10 percent, there are two possible outcomes but not two equally likely outcomes. You must sum their probabilities, not divide by two.
Common failure modes
Using combinations for assigned roles. The first symptom is a count that is too small by a factor of k!. Two roles among ten people produce 45 if you use C(10,2), but the correct answer is 90 because the roles distinguish the people.
Mixing ordered and unordered counts. In the card example, the ordered favorable count is 12,453,120. Dividing it by the unordered denominator 2,598,960 gives a value greater than one. That impossible probability is an immediate sign that the numerator and denominator describe different sample spaces.
Forgetting replacement. A simulation with replacement will contain duplicate draws. If the formula says duplicate selections are impossible, the model and the calculation are answering different questions.
What they’ll ask next
What if I choose three people, make one president, and leave the other two without roles?
Choose the president in 10 ways, then choose the unordered pair from the remaining 9:
10 × C(9,2) = 10 × 36 = 360
Equivalently, count all three-person permutations and divide by 2! for the two people whose order does not matter:
P(10,3)/2! = 720/2 = 360
What if all three people receive distinct roles?
Then every position matters, so use a permutation:
P(10,3) = 10 × 9 × 8 = 720
Can I always use permutations, even for a combination problem?
Yes, if you keep the sample space consistent. For a card hand, count ordered deals in both the numerator and denominator, and the probability will be correct. Combinations are usually simpler when the event itself ignores order, which is why they are the clearer answer.
Say this in the interview: “If swapping two selected items changes the outcome, I use a permutation; if it leaves the outcome unchanged, I use a combination, then I check replacement and keep the numerator and denominator in the same sample space.”