A Practical Guide to Quantitative Finance Interviews
Contents

4.2 Combinatorial Analysis

Many problems in probability theory can be solved by simply counting the number of different ways that a certain event can occur. The mathematic theory of counting is often referred to as combinatorial analysis (or combinatorics). In this section, we will cover the basics of combinatorial analysis.

Basic principle of counting: Let SS be a set of length-kk sequences. If there are

65

Then there are a total of n1⋅n2⋯nkn_1\cdot n_2\cdots n_k possible outcomes.

Permutation: A rearrangement of objects into distinct sequence (i.e., order matters).

Property: There are n!n1!n2!⋯nr!\displaystyle\frac{n!}{n_1!n_2!\cdots n_r!} different permutations of nn objects, of which n1n_1 are alike, n2n_2 are alike, ⋯\cdots, nrn_r are alike.

Combination: An unordered collection of objects (i.e., order doesn’t matter).

Property: There are (nr)=n!(n−r)!r!\displaystyle\binom nr=\frac{n!}{(n-r)!r!} different combinations of nn distinct objects taken rr at a time.

Binomial theorem: (x+y)n=∑k=0n(nk)xkyn−k\displaystyle(x+y)^n=\sum_{k=0}^{n}\binom nk x^k y^{n-k}

Inclusion-Exclusion Principle: P(E1∪E2)=P(E1)+P(E2)−P(E1E2)P(E_1\cup E_2)=P(E_1)+P(E_2)-P(E_1E_2)

P(E1∪E2∪E3)=P(E1)+P(E2)+P(E3)−P(E1E2)−P(E1E3)−P(E2E3)+P(E1E2E3)P(E_1\cup E_2\cup E_3)=P(E_1)+P(E_2)+P(E_3)-P(E_1E_2)-P(E_1E_3)-P(E_2E_3)+P(E_1E_2E_3)

and more generally,

P(E1∪E2∪⋯∪EN)=∑i=1NP(Ei)−∑i1<i2P(Ei1Ei2)+⋯+(−1)r+1∑i1<i2<⋯irP(Ei1Ei2⋯Eir)+⋯+(−1)N+1P(E1E2⋯EN)\begin{aligned}P(E_1\cup E_2\cup\cdots\cup E_N)&=\sum_{i=1}^{N}P(E_i)-\sum_{i_1<i_2}P(E_{i_1}E_{i_2})+\cdots\\&\quad+(-1)^{r+1}\sum_{i_1<i_2<\cdots i_r}P(E_{i_1}E_{i_2}\cdots E_{i_r})+\cdots\\&\quad+(-1)^{N+1}P(E_1E_2\cdots E_N)\end{aligned}

where ∑i1<i2<⋯irP(Ei1Ei2⋯Eir)\displaystyle\sum_{i_1<i_2<\cdots i_r}P(E_{i_1}E_{i_2}\cdots E_{i_r}) has (Nr)\displaystyle\binom Nr terms.

Poker hands

Poker is a card game in which each player gets a hand of 5 cards. There are 52 cards in a deck. Each card has a value and belongs to a suit. There are 13 values, 2,3,4,5,6,7,8,9,10,Jjack,Qqueen,Kking,Aace2,3,4,5,6,7,8,9,10,\overset{\text{jack}}{J},\overset{\text{queen}}{Q},\overset{\text{king}}{K},\overset{\text{ace}}{A}, and four suits, ♠spade, ♣club, ♥heart, ♦diamond.

66

What are the probabilities of getting hands with four-of-a-kind (four of the five cards with the same value)? Hands with a full house (three cards of one value and two cards of another value)? Hands with two pairs?

Solution: The number of different hands of a five-card draw is the number of 5-element subsets of a 52-element set, so total number of hands =(525)=2,598,960\displaystyle=\binom{52}{5}=2,598,960.

Hands with a four-of-a-kind: First we can choose the value of the four cards with the same value, there are 13 choices. The 5th card can be any of the rest 48 cards (12 choices for values and 4 choices for suits). So the number of hands with four-of-a kind is 13×48=62413\times48=624.

