You are on page 1of 6

Technische Universitt Mnchen WiSe 2011/12

Fakultt fr Informatik Solution for Exercise Sheet 8


Dr. Tobias Lasser
Richard Brosig, Jakob Vogel
January 17, 2012
Exercises in Basic Mathematical Tools
Assignment 1 Calculation Rules for Probabilities (Exemplary Solution)
Given two sets A, B and a probability space (, F , P) the following properties holds
(P1) P(A) 0 for all A F
(P2) P() = 1
(P3) P(

i=1
A
i
) =

i=1
P(A
i
) if A
i
A
j
= / 0 for i = j
(I) Two events A and B are independent if
P(AB) = P(A)P(B).
Show the following properties:
a) The probability of the complementary event

A := \A is P(

A) = 1P(A)
P()
A

A=
= P(A

A)
(P3), A

A=/ 0
= P(A) +P(

A) = 1
P(

A) = 1P(A)
b) P(AB) = P(A) +P(B) P(AB)
P(AB) = P(A(B\A)) A(B\A) = / 0 (P3)
= P(A) +P(B\A) a)
= P(A) +1P(B\A)
= P(A) +1P((\B) (AB)) (\B) (AB) = / 0 (P3)
= P(A) +1(P(\B) +P(AB)) a)
= P(A) +1((1P(B)) +P(AB))
= P(A) +P(B) P(AB)
c) P(AB) = P(A|B)P(B) = P(B|A)P(A)
This is the denition of the conditional probability.
Solution 8/ page 2
d) If A and B are independent, then

A and B are also independent.
P(

A)P(B) = (1P(A))P(B) a)
= P(B) P(A)P(B) A and B are independet
= P(B) P(AB) b)
= P(B) (P(A) +P(B) P(AB))
=P(A) +P(AB))
=P(A) +P((

AB) A)
=P(A) +P(

AB) +P(A)) (

AB) A = / 0 (P3)
= P(

AB)
e) Bayes Theorem: P(A|B) P(B) = P(B|A) P(A)
P(A|B) P(B) = P(AB) = P(BA) = P(B|A)P(A)
Assignment 2 Probabilities (Exemplary Solution)
a) Compute the probability p
40
that at least two persons in a lecture room with 40 persons have
their birthday on the same day in a year (365 days). Assume that the birthdays are equally
distributed over the year.
P(There are at least two persons having birthday on the same day.)
= 1P(No Person has birthday on another persons birthday.)
= 1
365 364 ... 327 326
365
40
= 1
365!
(36540)! 365
40
0.8912
Afterwards, compute the minimal number n of students such that p
n
> 1/2.
n=0; p=0; temp=1;
while p<0.5
temp=temp*(365-n)/365;
p=1-temp;
n=n+1;
end
The result is n = 23 and p
n
0.5073
b) A random variable X is called exponentially distributed with parameter > 0 if
P(X < x) = 1exp(x).
Given a random variable X with values in [0, ) and a distribution P
X
, the latter is called
memoryless if for all x, t > 0 with P(X > x) > 0
P(X > x +t|X >t) = P(X > x).
Show that the exponential distribution is memoryless.
Solution 8/ page 3
First we have to see that
P(X > x) = 1P(X 0) = exp(x)
P(X > x +t|X >t) =
P(X > x +t, X >t)
P(X >t)
=
P(X > x +t)
P(X >t)
=
exp((x +t))
exp(t)
= exp(x) = P(X > x)
Assignment 3 Combinatorics (Exemplary Solution)
Given are an array with 7 elds and nine different colors (including red, blue and green).
How many different color permutations are possible if...
a) ...you have no restriction?
For no restriction you have 9 possibilities for each of the 7 elds. Therefore we get
9 9 9 9 9 9 9 = 9
7
possibilities.
b) ...every eld has to have a different color?
With this restriction, we have 9 possibilities for the rst eld. For the second eld we are
not allowed to use the color, which is in the rst one, so we have 8 remaining colors. In
the third eld only the colors which are not in eld one and two are allowed, so we have to
choose one out of 7. This leads to
9 8 7 6 5 4 3 =
9!
(97)!
possibilities. (! denotes the factorial)
c) ...neighboring elds have to have a different color?
In this case there is no restriction to the rst eld of the array. So you can choose between
all 9 colors. The second eld of the array can also have all colors, except the color of the
rst on. So you are only allowed to choose between 8 colors. And so on...
9 8 8 8 8 8 8 = 9 8
6
d) ...the rst and the last eld need to be red?
If you set the rst and the last eld to red, you are in the same case as in exercise (a), with
only 5 instead of 7 array elds. This leads to
9
5
possibilities.
e) ...3 elds are required to be red, 2 blue, and the rest green?
We start to allocate the colors to the array elds.
Starting with the three red elds, we have 7 possibilities for the rst red eld, 6 for the
second and 5 for the third. Since we cannot distinguish the red colored elds from each
Solution 8/ page 4
other, we have to divide this through all permutations. In the case of 3 items we have
3 2 1 = 3! permutations, and we get
7 6 5
3!
=
7!
3!(73)!
=:

