Probability Problems 04
Table of Contents
Consecutive two heads after kth
Here, we want the probability that the sequence exactly ends at 10th tosses. So this equally means that the coin tosses have to be ended by $THH$. What about the previous 7 tosses? They are just $F(7)$, any possible sequences that doesn’t have $HH$.
$F(7)=34$. So the probability is $34/2^{10}=17/512$.
Waiting for a larger number
Waiting for all six outcomes
The first time you roll a die, you are guaranteed to receive a different number.
Then the second time, only probabilty of $5/6$ to get with an expected number of $6/5$.
Overall, you have $6\times(1+\frac{1}{5}+\frac{1}{4}+…++\frac{1}{6})$ expected number of times to get all the outcomes.
Waiting for an Ace
Waiting for multiple heads
1. What is the expected number of flips before getting three heads for the first time?
2. What is the expected number of flips before getting four heads for the first time?
Thus, for a single head, you expect $1/p$ tosses due to the geometric distribution. So for $m$ tosses, you expect $m/p$ number of tosses.
No consecutive n heads
def possiblesequence(n: int, k:int):
res = list()
def backtrack(idx, comb):
if len(comb) == n:
res.append("".join(comb))
if len(comb) > n:
return
backtrack(idx + 1, comb + ["H"])
backtrack(idx + 1, comb + ["T"])
backtrack(0, [])
count = 0
for seq in res:
if "H"*k not in seq:
count += 1
print("Toss a coin {0} times:".format(n))
print("No Consequtive {0} heads : {1}".format(k, count))
print("Total Possibilities: {0}".format(2**n))
# return count
Uniform Sum Smaller than t
Prove by induction the more general result: If $0 \leq t \leq 1$, then $$ P\left(S_n \leq t\right)=\frac{t^n}{n !}, $$ where $S_n$ denotes the sum $X_1+\cdots+X_n$. The base case $n=1$ is clear. If holds for $n$, then calculate for $0 \leq t \leq 1$ : $$ P\left(S_{n+1} \leq t\right)=\int_0^1 P\left(S_n+x \leq t\right) f(x) d x \stackrel{(1)}{=} \int_0^t \frac{(t-x)^n}{n !} d x=\frac{t^{n+1}}{(n+1) !} $$
Uniforms Sum Greater than 1
Draw numbers until get 0
The answer is $1+\frac{1}{2}+\frac{1}{3}+\dots+\frac{1}{N}$. Can be proved using recursion.
Variance of the first n natural numbers
The mean is simple, which is$\frac{n+1}{2}$. While the variance you need to mean for squared sum.
$$ \begin{gathered} \operatorname{Var}(Y)=\frac{1}{n} \cdot\left(\sum_{i=1}^n i^2\right)-\left(\frac{1}{n} \cdot\left(\sum_{i=1}^n i\right)\right)^2 \\ \operatorname{Var}(Y)=\frac{1}{n} \cdot \frac{n \cdot(n+1) \cdot(2 n+1)}{6}-\frac{(n+1)^2}{4} \end{gathered} $$Which you can then simplified as $\frac{n^2-1}{12}$.
Seen both marbles at least once
After four draws from the bag what is the probability that you have seen both the red and green marbles at least once?
def f():
res = list()
def backtrack(idx, comb):
if idx == 4:
res.append(comb)
return
else:
for i in range(1, 6):
backtrack(idx + 1, comb + str(i))
backtrack(0, "")
return res
a = f()
count = 0
for s in a:
if list(s).count('1') >= 1 and list(s).count('2') >= 1:
count += 1
print(count)
print(count / 5**4)
Total outcomes is $5^4=625$. Consider outcomes that have no green, or no red marbles, which is $2\times4^4=512$ outcomes. But these two cases have overlap outcomes when neither of the colors are included (that is when the four draws are all from the other three colors), thus we need to add back $3^4$ outcomes.
Overall, we have $5^4-2\times4^4+3^4=194$ outcomes meet our criteria.
Combination of coins
How many different combinations of these coins (not their values) can you make?
In this case, we have $5+4-1=8$ choose $4-1=3$, which is $56$.
Number of Paths I
Not matter the sequence of steps, you need $7$ steps in total. And of these steps, you need $3$ steps down and $4$ steps to the right. This is just a combination problem where you can choose $3/4$ from $7$ spots. Thus the answer is $7$ choose $3$.
Number of Paths II
There is no closed form formula for this, see answers here.
But there are two things to notice:
- when $n=3$, the answer is $2$.
- When $n$ is even, then the answer is $0$. Why? Think about the black and white checkboard argument where adjunct squares always have different colors. The colors on opposite corners are the same. But to pass every square only once, you have to take $n^2-1$ steps, which is odd. So you must end up with an opposite color. That’s why you can never reach the opposite corner.
Number Sequence
Take a rest, I know this is a boring problem. If you notice the first few prime numbers are $2,3,5,7,11,13$, and add $+1$ for odd terms and $-1$ to the even terms then you get the answer. The next should be $18$.