You are on page 1of 6

15-251 Quiz 3 Page 1 of 6

15-251: GTI Quiz 3 Solutions


NOTE: There were three different version of this quiz (differing in the order of the T/F
questions and some of the specific numbers used in certain questions).

Repeat After Me.


This part is to test your ability to study material that has been labeled as likely
to appear on exams. If you do not do well on this section, your study habits
could use adjustment.

1. [30 points]
For each of the following, circle either true or false (2 pts each).

a. F “Random variable” and “Event” mean the same thing.


b. F A random variable is a subset of the sample space.
c. T For any two random variables X and Y , E[X + Y ] = E[X] + E[Y ].
d. F For any two random variables X and Y , E[X ∗ Y ] = E[X] ∗ E[Y ].
e. T If x, y ∈ Zn∗ and x 6≡ y(mod n), then x−1 6≡ y −1 (mod n).
f. F If a ≡ b (mod n), and x ∈ Zn∗ , then xa ≡ xb (mod n).
g. T For any n > 1, n and 3n + 1 are relatively prime.
h. T The set of all pairs of integers {(a, b) : a, b ∈ Z} is countable.
i. T The set of all pairs of rationals is countable.
j. F The set of all pairs of reals is countable.
k. T The set of all Java programs is countable.
l. F Suppose P is a program that, when run, prints out program Q. Then
it must be the case that Q is a shorter program than P.
m. F There exists a program P that given the text of any program Q as
input, can correctly output whether or not Q halts.
n. T There exists a program P that can list all programs Q that halt. That
is, this list should include all and only those programs Q that halt.
o. F There are only two different infinities.
15-251 Quiz 3 Page 2 of 6

Reading Solutions.
This section tests whether you read the homework solutions that we hand out.

2. [10 points]
Suppose we have a probability distribution over n symbols s1 , s2 , . . . sn , where each proba-
bility is of the form 1/2j for some positive integer j. (Assume n > 1.) For example, we
might have the alphabet {a, b, c, d} with probability distribution p(a) = 1/4, p(b) = 1/8,
p(c) = 1/8, and p(d) = 1/2.
As you learned in 15-211, the Huffman-code algorithm produces prefix-free codes. It takes
the two symbols of lowest probability and makes them siblings. Then, it chooses to view the
two symbols together as a single symbol whose probability is the sum of the two constituent
probabilities. Lastly, it recursively computes a Huffman tree on the remaining alphabet of
size n − 1.

Prove by induction that, given a probability distribution of the above form, the Huffman-
code algorithm will produce a tree in which a symbol of probability 1/2j is at depth exactly
j. (Equivalently, the code for a symbol of probability 1/2j is a string of length j).

You may assume that for any distribution of this form, the symbol of lowest probability does
not occur alone; there must be some other symbol of the lowest probability.
What we were looking for here was something that conveyed the important information:
Induction on n, the number of symbols in the distribution.
Base case: n = 1. There is one symbol with probability 1/20 at depth 0.
Inductive Hypothesis: Assume that there is a distribution of the given form of size n, then a
symbol of probability 1/2j is at depth j.
Inductive Step: Given a distribution of size n + 1, the algorithm combines the smallest two
probabilities (we’re given that there must be two of them). Let them be a and b, each with
probability 1/2j . When combined, they form a node of probability 1/2j−1 . We can apply the IH
to this distribution now (it is of size n), and we get a tree where the node ab is at depth j − 1.
Thus a and b are at depth j.
15-251 Quiz 3 Page 3 of 6

Basic Techniques.
This part will test your ability to apply techniques that we have explicitly iden-
tified in lecture. You need to have practiced each technique enough to be able
to handle small variations in the problems. You do not need to reduce factorials
and binomial coefficients to a numeric answer.
3. [13 points]
Diana Unger can’t remember the secret code to open her lunch box. It’s a number between
0 and 6, but trial-and-error is no good because entering the wrong thing will cause her soda
to self-destruct, turning her lunch into a soggy mess. Luckily, she has shared her secret with
two friends Tom and Ray using Shamir’s secret-sharing scheme. Tom has f (2) and Ray has
f (3), where f is a degree-1 polynomial mod 7.
She asks her friends and finds that Tom has 5 and Ray has 2. Solve for f (0) and help Diana
recover the secret lunch code. Note: you do not need to use the generic method from class
but you should show your work.
Solution: There are several ways to solve this problem. The simplest is to notice that since f is
a linear function, the slope of this function must be f (3) − f (2) = −3 mod 7. So, this means
that f (1) = f (2) + 3 ≡ 1 mod 7 and f (0) = f (1) + 3 ≡ 4 mod 7. So, we find that the secret
lunch code is 4.
15-251 Quiz 3 Page 4 of 6

