Massachusetts Institute of Technology Handout 53 6.042J/18.062J: Mathematics for Computer Science May 11, 2000 Professors David Karger and Nancy Lynch

F’99 Final Quiz Solutions

Problem 1 [18 points] Injections and Cardinality.

(a) [8 points] Let f : D → D be a function from some nonempty set D to itself. In the following propositions, x and y are variables ranging over D, and g is a variable ranging over functions from D to D. Circle all of the propositions that are equivalent to the proposition that f is an injection:

a) x = y ∨ f(x) ≠ f(y)

b) x = y ⟹ f(x) = f(y)

c) x ≠ y ⟹ f(x) ≠ f(y)

d) f(x) = f(y) ⟹ x = y

e) ¬[∃x∃y(x ≠ y ∧ f(x) = f(y))

f) ¬[∃z∀x(f(x) ≠ z)

g) ∃g∀x(g(f(x)) = x)

h) ∃g∀x(f(g(x)) = x)

Solution.

a,c,d,e,g

□

We have proved that the infinite set of real numbers is “strictly bigger” than the infinite set of integers, and the set of integers is “strictly bigger” than any finite set.

(b) [5 points] State precisely what it means to say a set A is “strictly bigger” than another set B.

Solution.

There is no injection from A to B. Alternatively, there is no bijection between A and B, while there is an injection from B to A.

□

(c) [5 points] Give an example of a set that is strictly bigger than the set of real numbers.

Solution.

P (ℝ).

□

Handout 53: F’99 Final Quiz Solutions  1  Name:

Problem 2 [13 points] Modular Arithmetic.

(a) [5 points] Prove that there is no x such that

117 · x ≡ 1 (mod 213).

Solution. 117 · x ≡ 1 (mod 213) iff 117 · x + 213 · y = 1 for some integer y. This is equivalent to having gcd(213, 117) = 1, but by Euclid’s algorithm, gcd(213, 117) = 3.

□

(b) [8 points] Find an integer x for which

123 · x ≡ 1 (mod 2347)

Solution. x = −706 works because 1 = 37 · 2347 + (−706) · 123.

□

Problem 3 [10 points] Invariants.

(a) Give the definition of a state invariant of a state machine. Solution. A predicate, P, on states such that if there is a transition from state s to state t and P (s) is true, then P (t) is true.

□

(b) Besides the identically false and the identically true state invariants, how many other logically distinct state invariants does the following machine have? Describe them. (Two invariants are logically distinct if there exists a state in which one holds and the other doesn’t.) State Machine Description: States Q::= {A, B, C, D, E, F, G, H}, transitions:

{(A, B), (B, C), (C, A), (D, E), (E, F)(F, D), (C, D), (G, A), (B, H)} .

Solution. Three: the membership predicates for the following three sets of states:

{ABCDEF H} , {DEF } , {H} .
□

Handout 53: F’99 Final Quiz Solutions  2  Name:

Problem 4 [10 points] Stars and Bars.

A juggler plans to juggle 11 rings for his finale. In his bag are 20 identical red rings, 30 identical blue rings, and 40 identical white rings. He must select at least one of each color to be patriotic. An example of a patriotic choice of 11 rings would be: 3 red, 2 white, and 6 blue. How many different patriotic choices are there for the 11 rings?

Solution.

This is the same as asking how many ways there are to arrange 11 stars and two bars such that there is at least one star in each of the three groups delimited by the bars. Reserving three stars for this purpose leaves 8 stars and 2 bars, so there are

\binom{8 + 2}{2} = \binom{10}{2}.

Note that the initial number of red, white, and blue rings available to the juggler is irrelevant as long as there are at least nine of each.

□

Problem 5 [10 points] Equivalence Relations and Random Variables.

Define a binary relation ρ on real-valued random variables X, Y by the rule that X ρ Y iff Pr {X ≠ Y } = 0. Prove that ρ is an equivalence relation.

Solution.

ρ is reflexive because the event X ≠ X is the empty event—which has probability zero.

