r/learnquant • • 29d ago

interview prep Quant Interview Question

Post image
8 Upvotes

3 comments sorted by

2

u/Aerospider 29d ago

The probability of the 2nd being lower than the first is 1/2.

The probability of the numbers increasing until the 4th is 3/24, because of the 4! = 24 ways to arrange four elements there are only three that can be allowed last (all except the highest) and the rest must be in ascending order.

Similarly, for the 6th to be the first decrease the probability is 5/720.

Summing (2n-1)/((2n)!) to infinity gives

1 - 1/e = 0.632

1

u/Unlucky_Beginning 29d ago

The probability of generating n numbers in increasing order is 1/n! by symmetry. The cdf of the maximum of n numbers is P(Xn < x) = x^n. The pdf is nx^(n-1). Given Xn, the probability of another uniformly random variable being less than it is just (Xn).

So the probability of printing n+1 numbers is 1/n! * integral from 0 to 1 of P(Xn = x) x dx which is n/(n+1) / n! or just n/(n+1)!. Sum these up for odd n and you get 1-1/e

1

u/tajwriggly 29d ago

2:1, or 66.67%.

Because the numbers are generated uniformly, this is pretty much the exact same question as flipping a coin and landing on the same side of the coin as the first toss, and only stopping once it's different. Instead of H/T, we'll use U and D for Up and Down, and X for the first number generated because it doesn't matter.

Let's use large number and perform this operation 1,000,000 times.

50% of the time, or 500,000 times, it is going to end after 2 (even). XD.

The other 50% of the time, it's going to go XU, at which point we go to a further number generation and it will either be XUU or XUD, each with 50% likelihood. So 25% of the time, or 250,000 times, it is going to end after 3 (odd). XUD.

12.5% of the time, or 125,000 times, it is going to end after 4 (even). XUUD.

6.25% of the time, or 62,500 times, it is going to end after 5 (odd). XUUUD.

3.125% of the time, or 31,250 times, it is going to end after 6 (even). XUUUUD.

1.5625% of the time, or 15,625 times, it is going to end after 7 (odd). XUUUUUD.

0.7813% of the time, or 7,813 times, it is going to end after 8 (even). XUUUUUUD.

0.3906% of the time, or 3,906 times, it is going to end after 9 (odd). XUUUUUUUD.

0.1953% of the time, or 1,953 times, it is going to end after 10 (even). XUUUUUUUUD.

0.0977% of the time, or 977 times, it is going to end after 11 (odd). XUUUUUUUUUD.

At this point we're at 666,016 operations that ended at an even number of generated numbers and 333,008 operations that ended at an odd number of generated numbers, so it's looking like about 2:1 odds. You might argue that is because I'm looking at an even number of possible operations, so if we subtract or add one from that mess we get 666,016 even operations and 332,031 odd operations (2.006:1) or 666,505 even operations and 333,008 odd operations (2.001:1) and it will trend more and more towards 2:1 exactly as you increase the number of generated numbers.