Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Counting without listing
How many ways can 3 books stand on a shelf? The first spot has 3 choices, the next 2, the last 1: . How many outfits from 3 shirts and 2 pairs of trousers? . Multiplying choices is the counting principle, and it lets you count huge sets without writing them out.
Two questions decide the formula. Does order matter? (A race podium: yes. A team: no.) Can things repeat? (PIN digits: yes. Lottery balls: no.) Counting ordered arrangements gives permutations. Counting unordered groups gives combinations.
| case | formula | count (n = 5, k = 3) | examples |
|---|---|---|---|
| ordered, with replacement | nᵏ | 125 | PIN codes, dice sequences |
| ordered, no replacement | n!/(n−k)! | 60 | podium finishes, task schedules |
| unordered, no replacement | C(n, k) | 10 | committees, poker hands, minibatches |
| unordered, with replacement | C(n+k−1, k) | 35 | scoops of ice cream, multisets |
How many test cases cover every pair of options? How many ways can a planner route a rover on a grid? How likely is a random hash collision? Engineers answer all of these by counting, and the same formulas size the search spaces that AI algorithms must explore.
- 1. Ways to arrange 3 books?
- 2. 4-digit PIN codes (digits may repeat)?
- 3. A team (unordered) vs a podium (ordered): which has more possibilities?
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.The four basic counts (choosing k of n)
| without repetition | with repetition | |
|---|---|---|
| ordered | ||
| unordered |
divides the ordered selections by the orders of each group.
Examples:
- podiums from 10 runners;
- 3-person teams;
- poker hands.
Probability by counting: P(full house) .
- 1. C(10, 3) = ?
- 2. C(n, k) vs C(n, n − k)?
- 3. Ordered, with repetition, k of n:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.More counting patterns
- Binomial theorem: . Setting gives , the number of subsets.
- Pascal’s rule: . Either item is in the group or it isn’t.
- Stars and bars: distributing identical items into bins can be done in ways. Write stars and bars in a row and choose the bars’ positions.
- Lattice paths: monotone paths across an grid number , since you choose which steps go right.
- Multinomial: arrangements of a word with repeated letters number .
- Binomial probabilities: P(exactly heads in fair tosses) . This leads into the binomial distribution (A4.2-1).
- 1. Ways to put 10 identical items in 4 bins?
- 2. Monotone paths on a 6 × 4 grid?
- 3. The sum of row n of Pascal's triangle is…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Proofs by counting two ways
- Pascal’s rule. Count the -subsets of by whether they contain : do and don’t. ∎
- . Each element is in or out, giving subsets. Grouping them by size gives the sum. ∎
- Stars and bars. There’s a bijection between distributions and arrangements of stars and bars. There are such arrangements. ∎
Derangements (inclusion–exclusion)
How many permutations of items leave nothing in its original place? Let be the permutations fixing . Inclusion–exclusion (A4.1-1) gives . So . If people grab hats at random, the chance nobody gets their own is about 37%, whether is 10 or 10 million.
Stirling’s formula and entropy
, with relative error about . Taking logs gives , where is the entropy. The number of length- binary strings with a fraction of ones is about . That’s the counting core of information theory and of compression limits (A5).
Exercise 3.1: How many 5-card hands contain at least one ace?
Use the complement: .
- 1. The fraction of derangements tends to…
- 2. log C(n, pn) ≈ …
- 3. Pascal's rule is proved by…
Level 4: Expert
★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.Uniform sampling of combinatorial objects
Shuffling a dataset, picking a minibatch, sampling a random subset of a stream: each needs every outcome equally likely.
- Fisher–Yates shuffle (Durstenfeld, 1964; Knuth, TAOCP Vol. 2). Swapping position with a uniform position in gives each of the permutations probability .
- The tempting bug swaps with a position in . It has equally likely runs, which can’t divide evenly among permutations (27 runs vs 6 permutations for ). Some orders become more likely.
- Reservoir sampling (Vitter, 1985) draws a uniform -subset from a stream of unknown length in one pass. It’s used for replay buffers and telemetry downsampling.
Counting in AI, robotics and engineering
- Search-space size. A 7-DOF arm discretized at 100 values per joint has configurations. That’s why sampling planners (RRT, PRM) replace enumeration (LaValle, 2006). Task orderings of sub-tasks number , so scheduling and TSP-like problems explode.
- Combinatorial testing. Covering all pairs of options with values needs far fewer tests than (covering arrays). It’s used in flight-software verification (Kuhn, Kacker and Lei, 2013).
- Learning theory. Finite hypothesis classes of size give sample complexity via the union bound. The Sauer–Shelah lemma counts labelings, , to define VC dimension (B1).
- Hash collisions and IDs. The birthday bound (A4.1-1) says random -bit IDs collide after about draws. It sizes UUIDs, checksums and cryptographic hashes.
References
- R. Graham, D. Knuth, O. Patashnik (1994). Concrete Mathematics, 2nd ed. Addison-Wesley.
- D. Knuth (1997). The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed. Addison-Wesley. (Shuffling.)
- R. Durstenfeld (1964). “Algorithm 235: random permutation.” Communications of the ACM, 7(7).
- J. Vitter (1985). “Random sampling with a reservoir.” ACM Transactions on Mathematical Software, 11(1).
- R. Stanley (2011). Enumerative Combinatorics, Vol. 1, 2nd ed. Cambridge. (The twelvefold way.)
- D. R. Kuhn, R. Kacker, Y. Lei (2013). Introduction to Combinatorial Testing. CRC Press.
- T. Cover, J. Thomas (2006). Elements of Information Theory, 2nd ed., Ch. 11. Wiley. (Method of types.)
- S. LaValle (2006). Planning Algorithms. Cambridge.