ρ is symmetric because the event X ≠ Y is the same as the event Y ≠ X, so if either of these events has probability zero, then they both do.

To prove ρ is transitive, suppose X ρ Y and Y ρ Z. We must show that if X(s) ≠ Z(s) for some sample point s, then Pr {s} = 0. This implies Pr {X ≠ Z} = 0, so X ρ Z as required.

So suppose X(s) ≠ Z(s). If also X(s) ≠ Y (s), then Pr {s} = 0 because X ρ Y. Otherwise, Y (s) = X(s) ≠ Z(s), so Y (s) ≠ Z(s), and hence Pr {s} = 0 in this case as well because Y ρ Z.

□

Problem 6 [13 points] Counting with Repetition.

(a) [5 points] How many distinguishable ways are there to rearrange the letters in

“INSTRUCTOR”?

Solution.

There are 10! ways to arrange 10 distinct letters, but we have two T’s and two R’s, so this overcounts by a factor of 2! for the T’s and by a factor of 2! for the R’s. The correct answer is

\frac{10!}{2!2!} = 907200

□

(b) [8 points] … with all vowels consecutive?

Solution.

Let the letter V represent the block of vowels, treated as a single unit. How many ways can we rearrange the letters NSTRCTRV? There are 8! ways to arrange 8 distinct letters, but we have two T’s and two R’s, so this overcounts by a factor of 2!2!. So there are \frac{8!}{2!2!} ways to arrange the letters NSTRCTRV. There are three vowels, so there are 3! ways to arrange the vowels within the block V, so the number of ways to arrange the letters of INSTRUCTOR with all the vowels consecutive is

3!\frac{8!}{2!2!} = 60480.

Alternatively: 7!/2!2! ways to arrange the consonants, and 8 places to insert the 3 consecutive vowels between these 7 consonants.

□

Problem 7 [10 points] Conditional Probability.

Boston is justly famous for its enthusiastic sports fans. Surveys show that 90% of adult Bostonians are Celtics fans, and 75% are Red Sox fans. However, only 80% of the Celtics fans are also Red Sox fans. Now suppose that an adult Bostonian is chosen at random from among those that are not Celtics fans. What is the probability that such a person is a Red Sox fan?

Solution.

Let P represent the event that a Bostonian is a Red Sox fan, and S represent the event that the resident is a Celtics fan. Then

Pr \{P \} = Pr \{P | S\} Pr \{S\} + Pr \{P | \overline{S}\} Pr \{\overline{S}\} ,  so
Pr \{P | \overline{S}\} = \frac{Pr \{P \} − Pr \{P | S\} Pr \{S\}}{Pr \{\overline{S}\}}
= \frac{0.75 − (0.80 · 0.90)}{1 − 0.9}
= 0.3.

□

Problem 8 [10 points] Markov Bound.

A herd of 350 cows is stricken by an outbreak of ”mad cow” disease. The disease lowers the normal body temperature of a cow, and a cow will die if its temperature goes below 90 degrees F. The disease epidemic is so intense that it lowered the average temperature of the herd to 45 degrees. Body temperatures as low as 20 degrees, but no lower, were actually found in the herd.

(a) [6 points] State a best possible upper bound on the number of cows whose temperature is high enough to survive.

Solution.

Let R be the temperature. Apply Markov’s Bound to R − 20:

Pr {R ≥ 90} = Pr {R − 20 ≥ 70} ≤ E [R − 20] /70 = (45 − 20)/70 = 5/14,

so at most (5/14)350 = 125 cows have temperature ≥ 90 degrees.

□

(b) [4 points] Give an example set of temperatures that achieve your bound.

Solution.

Of the 350 cows, 125 have 90 degree temperature and 225 have 20 degree temperature. The mean is

(125 · 90 + 225 · 20)/350 = 45,

as required.

□

Problem 9 [15 points] Linear Recurrence. You just moved into your new house and you are throwing a housewarming party. You invite 5 people on the first day and tell them to invite their friends. Each newly invited person invites 2 people the day after they are invited.

