Permutations and Combinations
Permutations and combinations count selections from a finite set. The key distinction is order. If the order of selected objects matters, use permutations or ordered arrangements. If order does not matter, use combinations.
These formulas are special cases of the product and division rules. The safest approach is to describe the object being counted in words before choosing a formula: ordered or unordered, with or without repetition, all objects or only some objects, distinct objects or repeated types.
Definitions
A permutation of distinct objects is an ordering of all objects. There are
permutations, where and .
An -permutation of distinct objects is an ordered selection of objects from :
An -combination of distinct objects is an unordered selection of objects from :
A multiset permits repeated elements. Counting with repetition changes the formula. Ordered selections with repetition from types have possibilities. Unordered selections with repetition of objects from types have
possibilities, the stars-and-bars count.
If a word has letters with repeated multiplicities , then the number of distinct rearrangements is
Key results
The formula for combinations follows from the division rule. First count ordered selections:
Each unordered -element subset has exactly orderings, so
Symmetry:
Choosing objects to include is equivalent to choosing objects to exclude.
Pascal's identity:
Proof: fix a particular element . An -subset either contains , in which case choose more from the other elements, or does not contain , in which case choose all from the other elements.
The binomial theorem states
The coefficient counts the choice of which of the factors contribute a term.
Stars and bars counts nonnegative integer solutions to
as . Think of stars and bars; the bars separate stars into boxes.
Visual
| Selection model | Order matters? | Repetition allowed? | Formula |
|---|---|---|---|
| arrange all distinct objects | yes | no | |
| choose ordered from | yes | no | |
| choose unordered from | no | no | |
| length- strings from symbols | yes | yes | |
| unordered from types | no | yes | |
| rearrange multiset | yes | repeated given |
Worked example 1: Count committees with roles
Problem. From students, choose a committee of . Then choose a chair and secretary from the committee. How many outcomes are possible?
Method.
- First choose the committee. Order does not matter:
- For each committee, choose the chair. There are choices.
- Then choose the secretary from the remaining committee members. There are choices.
- Multiply:
- Alternative check: choose the chair and secretary first as an ordered pair, then choose the other two committee members:
Checked answer. There are outcomes. The two methods agree because they describe the same final object: a -person committee with two distinct roles assigned.
Worked example 2: Count solutions with stars and bars
Problem. How many nonnegative integer solutions are there to
Method.
- Interpret the equation as distributing identical objects among boxes.
- Use stars and bars.
- There are positions in the star-bar string.
- Choose which positions contain bars:
- Equivalently choose the positions containing stars:
Checked answer. There are nonnegative integer solutions. For example, the pattern **|*****||*** corresponds to .
Code
from math import factorial, comb, perm
def multiset_permutations(counts):
total = sum(counts)
result = factorial(total)
for c in counts:
result //= factorial(c)
return result
def stars_and_bars(types, items):
return comb(types + items - 1, items)
print(factorial(5))
print(perm(10, 3))
print(comb(52, 5))
print(multiset_permutations([1, 4, 4, 2])) # MISSISSIPPI
print(stars_and_bars(4, 10))
Python's math.comb and math.perm are exact integer functions, useful for checking combinatorial calculations.
Common pitfalls
- Using permutations when order does not matter.
- Dividing by when repetition or repeated types mean not every object has exactly orderings.
- Forgetting that , which is needed for edge cases such as choosing all objects.
- Applying stars and bars to distinct objects. It counts identical objects distributed among labeled boxes.
- Counting roles and membership in the wrong order without checking that the final object is counted exactly once.
- Treating as zero or undefined without checking conventions; for integer counting, it is when or .
When a problem mixes membership and roles, decide what the final outcome contains. A committee with a chair is not merely an unordered set; it is an unordered set plus one distinguished member. You can count by choosing the committee first and then the chair, or by choosing the chair first and then the remaining members. Both methods should agree if they describe each final outcome exactly once. If they do not agree, one method is probably counting a different object.
Repeated letters and repeated selections are different issues. The word LEVEL has repeated letters already present, so distinct rearrangements require dividing by repeated multiplicities. By contrast, forming a length- password from letters with repetition allowed means each position may independently choose any letter. That count is , not and not a multiset count, because the positions are ordered.
Stars and bars also has boundary conditions. It counts nonnegative solutions by default. If a problem requires positive solutions to , first set , so the transformed equation is with . If upper bounds appear, plain stars and bars is no longer enough; use inclusion-exclusion or generating functions to remove solutions violating the bounds.
Binomial coefficients have several interchangeable interpretations. can count subsets of size , paths with steps of one kind and of another, coefficients in , or ways to place identical markers among labeled positions. Choosing the interpretation that matches the problem often gives a proof as well as a number.
A strong final check is to compare extreme cases. If , there should usually be one way to choose nothing. If , there should usually be one way to choose everything. If a formula fails these edge cases, the model likely used ordered choices, repetition, or division incorrectly.
For arrangements around a circle, be careful about symmetries. Seating distinct people around a round table usually gives arrangements because rotating the whole table does not change the seating. If mirror images are also considered identical, divide by another factor of for . These formulas are not ordinary permutations; they come from deciding which transformations leave the final arrangement unchanged.
For distributions, distinguish labeled and unlabeled boxes. Stars and bars counts identical objects into labeled boxes: giving candies to Alice and to Bo is different from giving to Alice and to Bo. If boxes are also unlabeled, the problem becomes an integer partition problem and requires different tools. Many mistakes come from silently changing whether recipients are distinct.
When a problem says "at least" or "at most," formulas often need summation. Choosing at most members from is not ; it is . Choosing at least may be easier by complement: nonempty subsets of a -element set.
A useful way to avoid formula hunting is to build the object in stages. If the stages are ordered choices, multiply. If the staged construction imposes an artificial order that the final object does not have, divide by the number of artificial orderings. This explains the formulas instead of treating them as separate memorized facts.
For combinations with restrictions, consider whether to choose the special objects first or last. Counting poker hands with exactly two aces starts by choosing the aces and then choosing non-aces. Counting committees with at least one senior may be easier by complement. The right order is the one that makes later choices independent and avoids overlap.
If a counting problem has identical objects and labeled boxes, stars and bars may apply. If the objects are distinct and the boxes are labeled, each object chooses a box, giving a product count instead. If both objects and boxes are unlabeled, the problem is usually about partitions and needs different methods.
Connections
- Counting principles supplies the product and division rules behind these formulas.
- Pigeonhole and inclusion-exclusion handles overlapping restrictions.
- Discrete probability uses combinations to count equally likely outcomes.
- Generating functions generalizes stars and bars and coefficient extraction.