Hands with a Full House: In sequence we need to choose the value of the triple, 13 choices; the suits of the triple, (43)\displaystyle\binom43 choices; the value of the pair, 12 choices; and the suits of the pair, (42)\displaystyle\binom42 choices. So the number of hands with full house is 13×(43)×12×(42)=13×4×12×6=3,744\displaystyle13\times\binom43\times12\times\binom42=13\times4\times12\times6=3,744.

Hands with Two Pairs: In sequence we need to choose the values of the two pairs, (132)\displaystyle\binom{13}{2} choices; the suits of the first pair, (42)\displaystyle\binom42 choices; the suits of the second pair, (42)\displaystyle\binom42 choices; and the remaining card, 44 (52−4×252-4\times2, since the last cards can not have the same value as either pair) choices. So the number of hands with two pairs is (132)×(42)×(42)×44=78×6×6×44=123,552\displaystyle\binom{13}{2}\times\binom42\times\binom42\times44=78\times6\times6\times44=123,552.

To calculate the probability of each, we only need to divide the number of hands of each kind by the total possible number of hands.

Hopping rabbit

A rabbit sits at the bottom of a staircase with nn stairs. The rabbit can hop up only one or two stairs at a time. How many different ways are there for the rabbit to ascend to the top of the stairs?5

67

Solution: Let’s begin with the simplest cases and consider solving the problem for any number of stairs using induction. For n=1n=1, there is only one way and f(1)=1f(1)=1. For n=2n=2, we can have one 2-stair hop or two 1-stair hops. So f(2)=2f(2)=2. For any n>2n>2, there are always two possibilities for the last hop, either it’s a 1-stair hop or a 2-stair hop. In the former case, the rabbit is at (n−1)(n-1) before reaching nn, and it has f(n−1)f(n-1) ways to reach (n−1)(n-1). In the latter case, the rabbit is at (n−2)(n-2) before reaching nn, and it has f(n−2)f(n-2) ways to reach (n−2)(n-2). So we have f(n)=f(n−2)+f(n−1)f(n)=f(n-2)+f(n-1). Using this function we can calculate f(n)f(n) for n=3,4,⋯n=3,4,\cdots6

Screwy pirates 2

Having peacefully divided the loot (in chapter 2), the pirate team goes on for more looting and expands the group to 11 pirates. To protect their hard-won treasure, they gather together to put all the loot in a safe. Still being a democratic bunch, they decide that only a majority — any majority — of them (≥6\ge6) together can open the safe. So they ask a locksmith to put a certain number of locks on the safe. To access the treasure, every lock needs to be opened. Each lock can have multiple keys; but each key only opens one lock. The locksmith can give more than one key to each pirate.

What is the smallest number of locks needed? And how many keys must each pirate carry?7

Solution: This problem is a good example of the application of combinatorial analysis in information sharing and cryptography. A general version of the problem was explained in a 1979 paper “How to Share a Secret” by Adi Shamir. Let’s randomly select 5 pirates from the 11-member group; there must be a lock that none of them has the key to. Yet any of the other 6 pirates must have the key to this lock since any 6 pirates can open all locks. In other words, we must have a “special” lock to which none of the 5 selected pirates has a key and the other 6 pirates all have keys. Such 5-pirate groups are randomly selected. So for each combination of 5 pirates, there must be such a “special” lock. The minimum number of locks needed is (115)=11!5!6!=462\displaystyle\binom{11}{5}=\frac{11!}{5!6!}=462 locks. Each lock has 6 keys, which are given to a unique 6-member subgroup. So each pirate must have 462×611=252\displaystyle\frac{462\times6}{11}=252 keys. That’s surely a lot of locks to put on a safe and a lot of keys for each pirate to carry.

68

Chess tournament

A chess tournament has 2n2^n players with skills 1>2>⋯>2n1>2>\cdots>2^n. It is organized as a knockout tournament, so that after each round only the winner proceeds to the next round. Except for the final, opponents in each round are drawn at random. Let’s also assume that when two players meet in a game, the player with better skills always wins. What’s the probability that players 1 and 2 will meet in the final?8

