Download HW 3 Solutions - Duke Computer Science

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Statistics wikipedia , lookup

History of statistics wikipedia , lookup

Inductive probability wikipedia , lookup

Randomness wikipedia , lookup

Birthday problem wikipedia , lookup

Ars Conjectandi wikipedia , lookup

Probability interpretations wikipedia , lookup

Probability wikipedia , lookup

Transcript
CompSci 102 Discrete Mathematics for CS
Spring 2005
HW 3 Solutions
Forbes
Due Wednesday, April 6 in class
1. (36 pts.)
Book Problems
(a) We might as well assume the first person sits in the northernmost seat. Then there
are P(5,5) ways to seat the remaining people, since they form a permutation reading
clockwise from the first person. Therefore, the answer is 5! = 120.
(b) We determine whether two events E1 and E2 are independent by determining if
Pr[E1 ∩ E2 ] = Pr[E1 ] Pr[E2 ].
a) Intuitively, these events should be independent, since the first event seems to have
no influence on the second. In fact, we can compute as follows. First Pr[E1 ] = 1/2
and Pr[E2 ] = 1/2 by the symmetry of coin tossing. Furthermore E1 ∩ E2 is the event
that the first two coins come up tails and heads, respectively. Since there are four
equally likely outcomes for the first two coins (HH, HT, T H, T T ), Pr[E1 ∩ E2 ] =
1/4 = 1/2 · 1/2 = Pr[E1 ] Pr[E2 ] = 1/4, so the events are indeed independent.
b) Again Pr[E1 ] = 1/2. For E2 , not that there are 8 equally likely outcomes for the three
coins, and in 2 of these cases E2 occurs (HHT, T HH); therefore Pr[E2 ] = 2/8 = 1/4.
Thus, Pr[E1 ] Pr[E2 ] = 1/8. Now E1 ∩E2 is the event that the first coin comes up tails,
and two but not three heads come up in a row. This event occurs when the outcome
is T HH, so the probability is 1/8 = Pr[E1 ] Pr[E2 ], so the events are independent.
c) As in part b, Pr[E1 ] = 1/2 and Pr[E2 ] = 1/4. This time, Pr[E1 ∩ E2 ] = 0 since
there is no way to get two heads in a row if the second coin comes up tails. Since
Pr[E1 ∩ E2 ] = 0 6== 1/8 = Pr[E1 ] Pr[E2 ], the events are not independent.
(c) We assume that n is much greater than k, since otherwise, we could simply compare
each element with its successor in the list and know for sure whether the list is sorted.
We choose two distinct random integers i, j in the range of 1 to n. We then compare the
ith and jth elements of the given list; if there are correct order relatively to each order,
we answer “unknown” at this step and proceed. If not, then we answer “true” (i.e., the
list is not sorted) and halt. We repeat this process for k steps (or until we have found
elements out of order), choosing new random indices each time.
In a random list, the probability that two randomly chosen events are in the correct
relative order is 1/2. Therefore, the probability that we wrongly answer “false” (the list
is sorted) will be about 1/2k if the list is a random permutation and not actually sorted.
If k is large, this will be very small. For example, if k = 100, then this probability will
be less than one chance in 1030 .
(d) Let xi be the number of comparisons used by quick sort for the ith permutation.
a) Each of the n! permutations occurs with probability 1/n! so E[X] =
is the average of comparisons.
1
P
1/n · xi which
b) The summation considers each unordered pair (j, k) once and contributes a 1 if the
jth smallest element and the kth smallest element are compared (and contributes 0
otherwise). Therefore, the summation counts the number of comparisons, which is
the definition of X. Note that by the way the algorithm works, the pivot element is
put between the two sublists, so it is never compared with any other elements after
that round is finished.
c) Take the expectation of both sides of the equation in part b. By linearity expectation
we have
E[X] =
n X
X
j = 1n−1 E[Ij,k ],
k=2
and we have E[Ij,k ] is the stated probability by the expected value of Bernoulli trials
(Theorem 2 in 5.3) where n = 1.
d) Prove p = 2/(k − j + 1) using strong induction on n, the number of elements
• Base case: It is true when n = 2, since in this case, the two elements are indeed
compared once and 2/(k − j + 1) = 2/(2 − 1 + 1) = 1.
• Assume p = 2/(k − j + 1) for all lists of size ≤ n. Consider the first round of quick
sort and let the pivot (element in the first position) be the ith smallest element.
You then have the following possible cases
i. If j < i < k, then the jth smallest element gets put into the first sublist and
the kth smallest element gets put in the second sublist, so these two elements
will never be compared. The probability of this case is (k − j − 1)/n for a
random permutation
ii. If i = j or i = k, then the jth smallest element and the kth smallest element
will be compared this round. This case happens with probability 2/n.
iii. If i < j, then both the jth and kth smallest elements get put in the second
sublist and so by induction, the probability that they will be 2/(k − j + 1) .
The probability of this case is (j − 1)/n.
iv. If i > j, the reasoning is similar to the case and the probability of this case is
(n − k)/n.
The probability of the desired comparison is then:
k−j−1
2
2
j−1 n−k
0·
+1· +
·
+
,
n
n k−j+1
n
n
which simplifies to 2/k − j + 1 as desired.
e) From the previous two parts, we need to prove that
n k−1
X
X
k=2 j=1
n
X
1
2
= 2(n + 1)
− 2(n − 1).
k−j+1
i
i=2
This proof can be done, painfully, by induction.
f) This result follows immediately from the previous two parts.
2. (10+5 pts.)
Monty Hall
Construct a sample space of possible outcomes consisting of all 4-tuples (i, j, k, l), where i is
the location of the prize, jj is the first door chosen by the contestant, k is the door opened by
the assistant, and l is the final door chosen by the contestant. Define the following random
variables:
CompSci 102, Spring 2005, HW 3 Solutions
2
• A: the door the prize is behind. Assume the prize is equally likely to be behind any of
the n doors
• B: the door the contestant chooses. Assume the contestant chooses a door at random
(i.e. all have probability 1/n).
• C: the door Monty chooses. Assume Monty chooses one of the non-prize doors at random
• D: the door the contestant chooses. Assume if the contestant decides to switch, he or
she chooses randomly from one of the remaining doors
(a) Under the sticking strategy, l = j. In this case, we win only for sample points of the
form (i, i, k, i) where k 6= i. The probability of each sample point is:
Pr[A = i] Pr [B = j] Pr [C = k] =
1
1
1
1
× ×
= 2
n n n−1
n (n − 1)
The number of ways to choose i is n, and k can be chosen in (n − 1) ways. Therefore,
the chance of winning is n(n − 1) × 1/(n2 (n − 1)) = 1/n.
Under the switching strategy, we win only on (i, j, k, i), where j 6= i and k 6= i. The
probability of each outcome is
Pr[A = i] Pr[B = j] Pr[C = k] Pr[D = l] =
1
1
1
1
1
× ×
=
.
n n n−2n−2
(n(n − 2))2
There are n ways to pick i, (n − 1) to pick j and (n − 2) ways to pick k, so the total
chance is n ∗ (n − 1)(n − 2)/(n(n − 2))2 = (n − 1)/(n(n − 2)).
Another way to arrive at this result is using conditioning. Let X be the event that
we do not pick the correct prize door initially and Y be the event that we do pick the
correct door with our second pick. Note that with probability 1/n, we pick the prize
door initially, in which case we never win by switching. In the other case (X) we did not
pick correctly initially and that happens with probability (n − 1)/n, and we then pick
the unique prize door (Y |X) with probability 1/(n − 2).
Pr[X ∩ Y ] = Pr[Y |X] Pr[X] =
n−1
n(n − 2)
(b) An a analysis similar ot the above shows that if there are m prizes and n doors, then
the chance of winning by switching is
m m−1
m
m
m(n − 1)
×
+ (1 − ) ×
=
.
n
n−2
n
n−2
n(n − 2)
You can show this using the conditioning method in a straightforward manner. Using
the sample-space enumeration method, the sample points are now of the form (S, j, k, l),
where S is the set of m prize doors and j, k, l, are as before. You will then consider two
cases, when door j is in S and when it is not. Combining these two solutions gives you
the same solution as above.
3. (20 pts.)
A paradox in conditional probability?
(a) For airline A, the chance of it arriving on time into San Diego is 453/500 = 0.906, while
for Airline B, it is 188/200 = 0.94. For arrivals on time into Chicago, the probabilities
are 211/300 = 0.703 and 685/900 = 0.761.
CompSci 102, Spring 2005, HW 3 Solutions
3
(b) For Airline A, the chance of arriving on time overall is (453 + 211)/500 + 300) = 0.83
while for Airline B it is 0.7936.
(c) The apparent paradox is that even though Airline A has a worse chance of arriving on
time to Airline B when looking at any single airport (part (a)), it is much better than
Airline B when we look at all flights (part (b)).
To explain this paradox, look the event that a plain is on time. The probability of this
event is:
Pr[on-time] = P r[on-time|Chicago] · Pr[Chicago] +
Pr[on-time|San Diego] · Pr[San Diego]
Thus, the fact, that B has a better on-time record at Chicago is undermined that most
of its flights are to Chicago, were the arrivals are less likely to be on time than at San
Diego.
4. (20 pts.)
Happy families
(a) Let there be n families, with each of the possible combinations of boys and girls. Let b
denote the event that a randomly chosen family has at least one boy, and BB be the
event that both children are boys. Therefore, we can compute the probabilities of each
event as below:
Pr[B] = 3n/4n = 3/4
Pr[BB] = n/4n = 1/4
Hence Pr[BB|B] = Pr[BB ∩ B] Pr[B] = Pr[BB]/ Pr[B], since BB ⊆ B. Thus the
conditional probability is 1/3.
(b) In this case, we will be picking uniformly from the 8n children, and since there are 4n
boys, we will pick a boy with probability Pr[B] = 4n/8n = 1/2. However, we will
have picked a boy whose sibling is also a boy with probability Pr[BB] = 2n/8n = 1/4,
and hence the chance Pr[BB|B] = 1/4
1/2 = 1/2.
(c) The difference in the wo cases comes because of the different sample spaces. In the
first case, when we are informed that the chosen family has at least one boy, we restrict
ourselves to a sample space of 3n families, and a third of these are good, since we are
not favoring any of the types of families.
However, in the second case, when we pick a child, and it turns out to be a boy, we
are favoring families with two boys, since we increase the chances that a child from this
family will get picked (recall that we are conditioning on the event that the child picked
is a boy). Thus, the chance in the second case is larger than in the first.
5. (14 pts.)
Independence
(a) Note that the event A has the sample points (possible outcomes) (1, i), (3, i), (5, i)
∀ i, 1 ≤ i ≤ 6. Thus, Pr[A] = |A|/36 = 1/2. By symmetry, Pr[B] == 1/2 as
well. For C, the sample points are (1, i), (3, i), (5, i) for even i and (2, i), (4, i), (6, i) for
odd i which gives us that |C| = 18, and Pr[C] = 1/2 as well.
The event A ∩ B has the points (1, i), (3, i), (5, i) for odd i and thus Pr[A ∩ B] = 9/36 =
Pr[A] Pr[B]. The event B ∩ C has the sample points (2, i), (4, i), (6, i) for odd i which
implies that Pr[B ∩ C] = 9/36 = Pr[B] Pr[C] and hence B and C are independent.
Finally, A ∩ C has the points (1, i), (3, i), (5, i) for even i and thus |A ∩ C|/36 = 1/4 =
Pr[A] Pr[C] as well. Thus, each pair of events is independent of each other.
CompSci 102, Spring 2005, HW 3 Solutions
4
(b) However, A ∩ B ∩ C = ∅, since if both die are odd, then their sum is even. Thus
Pr[A ∩ B ∩ C] = 0 6= Pr[A] Pr[B] Pr[C], which implies that they are not mutually
independent.
CompSci 102, Spring 2005, HW 3 Solutions
5