7
3

= 35
possible distributions.
For the 2 blue elds we have four array elds left, so we get
4 3
2!
=
4!
2!(42)!
=:

4
2

= 6
The for the rest we have 2 elds left and we have to choose all two elds, so we get

2
2

= 1
Together we have

7
3

4
2

2
2

= 35 6 1 = 210
different possible orderings.
The term

n
k

:=
n!
k!(nk)!
used above is called binomial coefcient and models, among other things, the drawing of
balls out of an urn without returning them. This is often read as n choose k.
f) ...3 neighboring elds are red, the other elds are arbitrary?
Here we have ve possibilities for the arrangement of the 3 red elds. The remaining 4 elds
can be colored arbitrary. So we have
5 9
4
congurations.
Assignment 4 1D Random walk, Markov chain (Exemplary Solution)
a) Find a recursive formulation for the probability p
k
:= P(A
k
) (with A
k
denoting the event
The gambler has k$, and wins the game).
Starting with k Dollars there are two different cases. First, the ball falls on a red number.
In this case his chance to win K$ would be the same as he would start with k +1 Dollars.
In the second case the ball falls on a green or black number. In this case the his chance to
win is the same as he would start with k 1 Dollar.
P(A
k
) = P(A
k+1
)P(red) +P(A
k1
)(1P(red))
= p
k+1
p+ p
k1
(1p) (1)
b) What are the boundary conditions for p
K
and p
0
?
The game stops as soon as the gambler has won K$ or if he is bankrupt. In the rst case,
we have
p
K
= 1.
In words: If the gambler has K Dollars, he wins with a chance of 100% (because he will stop
playing). In the second possibility when the game stops, would be the ruin of the gambler
p
0
= 0.
With no money, there is also no chance to win.
Solution 8/ page 5
c) Try to nd an iterative method to solve this problem?
We can model this problem as a Markov chain. Here we have a nite set of states (k =0...K).
In this case we can compute a transition matrix P and a state vector .
Having k$, for example, is modeled by the state vector = e
k
[0, 1]
K+1
(The gambler
has, with a probability of 100%, this amout of money.) After each game the distribution
is changed. This is modeled by the transition matrix. Multiplying a state vector with the
transition matrix gives the a new state vector with the distribution after another turn of
roulette.
For a correct model of a Markov chain some requirements has to be met by P and :
(i) All elements p
i j
and
i
have to be equal to, or larger than 0. (probabilities are between
0 and 1)
(ii) The sum of all elements of has to be 1. (P() = 1)
(iii) The sum of all rows of P has to be 1 (stochastic matrix, requirement (ii) has to be valid
after the multiplication with P)
Given formula (1), the probability p
k
of the state k$ depends only on the probabilities p
k+1
and p
k1
. For the transition matrix P [0, 1]
K+1K+1
we get
p
i j
=

p if j = i +1 and 1 < i < K


1p if j = i 1 and 2 < i < K+1
1 if j = i = K+1
1 if j = i = 1
0 else
The third and the fourth case are modeling the end of the game, since columns with a 1 in
the diagonal and 0 elsewhere are modeling a sink (e

1
= e

1
P). Each time the gambler bets
on red, the current state has to be multiplied with the transition matrix.

n+1

n
P
Starting with the state = e
k
(The gambler has k$.) and iterating until the iteration
converges (if it does) will give us the probability Starting with k$, the gambler wins. as
the last element of the state vector

.
To compute all probabilities p
k
, k = 0...K, we can compute

n+1
=
n
P
with
0
=I where I denotes the (K+1)-dimensional identity. Since we need the last column
of the matrix only, we have
p
k,all
= IP

e
K+1
= P

e
K+1
p=18/37; K=20; k=10;
%% assemble the transition matrix
P=p
*
diag(ones(1,K),1)+(1-p)
*
diag(ones(1,K),-1);
P(1,1)=1;P(1,2)=0; P(end,end)=1; P(end,end-1)=0;
%% generate initial state
Solution 8/ page 6
pi=zeros(1,21);
pi(k)=1;
for i=1:10000
pi=pi
*
P;
end
pi
% OR
p_k_all=[zeros(K,1);1];
for i=1:10000
p_k_all=P
*
p_k_all;
end
p_k_all

You might also like