Solution: There are at least two approaches to solve the problem. The standard approach applies multiplication rule based on conditional probability, while a counting approach is far more efficient. (We will cover conditional probability in detail in the next section.)

Let’s begin with the conditional probability approach, which is easier to grasp. Since there are 2n2^n players, the tournament will have nn rounds (including the final). For round 1, players 2,3,⋯ ,2n2,3,\cdots,2^n each have 12n−1\displaystyle\frac1{2^n-1} probability to be 1’s rival, so the probability that 1 and 2 do not meet in round 1 is 2n−22n−1=2×(2n−1−1)2n−1\displaystyle\frac{2^n-2}{2^n-1}=\frac{2\times(2^{n-1}-1)}{2^n-1}. Condition on that 1 and 2 do not meet in round 1, 2n−12^{n-1} players proceed to the 2nd round and the conditional probability that 1 and 2 will not meet in round 2 is 2n−1−22n−1−1=2×(2n−2−1)2n−1−1\displaystyle\frac{2^{n-1}-2}{2^{n-1}-1}=\frac{2\times(2^{n-2}-1)}{2^{n-1}-1}. We can repeat the same process until the (n−1)(n-1)th round, in which there are 222^2 (=2n/2n−2=2^n/2^{n-2}) players left and the conditional probability that 1 and 2 will not meet in round (n−1)(n-1) is 22−222−1=2×(22−1−1)22−1\displaystyle\frac{2^2-2}{2^2-1}=\frac{2\times(2^{2-1}-1)}{2^2-1}.

Let E1E_1 be the event that 1 and 2 do not meet in round 1;
E2E_2 be the event that 1 and 2 do not meet in rounds 1 and 2;
…
En−1E_{n-1} be the event that 1 and 2 do not meet in round 1,2,⋯ ,n−11,2,\cdots,n-1.

Apply the multiplication rule, we have

P(1 and 2 meet in the nth game)=P(E1)×P(E2∣E1)×⋯×P(En−1∣E1E2⋯En−2)=2×(2n−1−1)2n−1×2×(2n−2−1)2n−1−1×⋯×2×(22−1−1)22−1=2n−12n−1\begin{aligned}P(\text{1 and 2 meet in the }n\text{th game})&=P(E_1)\times P(E_2\mid E_1)\times\cdots\times P(E_{n-1}\mid E_1E_2\cdots E_{n-2})\\&=\frac{2\times(2^{n-1}-1)}{2^n-1}\times\frac{2\times(2^{n-2}-1)}{2^{n-1}-1}\times\cdots\times\frac{2\times(2^{2-1}-1)}{2^2-1}=\frac{2^{n-1}}{2^n-1}\end{aligned} 69

Now let’s move on to the counting approach. Figure 4.2A is the general case of what happens in the final. Player 1 always wins, so he will be in the final. From the figure, it is obvious that 2n2^n players are separated to two 2n−12^{n-1}-player subgroups and each group will have one player reaching the final. As shown in Figure 4.2B, for player 2 to reach the final, he/she must be in a different subgroup from 1. Since any of the remaining players in 2,3,⋯ ,2n2,3,\cdots,2^n are likely to be one of the (2n−1−1)(2^{n-1}-1) players in the same subgroup as player 1 or one of the 2n−12^{n-1} players in the subgroup different from player 1, the probability that 2 is in a different subgroup from 1 and that 1 and 2 will meet in the final is simply 2n−12n−1\displaystyle\frac{2^{n-1}}{2^n-1}. Clearly, the counting approach provides not only a simpler solution but also more insight to the problem.

Two knockout tournament diagrams: A general case, B with players 1 and 2 in different groups of 2 to the power n−1 players, so both reach the final
Figure 4.2A The general case of separating 2n2^n players into 2n−12^{n-1}-player subgroups; 4.2B The special case with players 1 and 2 in different groups

Application letters

