# Midterm 1 - HKN

## Midterm 1 - HKN

CS 70 Discrete Mathematics and Probability Theory Midterm 1 Summer 2014 James Cook Thursday July 17, 2014, 12:40pm-2:00pm. Instructions: • Do not t...

CS 70

Discrete Mathematics and Probability Theory

Midterm 1

Summer 2014 James Cook Thursday July 17, 2014, 12:40pm-2:00pm. Instructions: • Do not turn over this page until the proctor tells you to.

• Don’t write any answers on the backs of pages (we won’t be scanning those). There is an extra page at the end in case you run out of space. • The exam has 10 pages (the last two are mostly blank).

P RINT your student ID: ,

P RINT AND S IGN your name: (last)

(first)

(signature)

P RINT your discussion section and GSI (the one you attend): Name of the person to your left: Name of the person to your right: Name of someone in front of you: Name of someone behind you:

CS 70, Summer 2014, Midterm 1

1

P RINT your name and student ID:

True/False 1. (16 pts.) For each of the following statements, circle T if it is true and F otherwise. You do not need to justify or explain your answers. T

F

For all positive integers x and p, if gcd(x, p) = 1, then x p−1 ≡ 1 (mod p). Solution: False: for example, take p = 4 and x = 3.

T

F

One way to prove a statement of the form P =⇒ Q is to assume ¬Q and prove ¬P. Solution: True. This is proof by contrapositive.

T

F

∀x∃yP(x, y) ≡ ∃x∀yP(y, x). Solution: False. For example, if the domain is R and P(x, y) is x < y, then ∀x∃yP(x, y) is true but ∃x∀yP(y, x) is false.

T

F

P ⇒ (Q ⇒ R) ≡ (P ∧ Q) ⇒ R Solution: True. This can be seen with a truth table, or by P ⇒ (Q ⇒ R) ≡¬P ∨ (¬Q ∨ R) ≡(¬P ∨ ¬Q) ∨ R ≡¬(P ∧ Q) ∨ R ≡(P ∧ Q) ⇒ R.

T

F

P ⇒ (Q ∧ R) ≡ (P ⇒ Q) ∨ R Solution: False. For example, if P and R are true and Q is false, then P ⇒ (Q ∧ R) is false but (P ⇒ Q) ∨ R is true.

T

F

To prove (∀n ∈ N)P(n), it is enough to prove P(0), P(2) and (∀n ≥ 2)(P(n) ⇒ P(n + 2)). Solution: False. For example, if P(n) is “n is even”, then (∀n ∈ N)P(n) is false, but P(0), P(2) and (∀n ≥ 2)(P(n) ⇒ P(n + 2)) is true.

T

T

F

F

In a stable marriage instance, there can be two women with the same optimal man. Solution: False. If we run the propose and reject algorithm with women proposing, then the resulting pairings will have every woman paired with her optimal man. A single man can not be paired with two women, so any two women must have different optimal men. In stable marriage, if Man 1 is at the top of Woman A’s ranking but the bottom of every other woman’s ranking, then every stable matching must pair 1 with A.

CS 70, Summer 2014, Midterm 1

2

Solution: False. For example, consider this instance: Woman R anking Man Ranking A 1 2 3 1 B C A B 2 3 1 2 A C B C 2 3 1 3 A C B Here, a stable matching is (1, B), (2, A), (3,C).

CS 70, Summer 2014, Midterm 1

3

P RINT your name and student ID:

Short Answer 2. (4 pts.) Compute (23 · 571 ) + (33 + 42 ) mod 8. Solution: 3.

3. (4 pts.) Compute

200 + 14 · 102 mod 10. 99

Solution: 200 + 14 · 102 0 + 4 · 2 ≡ 99 9 8 ≡ −1 ≡−8 ≡2 (mod 10)

4. (4 pts.) Prove that (∃x ∈ R)(∀y ∈ R) x · y < 2. Solution: Choose x = 0. Then for any y ∈ R, x · y = 0 < 2. Common mistake: • You must find a single value of x, since it starts with ∃. Providing different values of x for different values of y doesn’t prove the proposition. For example, x = 1/y depends on y, so that doesn’t work.