(a) [5 points] Give a recurrence describing the total number of people invited up to and including the nth day, that is, the people you invited, and the people invited by the people you invited, etc. For example, on the first day, 5 people are invited, by the second day 15 people have been invited—the 5 people invited on the first day and the ten people they invite on the second day—and by the third day, 35 = 15 + 2 · 10 people have been invited.

Solution.

The number, T (n), of people invited through the nth day equals the number, T (n − 1), of people invited through the previous day, plus to 2 new guests for each of the T (n − 1) − T (n − 2) people newly invited on the previous day, So,

T (n) = T (n − 1) + 2[T (n − 1) − T (n − 2)] = 3T (n − 1) − 2T (n − 2).

□

(b) [5 points] Describe initial conditions for the recurrence.

Solution.

You know that T(0) = 0 since no one was invited on day 0 and T(1) = 5, since you invited 5 people on the first day.

□

(c) [5 points] Give a closed form expression equal to the number of people invited by the nth day.

Solution.

The characteristic polynomial is p(a) ::= a^{2} − 3a + 2 = (a − 2)(a − 1), so

T (n) = c2^{n} + b1^{n} = c2^{n} + b.

for some b, c ∈ ℝ. Plugging in the initial conditions, gives two equations:

T (0) = 0 = c + b
T (1) = 5 = c ∗ 2 + b,

so c = 5, b = −5 and

T (n) = (5 ∗ 2^{n}) − 5.

□

Problem 10 [11 points] Binomial Identity. Suppose you want to choose a team of m people from a pool of n people for your startup company, and from these m people you want to choose k to be the team managers. Prove that you can do this in

\binom{n}{k}\binom{n − k}{m − k}

ways.

Solution.

First, brute-force:

Choosing m out of n, and then k out of the chosen m, can be done in \binom{n}{m}\binom{m}{k} ways. Now,

\binom{n}{m}\binom{m}{k} = \frac{n!}{m!(n − m)!} \frac{m!}{k!(m − k)!}
= \frac{n!}{(n − m)!k!(m − k)!}
= \frac{n!(n − k)!}{(n − m)!k!(m − k)!(n − k)!}
= \frac{n!}{k!(n − k)!} \frac{(n − k)!}{(n − m)!(m − k)!}
= \frac{n!}{k!(n − k)!} \frac{(n − k)!}{((n − k) − (m − k))!(m − k)!}
= \binom{n}{k}\binom{n − k}{m − k}.

Combinatorial proof:

Instead of choosing first m from n and then k from m, you could alternately choose the k managers from the n people and then choose m − k people to fill out the team from the remaining n − k people. This gives you \binom{n}{k}\binom{n−k}{m−k} ways of picking your team. Since you must have the same number of options regardless of the order in which you choose to pick team members and managers,

\binom{n}{m}\binom{m}{k} = \binom{n}{k}\binom{n − k}{m − k}.

□

Problem 11 [15 points] Trees and Structural Induction.

A full binary tree with its vertices and leaves is defined inductively as follows:

• A simple graph with one vertex is a full binary tree. The vertex is called the root of the tree. The set of leaves of the tree is the set whose sole member is the root. The set of vertices of this tree is the same as the set of leaves.

• If B_{1} and B_{2} are full binary trees such that the vertices of B_{1} and B_{2} are disjoint, then a simple graph consisting of a new vertex with edges from the new vertex to the roots of B_{1} and B_{2} is also a full binary tree, B. The root of B is the new vertex. The vertices of B are exactly its root, the vertices of B_{1}, and the vertices of B_{2}. The leaves of B are exactly the leaves of B_{1} and the leaves of B_{2}.

For example, a full binary tree with 5 nodes and 3 leafs is is shown in Figure INSERT FIGURE.

Prove that for all full binary trees B,

|leaves(B)| = \frac{|vertices(B)| + 1}{2}.

Solution.

The induction hypothesis, P (B), is the equation to be proved.