You’re sending job applications to 5 firms: Morgan Stanley, Lehman Brothers, UBS, Goldman Sachs, and Merrill Lynch. You have 5 envelopes on the table neatly typed with names and addresses of people at these 5 firms. You even have 5 cover letters personalized to each of these firms. Your 3-year-old tried to be helpful and stuffed each cover letter into each of the envelopes for you. Unfortunately she randomly put letters 70 into envelopes without realizing that the letters are personalized. What is the probability that all 5 cover letters are mailed to the wrong firms?9

Solution: This problem is a classic example for the Inclusion-Exclusion Principle. In fact, a more general case is an example in Ross’ textbook First Course in Probability.

Let’s denote by Ei,i=1,⋯ ,5E_i,i=1,\cdots,5 the event that the ii-th letter has the correct envelope. Then P(⋃i=15Ei)\displaystyle P\left(\bigcup_{i=1}^{5}E_i\right) is the probability that at least one letter has the correct envelope and 1−P(⋃i=15Ei)\displaystyle1-P\left(\bigcup_{i=1}^{5}E_i\right) is the probability that all letters have the wrong envelopes. P(⋃i=15Ei)\displaystyle P\left(\bigcup_{i=1}^{5}E_i\right) can be calculated using the Inclusion-Exclusion Principle:

P(⋃i=15Ei)=∑i=15P(Ei)−∑i1<i2P(Ei1Ei2)+⋯+(−1)6P(E1E2⋯E5)P\left(\bigcup_{i=1}^{5}E_i\right)=\sum_{i=1}^{5}P(E_i)-\sum_{i_1<i_2}P(E_{i_1}E_{i_2})+\cdots+(-1)^6P(E_1E_2\cdots E_5)

It’s obvious that P(Ei)=15, ∀i=1,⋯ ,5P(E_i)=\frac15,\ \forall i=1,\cdots,5. So ∑i=15P(Ei)=1\displaystyle\sum_{i=1}^{5}P(E_i)=1.

P(Ei1Ei2)P(E_{i_1}E_{i_2}) is the event that both letter i1i_1 and letter i2i_2 have the correct envelope. The probability that i1i_1 has the correct envelope is 1/51/5; Conditioned on that i1i_1 has the correct envelope, the probability that i2i_2 has the correct envelope is 1/41/4 (there are only 4 envelopes left). So P(Ei1Ei2)=15×15−1=(5−2)!5!\displaystyle P(E_{i_1}E_{i_2})=\frac15\times\frac1{5-1}=\frac{(5-2)!}{5!}.

There are (52)=5!2!(5−2)!\displaystyle\binom52=\frac{5!}{2!(5-2)!} members of P(Ei1Ei2)P(E_{i_1}E_{i_2}) in ∑i1<i2P(Ei1Ei2)\displaystyle\sum_{i_1<i_2}P(E_{i_1}E_{i_2}), so we have

∑i1<i2P(Ei1Ei2)=(5−2)!5!×5!2!(5−2)!=12!\sum_{i_1<i_2}P(E_{i_1}E_{i_2})=\frac{(5-2)!}{5!}\times\frac{5!}{2!(5-2)!}=\frac1{2!}

Similarly we have ∑i1<i2<i3P(Ei1Ei2Ei3)=13!\displaystyle\sum_{i_1<i_2<i_3}P(E_{i_1}E_{i_2}E_{i_3})=\frac1{3!}, ∑i1<i2<i3<i4P(Ei1Ei2Ei3Ei4)=14!\displaystyle\sum_{i_1<i_2<i_3<i_4}P(E_{i_1}E_{i_2}E_{i_3}E_{i_4})=\frac1{4!}, and P(E1E2⋯E5)=15!\displaystyle P(E_1E_2\cdots E_5)=\frac1{5!}.

71 ∴ P(⋃i=15Ei)=1−12!+13!−14!+15!=1930\therefore\ P\left(\bigcup_{i=1}^{5}E_i\right)=1-\frac1{2!}+\frac1{3!}-\frac1{4!}+\frac1{5!}=\frac{19}{30}

So the probability that all 5 letters are mailed to the wrong firms is 1−P(⋃i=15Ei)=1130\displaystyle1-P\left(\bigcup_{i=1}^{5}E_i\right)=\frac{11}{30}.

Birthday problem