CS 70, Summer 2014, Midterm 1

4

P RINT your name and student ID:

RSA 5. (12 pts.) Someone sends Pandu an RSA-encrypted message x. The encrypted value is E(x) = 2. However, Pandu was silly and picked numbers far too small to make RSA secure. Given his public key (N = 77, e = 43), find x. Solution: N can be easily factored into 7 and 11. So (p − 1)(q − 1) = 60. The decryption exponent is 43−1 (mod 60), which we can find using the extended Euclidean algorithm: gcd(60, 43) 1 = 2 · 43 − 5 · (60 − 43) = −5 · 60 + 7 · 43 = gcd(43, 17) 1 = −1 · 17 + 2 · (43 − 2 · 17) = 2 · 43 − 5 · 17 = gcd(17, 9) 1 = 1 · 9 − 1 · (17 − 9) = −1 · 17 + 2 · 9 = gcd(9, 8) 1 = 1·9−1·8 = gcd(8, 1) 1 = 0·8+1·1 −1 So d ≡ 43 ≡ 7 (mod 60). x ≡ E(x)d ≡ 27 ≡ 128 ≡ 51 (mod 77).

CS 70, Summer 2014, Midterm 1

5

P RINT your name and student ID:

Induction 6. (12 pts.) Prove that every two consecutive numbers in the Fibonacci sequence are coprime. (In other words, for all n ≥ 1, gcd(Fn , Fn+1 ) = 1. Recall that the Fibonacci sequence is defined by F1 = 1, F2 = 1 and Fn = Fn−2 + Fn−1 for n > 2.) Solution: Proof by induction. Base case: F1 = 1 and F2 = 1, so clearly gcd(F1 , F2 ) = 1. Induction hypothesis: Suppose gcd( fn−1 , fn ) = 1. Induction step: We want to show gcd(Fn , Fn+1 ) = 1. We’ll use the fact from Euclid’s algorithm that gcd(a, a + b) = gcd(a, b). This fact is true because any d that divides both a and b, (a = kd, b = `d) must also divide a + b (because a + b = (k + `)d), and any d that divides both a and a + b (a = xd, a + b = yd) must also divide b (because b = (y − x)d). Using this fact, gcd(Fn , Fn+1 ) = gcd(Fn , Fn + Fn−1 ) = gcd(Fn , Fn−1 ) = 1; the last equality is the induction hypothesis.  Common mistakes: • Giving a base case that is not gcd(1, 1). If you do this, you haven’t proved for n ≥ 1. • Giving an induction hypothesis like “for all n > 1, P(n)”. Notice this is what you’re trying to show!

CS 70, Summer 2014, Midterm 1

6

P RINT your name and student ID:

Error-Correcting Codes 7. (15 pts.) Alice wants to send to Bob a message of length 3, and protect against up to 2 erasure errors. Using the error-correcting code we learned in class, she obtains a polynomial P(x) modulo 11 and sends 5 points to Bob. Bob only receives 3 of the points: P(1) = 4, P(3) = 1, P(4) = 5. (a) (12 pts.) Decode Alice’s original message P(1), P(2), P(3).

(b) (3 pts.) If Alice tried to send a message with a modulus of 10 instead of 11, what exactly could go wrong? (You don’t need to do any computations in your answer.) Solution: (a) We solve using the method of Lagrange Interpolation: ∆1 (x) =

(x − 3)(x − 4) (x − 3)(x − 4) = = 2 ∗ (x − 3)(x − 4) = 2x2 − 3x + 2 (1 − 3)(1 − 4) 6

∆3 (x) =

(x − 1)(x − 4) (x − 1)(x − 4) = = 5 ∗ (x − 1)(x − 4) = 5x2 − 3x − 2 (3 − 1)(3 − 4) −2

∆4 (x) =

(x − 1)(x − 3) (x − 1)(x − 3) = = 4 ∗ (x − 1)(x − 3) = 4x2 + 6x + 1 (4 − 1)(4 − 3) 3