Base case P (single root): there is 1 leaf, 1 vertex and indeed 1 = (1 + 1)/2.

Inductive step B has a root r connected to two full binary trees B_{1}, B_{2}; the induction hypothesis is that P (B_{1}) and P (B_{2}) are true. So

|leaves(B)| = |leaves(B_{1}) ∪ leaves(B_{2})|
= |leaves(B_{1})| + |leaves(B_{2})|  because vertices of B_{1} and B_{2} are disjoint
= \frac{|vertices(B_{1})| + 1}{2} + \frac{|vertices(B_{2})| + 1}{2}  by induction hypothesis
= \frac{(1 + |vertices(B_{1})| + |vertices(B_{2})|) + 1}{2}
= \frac{|\{r\} ∪ vertices(B_{1}) ∪ vertices(B_{2})| + 1}{2}  disjointness again
= \frac{|vertices(B)| + 1}{2}

□

Problem 12 [20 points] Chebyshev Bound.

A man has a pocketful of n keys, exactly one of which will open the door to his apartment. He picks a random key from his pocket, tries to open the door with it, and puts it back in his pocket if it doesn’t work (no, he isn’t very together about key management, and he may try the same key over and over again). He continues trying until he finds the key that works.

(a) [5 points] What is the expected number of trials of keys the man makes until he finds the right one? Hint: Mean time to failure.

Solution.

The probability of picking the right key on each trial is 1/n, so mean time to failure—in this case “failing” to pick the wrong key—is 1/(1/n) = n.

□

(b) [10 points] What is the variance for the number of trials, T, of keys till he finds the right one ? Hint: Some relevant summation formulas are in the Appendix.

Solution.

The probability stays the same on all subsequent trials since the picked key is always returned to the urn. Thus

Pr \{T = k\} = (\frac{n − 1}{n})^{k−1} \frac{1}{n}.

Note: this is the same as the waiting time for the first head in the Bernouli process with a biased coin. Let p = 1/n and let q = 1 − p.

The variance of T can be computed directly from the formula,

Var [T] = E [T^{2}] − E^{2} [T] .

Again, by definition we have

E [T^{2}] = ∑_{k=1}^{∞} k^{2}pq^{k−1}.

We know that

∑_{k=1}^{∞} kq^{k} = q ∑_{k=1}^{∞} kq^{k−1} = \frac{q}{(1 − q)^{2}} .

Moreover,

∑_{k=1}^{∞} k^{2}q^{k−1} = ∑_{k=1}^{∞} \frac{d kq^{k}}{dq}

= \frac{d(∑_{k=1}^{∞} kq^{k})}{dq}
= \frac{d(\frac{q}{(1−q)^{2}} )}{dq}
= \frac{1}{(1 − q)^{2}} + \frac{2q}{(1 − q)^{3}} = \frac{1}{p^{2}} + \frac{2q}{p^{3}} .

Finally, the expectation E [T^{2}] is

E [T^{2}] = p (\frac{1}{p^{2}} + \frac{2q}{p^{3}} ) = \frac{1}{p} + \frac{2q}{p^{2}} ,

and the variance is

Var [T] = \frac{1}{p} + \frac{2q}{p^{2}} − (\frac{1}{p})^{2} = \frac{q}{p^{2}} = n(n − 1).

□

(c) [5 points] What is the Chebyshev upper bound on the probability that the man will make at least a 100 trials till success? Let V denote the variance that you were asked to calculate in the previous part, and express your answer as a closed formula using V.

Solution.

One-way bound:

Pr \{T ≥ 100\} = Pr \{T − n ≥ 100 − n\} ≤ \frac{V}{V + (100 − n)^{2}} .

Full credit also for using the regular two-way bound.

□

Problem 13 [30 points] Random Graphs.

A simple graph with 10 vertices is constructed by randomly placing an edge between every two vertices with probability p. These random edge placements are performed independently.

(a) [2 points] What is the probability that a given vertex, v, of the graph has degree two?

Solution.