How many people do we need in a class to make the probability that two people have the same birthday more than 1/21/2? (For simplicity, assume 365 days a year.)

Solution: The number is surprisingly small: 23. Let’s say we have nn people in the class. Without any restrictions, we have 365 possibilities for each individual’s birthday. The basic principle of counting tells us that there are 365n365^n possible sequences.

We want to find the number of those sequences that have no duplication of birthdays. For the first individual, we can choose any of the 365 days; but for the second, only 364 remaining choices left, …, for the rrth individual, there are 365−r+1365-r+1 choices. So for nn people there are 365×364×⋯×(365−n+1)365\times364\times\cdots\times(365-n+1) possible sequences where no two individuals have the same birthday. We need to have 365×364×⋯×(365−n+1)365n<1/2\displaystyle\frac{365\times364\times\cdots\times(365-n+1)}{365^n}<1/2 for the odds to be in our favor. The smallest such nn is 23.

100th digit

What is the 100th digit to the right of the decimal point in the decimal representation of (1+2)3000(1+\sqrt2)^{3000}?10

Solution: If you still have not figure out the solution from the hint, here is one more hint: (1+2)n+(1−2)n(1+\sqrt2)^n+(1-\sqrt2)^n is an integer when n=3000n=3000.

Applying the binomial theorem for (x+y)n(x+y)^n, we have

(1+2)n=∑k=0n(nk)1n−k(2)k=∑k=2j,0≤j≤n/2n(nk)1n−k(2)k+∑k=2j+1,0≤j≤n/2n(nk)1n−k(2)k\begin{aligned}(1+\sqrt2)^n&=\sum_{k=0}^{n}\binom nk1^{n-k}(\sqrt2)^k\\&=\sum_{\substack{k=2j,\,0\le j\le n/2}}^{n}\binom nk1^{n-k}(\sqrt2)^k+\sum_{\substack{k=2j+1,\,0\le j\le n/2}}^{n}\binom nk1^{n-k}(\sqrt2)^k\end{aligned} 72 (1−2)n=∑k=0n(nk)1n−k(−2)k=∑k=2j,0≤j≤n/2n(nk)1n−k(2)k−∑k=2j+1,0≤j≤n/2n(nk)1n−k(2)k\begin{aligned}(1-\sqrt2)^n&=\sum_{k=0}^{n}\binom nk1^{n-k}(-\sqrt2)^k\\&=\sum_{\substack{k=2j,\,0\le j\le n/2}}^{n}\binom nk1^{n-k}(\sqrt2)^k-\sum_{\substack{k=2j+1,\,0\le j\le n/2}}^{n}\binom nk1^{n-k}(\sqrt2)^k\end{aligned}

So (1+2)n+(1−2)n=2∑k=2j,0≤j≤n/2n(nk)1n−k(2)k\displaystyle(1+\sqrt2)^n+(1-\sqrt2)^n=2\sum_{\substack{k=2j,\,0\le j\le n/2}}^{n}\binom nk1^{n-k}(\sqrt2)^k, which is always an integer. It is easy to see that 0<(1−2)3000≪10−1000<(1-\sqrt2)^{3000}\ll10^{-100}. So the 100th digit of (1+2)n(1+\sqrt2)^n must be 9.

Cubic of integer

Let xx be an integer between 1 and 101210^{12}, what is the probability that the cubic of xx ends with 11?11

Solution: All integers can be expressed as x=a+10bx=a+10b, where aa is the last digit of xx. Applying the binomial theorem, we have x3=(a+10b)3=a3+30a2b+300ab2+1000b3x^3=(a+10b)^3=a^3+30a^2b+300ab^2+1000b^3.

The unit digit of x3x^3 only depends on a3a^3. So a3a^3 has a unit digit of 1. Only a=1a=1 satisfies this requirement and a3=1a^3=1. Since a3=1a^3=1, the tenth digit only depends on 30a2b=30b30a^2b=30b. So we must have that 3b3b ends in 1, which requires the last digit of bb to be 7. Consequently, the last two digits of xx should be 71, which has a probability of 1% for integers between 1 and 101210^{12}.