P(x) = 4 ∗ ∆1 (x) + 1 ∗ ∆3 (x) + 5 ∗ ∆4 (x) = 4 ∗ (2x2 − 3x + 2) + (5x2 − 3x − 2) + 5 ∗ (4x2 + 6x + 1) = 8x2 + 5x2 + 20x2 − 12x − 3x + 30x + 8 − 2 + 5 = 33x2 + 15x + 11 = 4x Thus, the original encoding polynomial is P(x) = 4x, and the missing point is P(2) = 4 ∗ 2 = 8. Common mistakes: – Remember to check your work! Most points were lost just due to calculation mistakes. For errorcorrecting problems, checking your answer is easy, because you can just plug in the points that you received into the polynomial that you calculated. – Also remember that you can simplify numbers based on the modulus in the middle of a calculation. Simplifying the delta polynomials modulo 11, for example, would probably help make calculating the original polynomial easier, and decrease the chance of calculation errors. (b) The integers modulo 10 do not form a field, so there is no guarantee that Alice would be able to find a polynomial P(x) that passes through her three points. Alternate answer: Since the integers module 10 do not form a field, we have to guarantee that only one polynomial goes through the points Bob receives. So Bob may find more than one possible message. Common mistakes for (b): – Some people thought all computations were done modulo 11, but while sending or decoding the message a modulo of 10 was used instead. – Some people said using 10 instead of 11 would cause the message to be “insecure”. Note that error correcting codes don’t try to address security.

CS 70, Summer 2014, Midterm 1

7

P RINT your name and student ID:

Polynomials 8. (16 pts.) Suppose P is a polynomial over R, and for every x, y ∈ R, P(x + y) = P(x) + P(y). (a) Prove that for every positive integer n, P(n) = n · P(1).

(b) Prove that P has degree at most 1.

Solution: (a) Proof by induction on n. Base case: n = 1: P(1) = 1 · P(1). Induction step: If P(n) = n · P(1), then P(n + 1) = P(n) + P(1) = nP(1) + P(1) = (n + 1)P(1). Common mistakes: – Giving an induction hypothesis like “for all n > 1, P(n)”. Notice this is what you’re trying to show! (b) Define the polynomial Q(x) by Q(x) = P(1)x. We will show that P(x) and Q(x) are the same polynomial. Let d be the degree of P(x). By part (a), there are at least d+1 points where P(x) = Q(x). So P(x) and Q(x) are the same polynomial. Note: this was the most difficult question on the midterm. Only seven people got full credit, and six others got partial credit. Common mistakes: – Many people said that because xP(1) is a linear polynomial, P(x) must be linear, but did not explain why the polynomial P(x) is equal to the polynomial xP(1). (Part (a) only shows that it’s equal when x is a positive integer.) – Many people argued that if P(x) had degree d > 1, say P(x) = ad xd + ad−1 xd−1 + · · · + a1 x + a0 , then since P(x + y) = ad (x + y)d + ad−1 (x + y)d−1 + · · · + a1 (x + y) + a0 and P(x + y) = P(x) + P(y) = ad (xd + yd ) + ad−1 (xd−1 + yd−1 ) + · · · + a1 (x + y) + 2a0 it must follow that (x + y)d = xd + yd , (x + y)d−1 = xd−1 + yd−1 , etc. However, it’s not clear why that would have to be true: in general, it’s possible to have a + b + c = a0 + b0 + c0 without it being true that a = a0 , b = b0 and c = c0 . – Some people argued that if P(x) had degree at least two, then it would have at least two roots, and reached a contradiction based on that. However, it is possible for a polynomial of any degree to have zero roots: consider xd + 1. The property from class only says that a degree-d polynomial must have at most degree roots. (If we allow complex numbers, then it is true that every degree-d polynomial has d roots, if we count “repeated roots” multiple times; however, since we were only given that P(x + y) = P(x) + p(y) when x, y are real numbers, that line of reasoning doesn’t seem fruitful either.)

CS 70, Summer 2014, Midterm 1

8

P RINT your name and student ID: [Extra page. If you want the work on this page to be graded, make sure you tell us on the problem’s main page.]

CS 70, Summer 2014, Midterm 1

9

P RINT your name and student ID: [Doodle page! Draw us something if you want or give us suggestions or complaints.]

CS 70, Summer 2014, Midterm 1

10