Skip to content
  • Overview
  • Curriculum
    • FLUMental maths and numerical fluency
    • COMBCounting and combinatorics
      • 1Basic counting

        • Counting: the four cases, and how to tell them apart
      • 2Binomial coefficients

        • Binomial identities, and proving them by counting twice
      • 3Inclusion–exclusion and invariants

        • Inclusion–exclusion, derangements and the pigeonhole
      • 4Advanced structures

        • Lattice paths, the reflection principle and Catalan numbers
    • PROBProbability
    • GAMEGames, decision theory and puzzles
    • MMMarket making
    • MKTMarkets and products

Practise

  • Question bank
  • Mental arithmetic
  • Market simulator
  • Arbitrage trees
  • Horse racing
  • Bid book
  • Screening tests
  • Mock papers

Reference

  • Formula reference
  • Search

Your record

  • Review queue
  • Progress
  • Leaderboard
  • Profile
  • Invite friends
AccountSend feedback
  1. Curriculum
  2. /Trading and market making
  3. /Counting and combinatorics
  4. /Inclusion–exclusion and invariants

Inclusion–exclusion, derangements and the pigeonhole

COMB · Chapter 3·12 min read·Asked at Jane Street, Optiver, SIG, IMC

Assumes Counting: the four cases, and how to tell them apart.

After this lesson you should be able to

  • Apply inclusion–exclusion to "at least one" problems.
  • Derive the derangement count and know its limit.
  • Use a pigeonhole or parity argument to prove something is impossible.

Two techniques cover most of the counting problems that look hard. Inclusion–exclusion handles overlapping conditions, and its standard cue is the phrase "at least one". Pigeonhole and parity handle the questions that ask you to prove something *cannot* happen, which is a different kind of answer and needs a different reflex.

Equation 3.1

Inclusion–exclusion

Add the singles, subtract the pairs, add the triples, alternating. Each element ends up counted exactly once.

∣⋃i=1nAi∣=∑∣Ai∣−∑i<j∣Ai∩Aj∣+∑i<j<k∣Ai∩Aj∩Ak∣−⋯\left|\bigcup_{i=1}^{n} A_i\right| = \sum |A_i| - \sum_{i<j} |A_i \cap A_j| + \sum_{i<j<k} |A_i \cap A_j \cap A_k| - \cdots​i=1⋃n​Ai​​=∑∣Ai​∣−i<j∑​∣Ai​∩Aj​∣+i<j<k∑​∣Ai​∩Aj​∩Ak​∣−⋯
AiA_iAi​
The set of outcomes satisfying the iii-th condition.

Proposition 3.2

Take the complement first

When a problem says "at least one", the complement — "none" — is almost always the easier count. For independent conditions, P(at least one)=1−∏(1−pi)P(\text{at least one}) = 1 - \prod(1 - p_i)P(at least one)=1−∏(1−pi​), and you have avoided inclusion–exclusion entirely. Reach for the full alternating sum only when the conditions genuinely interact.

Holds when

  • The birthday problem, the coupon collector and "at least one six in four rolls" all yield to the complement in one line.
  • Inclusion–exclusion earns its keep when the events are structurally linked, as in derangements.
  • Both A and B — 10 of 100
  • A only — 30 of 100
  • B only — 20 of 100
  • Neither — 40 of 100
Figure 3.3 · Where the overlap goes when you count A or B. A covers 40 outcomes and B covers 30, but 10 satisfy both. Adding 40 + 30 counts those 10 twice, so subtract the overlap once: the union contains 60 of the 100 outcomes.

Derivation 3.4

Derangements — the hat-check problem

How many permutations of nnn items leave nothing in its own place?

  1. ∣Ai∣=(n−1)! where Ai fixes item i|A_i| = (n-1)! \text{ where } A_i \text{ fixes item } i∣Ai​∣=(n−1)! where Ai​ fixes item i

    Pin one item and permute the rest.

  2. ∣⋃Ai∣=∑k=1n(−1)k+1(nk)(n−k)!\left|\bigcup A_i\right| = \sum_{k=1}^{n}(-1)^{k+1}\binom{n}{k}(n-k)!​⋃Ai​​=k=1∑n​(−1)k+1(kn​)(n−k)!

    Inclusion–exclusion over which items are fixed.

  3. Dn=n!∑k=0n(−1)kk!D_n = n!\sum_{k=0}^{n}\frac{(-1)^k}{k!}Dn​=n!k=0∑n​k!(−1)k​

    Subtract from the total and simplify.

Dn=n!∑k=0n(−1)kk! ⟶ n!eD_n = n!\sum_{k=0}^{n}\frac{(-1)^k}{k!} \ \longrightarrow\ \frac{n!}{e}Dn​=n!k=0∑n​k!(−1)k​ ⟶ en!​

Why the answer is 1/e1/e1/e. The probability that a random permutation is a derangement tends to 1/e≈0.36791/e \approx 0.36791/e≈0.3679, and it does so almost immediately: at n=4n = 4n=4 it is already 0.3750.3750.375, and at n=7n = 7n=7 it matches to four decimals. The reason is that each item fails to be fixed with probability roughly 1−1/n1 - 1/n1−1/n, and (1−1/n)n→e−1(1-1/n)^n \to e^{-1}(1−1/n)n→e−1. The near-independence of the events is what makes a Poisson-style limit appear, and it is why the number of fixed points of a random permutation is approximately Poisson with mean one.

Example 3.5

Five traders hang up five identical-looking coats and each takes one at random. What is the probability nobody gets their own?

Show the worked solutionHide the worked solution

Worked solution

  1. Formula
    P=Dnn!=∑k=0n(−1)kk!P = \frac{D_n}{n!} = \sum_{k=0}^{n}\frac{(-1)^k}{k!}P=n!Dn​​=k=0∑n​k!(−1)k​
  2. Substitute
    =1−1+12−16+124−1120= 1 - 1 + \tfrac12 - \tfrac16 + \tfrac1{24} - \tfrac1{120}=1−1+21​−61​+241​−1201​
  3. Solve
    =60−20+5−1120=44120= \frac{60 - 20 + 5 - 1}{120} = \frac{44}{120}=12060−20+5−1​=12044​
  4. D5=44D_5 = 44D5​=44
  5. Answer
    P=44120≈36.7%P = \frac{44}{120} \approx 36.7\%P=12044​≈36.7%

Sanity check. Within 0.0020.0020.002 of 1/e=0.36791/e = 0.36791/e=0.3679 at only five items, which is the point of the intuition above.

The rest of this lesson is in Premium

You have read the opening. 14 more sections follow, including 5 worked examples and 3 quick checks.

Start the free 7-day trialSign in

Nothing is charged for 7 days, and you can cancel before then. Or read Arithmetic that survives a clock in full, free.

← Binomial identities, and proving them by counting twiceLattice paths, the reflection principle and Catalan numbers →
On this page
  • Inclusion–exclusion
  • Take the complement first
  • Where the overlap goes when you count A or B
  • Derangements — the hat-check problem
  • Worked example

QuantMax · 141 lessons · 1342 questions · c5c0caa

  • Premium
  • Arbitrage trees
  • Horse racing
  • Invite friends
  • Account
  • About QuantMax
  • Terms
  • Privacy

Firm names identify publicly reported question patterns and nothing more. QuantMax is not affiliated with, endorsed by, or recruiting for any firm named in the curriculum. Everything you do in lessons and the question bank is kept to your account.