4. [12 points]
Consider the sample space of two fair coin flips. For each of the following, give an example
using events within the sample space. Also, very briefly, explain why your example has the
desired property.

(a) Two independent events.


The event that the first coin is heads, and the event that the second coin is heads are
independent. Each has probability 1/2 and the probability they both happen is 1/4.

(b) Two events that are not independent.


The event that the first coin is heads, and the event that the first coin is tails are not
independent. Each has probability 1/2, but the probability they both happen is 0.

(c) Two independent random variables.


The indicator RV for the first coin being heads, and the indicator RV for the second coin
being heads are independent. That is because the event that the first RV takes on some
value a, and the event that the second RV takes on some value b are independent for all
a, b.

(d) Two random variables that are not independent.


If X is the indicator RV for the first coin, and Y = 1 − X, then X and Y are not
independent since Pr(X = 1 ∧ Y = 1) = 0.
15-251 Quiz 3 Page 5 of 6

5. [15 points]
Show, using diagonalization, that the set of real numbers in [0,1] whose decimal expansion
has the property that every digit is a prime number (2,3,5, or 7) is uncountable. (For exam-
ple, 0.2375 . . . and 0.55555 . . . are in the set, but 0.145 . . . and 0.303 . . . are not.) Specifically,

A. Assume this set is countable and therefore it can be placed in a list L. Given L, show
how you could define a number called Confuse.
Define confuse to be the real number such that confusei is a prime not equal to the ith digit of
the ith element of L. There will always be at least one choice. Notice that confuse satisfies the
condition of having every digit be a prime number.
B. Show that confuse is not in L.
If confuse were in L, then it would have to be in some position i. But it cannot be there, becuase
by definition, confusei is different from the ith digit of that number.
C. Explain why confuse not being in L implies the set is not countable.
If the set were countable, then it would be possible to define a set L with all of its elements. But
we have just shown that for any possible such list L, there is some element it misses. Therefore,
the set must not be countable.
15-251 Quiz 3 Page 6 of 6

A Moment’s Thought!
This section tests your ability to think a little bit more insightfully.

6. [20 points]
Suppose I have a deck with p − 1 cards, where p is prime. Assume the cards are all sorted.
Now, I “shuffle” the deck once by picking a random number a ∈ Zp∗ and then rearranging
the deck so that the card that was in position i is now in position ia mod p. So, the first
card is now in position a, the second card is now in position 2a mod p, and so on.

(a) True or False: this is guaranteed to be a “legal” shuffle in that no two cards are being
asked to go to the same position.
True

(b) True or False: some cards are more likely to end up in position 1 than others.
False: for any position, each card has exactly a 1/(p − 1) chance of ending there. For
example, card i ends in position 1 exactly when a = i−1 mod p

(c) True or False: some cards are more likely to end up in position p − 1 than others.
False: for any position, each card has exactly a 1/(p − 1) chance of ending there. For
example, card i ends in position p − 1 exactly when a = (p − 1)i−1 mod p

(d) True or False: all (p−1)! permutations of the cards are equally likely under this scheme.
False: this scheme can only produce p − 1 different permutations (one for each value of a).

(e) What is the probability that no card ends up in the same position as it started? Why?
p−2
If a 6= 1 then no card ends up in the same position as it started, so the probability is p−1
.

(f) What is the expected number of cards that end up in the same position as they started?
Why?
There are two ways to solve this. One is to notice that if a = 1 then all cards end up
where they started, and if a 6= 1 then none of the cards end up where they started, so the
expected number is 1. Another way to solve it is that for each card, there is a 1/(p − 1)
chance that it ends where it started (since this happens iff a = 1), and so by linearity of
expectation, the expected number than end where they started is 1.

You might also like