\binom{9}{2} · p^{2} · (1 − p)^{7}.

□

(b) [5 points] What is the expected number of nodes with degree two?

Solution.

10 times the previous answer by linearity of expectations.

□

(c) [15 points] What is the expected number of cliques of size k, that is, subgraphs isomorphic to the complete graph with k vertices? Express your answer as a closed form formula involving binomial coefficients.

Solution.

The strategy for computing the expected number of cliques uses linearity of expectation. Define an indicator random variable for every possible k-clique. Every k-subset of the n nodes is a possible k-clique, so there are \binom{n}{k} such random variables. (Here n = 10, but the argument is easier to follow with n as a parameter.) The random variable for a particular k-clique is 1 if the k-clique appears in the graph and 0 if not, so its expected value is just the probability that a particular k-clique occurs in the graph. This happens if and only if all k nodes are connected by edges; there are \binom{k}{2} such edges, so the probability of a particular k-clique is p^{\binom{k}{2}}. Summing the expected values of all the k-cliques gives the expected number of k-cliques:

\binom{n}{k}p^{\binom{k}{2}}.

□

(d) [8 points] The previous result implies an interesting fact which you may assume without proof: if p = 1/2, then the expected number of cliques of size 2 log n is greater than one, where n is the total number of vertices in the graph. (In the previous parts we had n = 10; now n is arbitrary.) Oddly, even though we can expect there to be such a clique, no procedure is known to find some clique of size 2 log n in the graph—when there is one—which is much more efficient than exhaustively searching through all possible subsets of vertices of size 2 log n and checking each subset to see if it is a clique. Circle each of the following expressions which correctly bounds the number of subsets such an exhaustive search would examine:

a) O(2^{n})

b) O(n^{2})

c) O(n^{log n})

d) O(n^{2 log n})

Solution.

(a),(d).

The number of such subsets is

\binom{n}{2 log n} = \frac{P (n, 2 log n)}{(2 log n)!} < P (n, 2 log n) < n^{2 log n},

and

\frac{P (n, 2 log n)}{(2 log n)!} > (\frac{(n − log n)}{2 log n})^{2 log n} > (n^{0.9})^{2 log n} = n^{1.8 log n} ≠ O(n^{log n}).

□

Problem 14 [15 points] Probabilistic Prediction.

We have three coins to flip: one has probability 3/4 of coming up heads, another has probability 7/8 of coming up heads, and finally there is one with probability 15/16 of coming up heads. One of the three coins is picked, and this coin is repeatedly tossed.

Explain a way to determine a number of tosses sufficient to allow identification with 99% confidence of the coin being tossed. You do not have to carry out the calculation, and you may cite without proof any of the results from the Appendix or other course material.

Solution.

Identify the coin to be the one whose probability is closest to the fraction of heads among n flips. This identification will be correct 99% of the time if the probability that the actual fraction of heads in n flips differs from the expected fraction of heads by more than 1/32 is at most 0.01. We choose 1/32 because it is half the distance between the two closest coin probabilities.

Let S_{n} be the number of heads appearing in n flips, so S_{n}/n is the fraction of heads. We assume the successive flips are independent, so the variance of S_{n}/n is 1/n^{2} times the variance of S_{n} which is n times the variance of a Bernoulli variable whose probability was the probability of heads in one flip. We know the variance of a Bernoulli variable is at most 1/4, so Var [S_{n}/n] ≤ (1/n^{2})(1/4)n = 1/4n. Chebyshev’s bound implies that the probability that S_{n}/n deviates from its mean by 1/32 is at most (1/4n)/(1/32)^{2}. Choose n so this quantity is at most 0.01.

Alternatively, observe that S_{n} will have a Bernoulli distribution with one of the three probabilities 3/4, 7/8, 15/16. Using the bounds from Lecture 21 on the tails of the binomial distribution, we could choose n large enough that the probability that Pr {|S_{n} − pn| ≥ n/32} ≤ 0.01 for each p = 3/4, 7/8, and 15/16.

□