Monday, October 15, 2012

Those damn coins...

Coin tossing (or coin flipping) is one of the popular settings for probability questions. It might be of interest to contrast coin tossing and dice rolling:

- Coin tossing follows a binomial distribution (which converges to Gaussian); die rolling follows a uniform distribution.

- Tossing m coins gives an expectation value of m/2; rolling an m-sided die gives an expectation value of (m+1)/2.

Because of the binomial distribution, coin tossing problems usually are more involved than dice rolling in terms of arithmetics. The most straight-forward kind of coin problems would simply ask you about the mean and variance of the number of Head or Tail:

CT01
What is the expected gain if you are paid $1 for each head in tossing 4 fair coins? What is the standard deviation?

CT01 - Answer:
Remember that in n binary trials with single success probability p, the mean is np and the variance is np(1-p). So the expected gain is $2 and the standard deviation is $1.

Sometimes the question is framed as a game:

CT02
What is the probability that the number of Heads is greater than or equals to 2 when tossing 4 coins?

CT02 - Answer:
The Pascal numbers for 4 trials are {1,4,6,4,1}. Hence the required probability is (6+4+1)/16 = 11/16.

Once the number of tossing becomes large, the Law of Large Number is handy.

CT03
What is the probability that there are more than 60 Heads out of tossing 100 coins?
CT03 - Answer:
The last thing you want to do is to calculate the binomial coefficients explicitly. Instead, observe that the probability distribution converges to a Gaussian as number of trials goes to infinity, with mean equals fifty and variance equals 25 (hence the standard deviation is 5). 60 is two standard deviations away from the mean, and the 68-95-997 rule gives (1 - 95%)/2 = 2.5%.

Another way to ask coin-tossing brainteeasers is to play with Bayesian statistics.

CT04
There are three coins, one with a H side and a T side (coin A); one with both sides being T (coin B); one with both sides being H (coin C).If you draw one among them at random and toss it to observe a Head, what is the conditional probability that coin C is picked?
CT04 - Answer:
This is a typical Bayesian inference question. Let X = [coin C is picked] and Y = [the toss gives an H], then
P(X|Y) = P(Y|X)*P(X)/P(Y) = 1 * (1/3) / (1/3*0 + 1/3*1/2 + 1/3*1) = 2/3

Hope you find this helpful. More to come!

See here for more interview questions/brainteasers

Sunday, October 14, 2012

All those interview questions and brainteasers...

It has been a while since this blog was created. It is intended to be a handy way to look up questions and brainteasers for interview preparation, although from time to time other relevant and interesting stuffs are also discussed.

I have recently once again been looking at a lot of the popular quant interview questions, and an idea comes to mind: perhaps it is worthwhile to re-do some posts in a more systemic manner? Instead of listing the questions and answers out, maybe a discussion of the brainteasers according to their solution technique would bring about more benefits?

It is with this spirit that I embark on this little project. In the following number of posts I would try to group different interview questions into categories and discuss them in more detail, especially how one should approach and attack them. You would find that all previous interview questions/brainteasers posts are now linked here; those posts would remain where they are, so you can think of this post as an overview or introduction.

Where to find more interview questions and brainteasers?
There are two popular printed books that are used extensively in interviews:
A Practical Guide To Quantitative Finance Interviews by Zhou, and
Heard on The Street: Quantitative Questions from Wall Street Job Interviews by Crack
Also, Frequently Asked Questions in Quantitative Finance by Wilmott has a relatively short section on brainteasers, although it is a compilation of materials available on his awesome website (see below). Quant Job Interview Questions And Answers by Joshi et al seems to be a good source too, though I have not read it myself.

Apart from printed books, there is an abundance of resource on the internet. The brainteaser section on the forum of Wilmott.com often has some original questions. Sites such as Braingle and Brainden are dedicated to brainteasers, although those might not be the ones that usually show up during interviews. For those looking for real challenges, wu :: forums should be able to keep you busy.

Finally, if you search the site Glassdoor for a particular company, there will be a bunch of questions that are submitted by those who have interviewed with the firm, with attempts to answer the questions (the quality of which can vary). If you can read Chinese, mitbbs.com has more questions that have actually been asked by interviewers (usually banks).

What should I expect?
Some brainteasers don't really require lengthy calculation. It takes a very specific 'Eureka' moment to be answered. It's fair to say that you won't know the answer if you haven't seen it before. And in case you wonder, yes, such questions do show up at interviews.

Otherwise, the majority of the questions does require calculation. When you are practising, don't just memorize the answer (that's obvious). Think about 1) why the answer is what it is; 2) whether there are alternative, shorter and sweeter ways to solve it; and 3) if the question could have been altered or extended. One thing that I find especially useful is to verify the answers using simulations. That not only assures you of correctness, but also gives you some intuition, as well as a handy way to play with different parameters and assumptinos.

So, here we go:

The series
Those damn coins... 
Those damn coins... (Part II) 
Those damn coins... (Part III)
More Coin Problems
Those damn dice...  
Those damn dice... (Part II) 
Those damn cards...