CSE 21 Spring 2016 Homework 8 Solutions Required Reading

CSE 21 Spring 2016
Homework 8 Solutions
Required Reading Rosen 7.1 through 7.4
Key Concepts basic probability principles, independence, conditional probability, expected
value, conditional expectation, linearity of expectation, variance and concentration, Bayes’
Theorem
1
1. (2 points each part)
(a) If I roll one standard cube die, generating a random number from 1 to 6, what is its expecation?
Since each number from 1 to 6 is equally likely , the expected number of pips is 1(1/6) + 2(1/6) +
3(1/6) + 4(1/6) + 5(1/6) + 6(1/6) = (7 ∗ 6/2)(1/6) = 3.5
(b) What is its variance? The absolute value of the difference between that value and 3.5 is equally
likely to be 2.5 (1 and 6), 1.5 (2 and 5) , and .5 (3 and 4), so the square is equally likely to be
6.25, 2.25 and .25, for an average of (35/12) = 2 11/12.
(c) If I sum up k such dice, what is the expected sum? By linearity of expectations, the expectation
of the sum is the sum of the expectations, and by the above, each die contributes 3.5 on average
to the sum, so the overlal expectation is 3.5k.
(d) If I multiply k such dice, what is the expectation of the product? Since the dice are thrown independently, the expectation of the product is the product of the expectations, and each contributes
a factor of 3.5, so 3.5k is the expected value of the product.
(e) What is the variance of the sum of k dice? Again, since they are independent , the variance of
the sum is the sum of the variances for a total of (35/12) ∗ k.
2. In a variant of the game Plinko from the gameshow The Price is Right, the player has one disk which
they insert into the top of the board shown below. Each time the disk hits a peg (shown as a black
circle), it has a 50% chance of falling to the left, and a 50% chance of falling to the right. Eventually,
the disk lands in one of the bins at the bottom of the board. Each bin is marked with a dollar amount,
and the player wins the amount of money shown on the bin in which the disk lands.
$500
$100
$50
$50
$100
$500
(a) (3 points) Suppose that bin 1 is the leftmost bin, and bins are numbered from 1 to 6 reading from
left to right. In terms of i, find a formula for the probability that the disk falls into bin i.
Solution: Since every path to a bin requires 5 left or right moves, the bin number in which the
disk lands depends upon how many of those moves are left moves and how many are right moves.
To land in bin i, the disk must make i − 1 right moves, and the rest left
moves. The number of
5
ways to select these i − 1 right moves out of the 5 total moves is i−1
, so the number of paths
5
to bin i is i−1 . The number of possible paths to any bin is given by 25 = 32 since there are 2
choices at each of 5 pegs. Since each of these 32 paths is equally likely, the probability that the
disk falls into bin i is given by the binomial distribution
5
P (disk falls into bin i) =
i−1
32
.
(b) (3 points) How much money does the player expect to win at this game?
Solution: Using the formula for expected value with the probabilites from part (a) gives
2
1
5
10
10
5
1
∗ 500 +
∗ 100 +
∗ 50 +
∗ 50 +
∗ 100 +
∗ 500 = $93.75.
32
32
32
32
32
32
(c) (3 points) How much money does the player expect to win if you know that the disk falls to the
right the first time it hits a peg?
( 4 )
Solution: Now the conditional probability of the disk falling into bin i is i−2
if i > 1 and 0 if
16
i = 1. The expected value formula gives
4
6
4
1
1
∗ 100 +
∗ 50 +
∗ 50 +
∗ 100 +
∗ 500 = $93.75.
16
16
16
16
16
Note that this is the same as part (a). Since the values on the bins are symmetric from left to
right, knowing that the disk goes right at the first peg does not tell us any additional information
about how much money is expected to be won.
(d) (3 points) How much money does the player expect to win if you know that the disk falls to the
right the first and second time it hits a peg?
( 3 )
if i > 2 and 0 if
Solution: Now the conditional probability of the disk falling into bin i is i−3
8
i = 1 or i = 2. The expected value formula gives
1
3
3
1
∗ 50 + ∗ 50 + ∗ 100 + ∗ 500 = $125.00
8
8
8
8
Note that here the expected value has gone up, since knowing that the disk goes right at the first
two opportunities makes it even more likely to fall in the rightmost bin, which is worth a lot.
3. (5 points) Suppose there are n people assigned to m different tasks. Assume that each person is randomly assigned a task and that for each person, all tasks are equally likely. Use linearity of expectation
to find the expected number of people working on a task alone.
Solution: Let X be the random variable that represents the number of people that are working on a
task alone. The solution is to compute the expected value E(X). Suppose the people are numbered
1, 2, . . . , n. Let Xi be
random variable such that P
Xi = 1 if person
Pthe
Pn i is alone and Xi = 0 otherwise.
n
n
It follows that X = i=1 Xi . Therefore E(X) = E ( i=1 Xi ) = i=1 E(Xi ).
What is the probability that person i is alone? Person i is assigned a certain task and for each other
person there is a m−1
the chance that
m chance that they are doing a different task than person i. So
m−1 n−1
all n − 1 other people are doing a different task than person i is P (Xi = 1) = m
. So we have
m−1 n−1
that the expected value of each Xi is E(Xi ) = m
.
E(X) =
n
X
i=1
E(Xi ) =
n−1
n X
m−1
m
i=1
=n
m−1
m
n−1
.
4. (10 points) Say I have a randomized algorithm for a yes/no problem. Each time I run the algorithm,
I have a 3/4 probability of outputting the correct answer. Use Chebyshev’s inequality to show that if
I run the algorithm 2k + 1 times and output the majority answer, the probability that I output the
wrong answer is at most c/k for some constant c.
Let Xi be the random variable that is one if the i’th run of the algorithm is correct, and 0 otherwise.
Let X = sum2k+1
i=1 Xi be the total number of correct answers. The majority answer is incorrect if and
only if X ≤ k. According to the assumptions in the problem, each Xi is indepently one with probability
3/4. Thus, the expectation of each Xi is 3/4 and the variance of each Xi is 3/4(1/4)2 + 1/4(3/4)2 =
1/4(3/4)(1/4 + 3/4) = 3/16. By linearity of expectations then , E[X] = 3/4(2k + 1) and since the
Xi ’s are independent , V [X] = 3/16(2k + 1). Then P rob[majorityisincorrect] = P rob[X ≤ k] ≤
3
P rob[|X − E[X]| ≥ 3/4(2k + 1) − k > (2k + 1)/4 ]. Chebyshev’s inequality says for any random variable
and any value T , P rob[|Y − E[Y ]| > T ] < V [Y ]/T 2 . So applying this with T = (2k + 1)/4, we get
P rob[majority is incorrect] < 3/16(2k + 1)/((2k + 1)/4)2 = 3/(2k + 1) < 1.5/k So we have shown the
claim in the problem with c = 1.5.
5. (10 points) Give a randomized expected linear-time algorithm using ideal hash functions that determines whether two arrays A[1..n] and B[1..n] are disjoint, i.e., whether no element of A is also an
element of B..
Our algorithm will construct a hash table for the elements of A with chaining to resolve collisions.
We will set the table size m by m = n. We pick an ideal hash function h from elements to {1...m},
and initialize an empty linked list at each location in the hash table. For each element of A, A[I], we
compare A[I] to each element currently in the list at h(A[I]), and continue until we either find A[I] or
reach the end of the list. If A[I] is already in the table, we continue on the next I. If we reach the end
of the list, we append A[I] to the end.
Then we run through all the elements of B, B[J] and compare them to elements in the list at h(B[J]),
which are the list of elements of A that hash to the same location. If we find B[J] on the list, we return
“Not disjoint” and terminate. Otherwise, we continue to the next B[J]. If no B[J] is found, we can
then return “Disjoint”.
Since we only insert elements from A on to any of these lists, we will only return “Not disjoint” if
for some I, J, A[I] = B[J]. Conversely, if B[J] = A[I], then h(B[J]) = h(A[I]), and either A[I] was
inserted on the list h(A[I]) when creating the hash table or it was already there. In either case, it will
be on the list at that location when we search the list for B[J], and so we will return “Not disjoint”.
Thus, we return “not disjoint” if and only if the lists intersect, which is the definition of correctness.
For a fixed h, the algorithm’s time to insert each element I has at most one step where A[I] is found,
at most one step where A[I] is inserted, and a number of steps of searching without finding A[I] equal
to the number of A[I 0 ] 6= A[I] with I 0 < I and h(A[I 0 ]) = h(A[I). Thus, the total time to create the
table is proportional to O(n) + O(number of collisions between distinct elements). As we vary over
random hash functions h, the expected number of collisions is at most C(n, 2) ∗ 1/m = O(n), since
there are C(n, 2) pairs of distinct elements at most, and each collides only with probability 1/m = 1/n
for a random hash function.
Similarly, the time to search for each B[J] is O(1+ the number of A[I] 6= B[J] with h(A[I]) = h(B[J]).
For each J, there are at most n different elements A[I], and each collides with B[J] with probability
1/m = 1/n over the choice of hash function, so the expected time for each B[J[ is O(1 + n/n) = O(1).
Thus,the total expected time is O(n) over both stages of the algorithm.
4