Skip to content
QuantMax
QuantMax
  • 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. /Basic counting

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

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

After this lesson you should be able to

  • Classify a counting problem by order and replacement.
  • Use stars and bars for identical objects.
  • Spot when a "count" question is really a probability question.

Almost every counting question in an interview is one of four standard cases, and almost every wrong answer comes from picking the wrong one. Decide two things — does order matter, and can items repeat — and the formula follows.

RepetitionOrder mattersOrder does not
No repetitionn!(n−k)!\dfrac{n!}{(n-k)!}(n−k)!n!​(nk)\dbinom{n}{k}(kn​)
Repetition allowednkn^knk(n+k−1k)\dbinom{n+k-1}{k}(kn+k−1​)
Table 1.1 · The four cases. The bottom-right entry is stars and bars, and it is the one candidates forget exists. It counts multisets: how many ways to choose kkk items from nnn types when you may take several of a type.

Equation 1.2

The binomial coefficient

The number of ways to choose kkk items from nnn when order does not matter.

(nk)=n!k! (n−k)!\binom{n}{k} = \frac{n!}{k!\,(n-k)!}(kn​)=k!(n−k)!n!​
(nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k}(kn​)=(n−kn​)
Choosing what to take is the same as choosing what to leave.
(nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}(kn​)=(k−1n−1​)+(kn−1​)
Pascal: condition on whether the first item is taken.

Proposition 1.3

The identities worth knowing

Three come up repeatedly. The hockey-stick identity sums a column of Pascal’s triangle. Vandermonde’s identity splits a choice across two groups. And the committee-and-chair argument, k(nk)=n(n−1k−1)k\binom{n}{k} = n\binom{n-1}{k-1}k(kn​)=n(k−1n−1​), is the cleanest example of the double-counting technique: count the same thing two ways and equate.

Holds when

  • Hockey stick: ∑i=kn(ik)=(n+1k+1)\sum_{i=k}^{n}\binom{i}{k} = \binom{n+1}{k+1}∑i=kn​(ki​)=(k+1n+1​).
  • Vandermonde: ∑i(mi)(nk−i)=(m+nk)\sum_{i}\binom{m}{i}\binom{n}{k-i} = \binom{m+n}{k}∑i​(im​)(k−in​)=(km+n​).
  • Double counting is usually a cleaner proof than algebra, and it is what an interviewer wants to see.

Derivation 1.4

Stars and bars

How many ways can kkk identical items be distributed among nnn distinct boxes?

  1. ⋆⋆⏟box 1∣ ⏟box 2∣⋆⏟box 3\underbrace{\star\star}_{\text{box 1}} \mid \underbrace{\ }_{\text{box 2}} \mid \underbrace{\star}_{\text{box 3}}box 1⋆⋆​​∣box 2 ​​∣box 3⋆​​

    Write the items as stars and the dividers between boxes as bars.

  2. k stars and n−1 bars, in a rowk \text{ stars and } n-1 \text{ bars, in a row}k stars and n−1 bars, in a row

    Every arrangement corresponds to exactly one distribution.

  3. choose which k of the n+k−1 positions are stars\text{choose which } k \text{ of the } n+k-1 \text{ positions are stars}choose which k of the n+k−1 positions are stars
(n+k−1k)\binom{n+k-1}{k}(kn+k−1​)

Example 1.5

You buy 10 identical lots and must allocate them across 4 accounts, with empty accounts allowed. How many allocations are there?

Show the worked solutionHide the worked solution

Worked solution

  1. Formula
    (n+k−1k)\binom{n+k-1}{k}(kn+k−1​)
  2. Substitute
    n=4 accounts, k=10 lotsn = 4 \text{ accounts},\ k = 10 \text{ lots}n=4 accounts, k=10 lots
  3. Solve
    =(1310)=(133)= \binom{13}{10} = \binom{13}{3}=(1013​)=(313​)
  4. =13×12×116= \frac{13 \times 12 \times 11}{6}=613×12×11​
  5. Answer
    286286286

Sanity check. If empty accounts were forbidden, put one lot in each first and distribute the remaining 6, giving (96)=84\binom{9}{6} = 84(69​)=84 — a useful check that the constraint changes the count in the right direction.

The rest of this lesson is in Premium

You have read the opening. 13 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 twice →
On this page
  • The four cases
  • The binomial coefficient
  • The identities worth knowing
  • Stars and bars
  • Worked example

QuantMax · 141 lessons · 1342 questions · c5c0caa

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

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.