Combinatorics is fascinating. It's about counting. The concept and exercises are often simple to understand, but the solutions can be tricky to find. Does order matter? Are repetitions allowed?
I wanted to write a short summary for myself where I could find the main formulas and have an intuitive proof of why they work. The proofs may not be extremely rigorous, but I think they are fairly easy to understand.
In these explanations, you will mainly encounter 2 letters, (the total number of elements in the set) and (the length of the sequence you want to get). For example, if you have an alphabet with 4 letters and you want to form a 2-letter password, then and .
With Order, Repetition Allowed
Example: How many unique 6-letter passwords can you create? (assuming that the allowed characters are A-Za-z0-9 for a total of 62 chars) → .
Formula:
Proof: We fill the positions one by one. Each position has possible elements because repetition is allowed. By the multiplication rule, the total number of sequences we can form is:
With Order, No Repetition
Example: How many ways can the top 3 finishers be arranged from 10 runners? → .
Formula:
This is called a -permutation.
The number of -permutations is hence .
Proof: We fill the positions one by one. The first position has choices, the second has (one element is already used and repetition is not allowed), the third has , and so on. The th position has choices left. By the multiplication rule, the total number of sequences we can form is:
Without Order, Repetition Allowed
Example: How many ways to choose 3 scoops of ice cream from 5 flavors (flavors can repeat)? → .
Proof: A selection is fully described by how many items we pick of each type. So we just need to count solutions to:
where is the number of times type is picked.
This is the stars and bars trick. Represent each picked item with a star () and use bars () to separate the types. With flavors and scoops, picking 2 of flavor 1 and 1 of flavor 3 looks like:
Every selection becomes a row of stars and bars, symbols in total. Picking a selection is the same as picking which of those positions hold a star:
Without Order, No Repetition
Example: How many 5-card hands can be drawn from a 52-card deck? → .
Proof: Let . Every -permutation of can be built in exactly one way by:
- Taking elements from (no repetition, no order, like drawing balls from a bag of numbered balls). By definition this is .
- Ordering these elements. There are ways to do this (as proven above).
By the multiplication rule,
If you are interested and want to know more, a good reference is Introductory Combinatorics by Richard A. Brualdi.