CS 70 Discrete Mathematics and Probability Theory Summer 2015 Chung-Wei Lin Midterm 1 PRINT Your Name:, last) first) SIGN Your Name: PRINT Your Student ID: CIRCLE your exam room: 2050 VLSB 10 EVANS OTHER Name of the person sitting to your left: Name of the person sitting to your right: After the exam starts, please write your student ID or name) on every odd page we will remove the staple when scanning your exam). We will not grade anything on the extra pages Pages 14 16) or outside of the space provided for a problem unless we are clearly told in the space provided for the question to look there. Except special notices, you must show your work to get credits. You may consult one single-sided sheet of notes. Apart from that, you may not look at books, notes, etc. Calculators, phones, and computers are not permitted. You have 110 minutes. There are 9 questions for a total of 100 points plus 15 bonus points. Use the number of points as a rough guide for the amount of time to allocate to that question. Note that the last two questions 8 and 9) are harder than the rest, so you should attempt it only after you take a good shot at the rest and don t feel bad if you cannot get them). There are 16 pages sides) on the exam. Notify a proctor immediately if a page is missing. Do not turn this page until your instructor tells you to do so. CS 70, Summer 2015, Midterm 1 1
1. TRUE or FALSE First Round 8 points, 1 point for each part) For any proposition P,Q,R and x,y R, determine whether the following statements are true or false. Just circle the correct choice. No explanation is required. No partial credit will be given. T F P Q) Q P). T F P P). T F P Q) P Q). T F P Q) Q R)) P R). T F x P) x P). T F y x P x y P. T F x 0 y 0) is true means there exists exactly one of x and y being 0. T F In R, 2015 points can determine a unique polynomial of degree 2014. Answer: F,T,T,T,T,F,F,F. 2. Counting Minions and Bananas 6 points, 3 points for each part) For the following two parts, just write down your answers. You do not need to calculate the exact value of a ) b or a!. No explanation is required. No partial credit will be given. Figure 1: They are Kevin, Bob, Stuart,... [http://scifi.stackexchange.com/]. a) There are 7 different minions in the figure. Three of them are going to form a team and find their new master. How many different ways to form the team, where one member has exactly one eye and the other two members have two eyes? Answer: 2 5 1) 2) or 20. b) How many different anagrams of BANANA are there? 6! Answer: 3!2! or 60. 2
3. Conceptual Questions 10 points, 1/1/2/3/3 points for each part) a) Kevin and Bob decide to apply the RSA cryptography so that Kevin can send a secret message to Bob. There are several important variables, p,q,n,e,d, defined in the RSA cryptography. Which of them are public? No explanation is required. No partial credit will be given.) Answer: N and e you can also answer N and d with appropriate explanation). b) Following Part a), let s switch to private variables. Are those private variables kept by Kevin only, Bob only, or both Kevin and Bob? No explanation is required. No partial credit will be given.) Answer: Bob. c) Explain why it is difficult for an attacker to break the RSA cryptography. We are expecting only one sentence.) Answer: Factoring N is very difficult. d) Explain why the two primes in RSA must be different. We are expecting two reasons.) Answer: If p q, the correctness is not guaranteed because x e ) d x mod N) is not always true. Besides, the security level is lowered because taking square root of N can easily get the prime. e) Explain why p must be prime in the polynomial secret sharing with mod p. We are expecting two reasons.) Answer: If p is not prime, the correctness is not guaranteed because d + 1 points cannot always determine a unique polynomial of degree at most d. Besides, the security level is lowered because some information about the secret may be revealed, even if there are no sufficient points. 3
4. Stable Marriage 8 points, 3/5 points for each part) a) Is the pairing {1,A),2,B),3,C)} stable for the following case? Why? Men Preference Lists Women Preference Lists 1 C > A > B A 2 > 1 > 3 2 B > C > A B 3 > 1 > 2 3 B > C > A C 3 > 2 > 1 Answer: No. 3,B) is a rogue couple because 3 prefers B to C and B prefers 3 to 2. Note: It is the only rogue couple in the pairing. b) Find a stable pairing for the following case. Answer: Run the men-proposing SMA: Men Preference Lists Women Preference Lists 1 D > B > A > C A 1 > 4 > 2 > 3 2 A > D > B > C B 4 > 3 > 2 > 1 3 D > C > B > A C 1 > 3 > 2 > 4 4 D > A > B > C D 3 > 1 > 2 > 4 Day 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7 A 2 2,4 4 4 1,4 1 1 B 1 1 1,2 2 2,4 4 C 2 D 1,3,4 3 2,3 3 3 3 3 The stable pairing: {1,A),2,C),3,D),4,B)}. Note 1: If you run the women-proposing SMA, you will get the same stable pairing. Note 2: You can ignore 3,D) first because they must be paired together each of them is the favorite partner of the other). 4
5. Minions Using RSA 8 points, 5/3 points for each part) Kevin and Bob decide to apply the RSA cryptography so that Kevin can send a secret message to Bob. a) Assuming p 3, q 11, and e 7, what is d? Calculate the exact value. Answer: 3 1)11 1) 20, so d is the multiplicative inverse of 7 mod 20. Run egcd20,7) and get 1 1) 20 + 3) 7, so d 3. Note: You can also try d 1,2,3,... and get d 3. b) Following Part a), what is the original message if Bob receives 4? Calculate the exact value. Answer: N 3 11 33. 4 d 4 3 64 31 mod 33). 5
6. Minions Using Error Correction Codes 10 points, 5 points for each part) a) Kevin wants to send a message of 4 packets to Stuart and guard against 1 lost packet. Working over GF7), he finds the unique polynomial Px) that passes through the points he wants to send, and sends Stuart 5 packets: 0,P0)), 1,P1)), 2,P2)), 3,P3)), 4,P4)). Stuart receives the following packets: 0,3), 1,0), 2,0), 4,0). What is the value of the missing packet? Calculate the exact value. Answer: 0 x) x 1)x 2)x 4) 1) 2) 4) x 1)x 2)x 4) 8 x 1)x 2)x 4) mod 7); Px) 3 0 x) 3x 1)x 2)x 4) 4x 1)x 2)x 4) mod 7); P3) 42)1) 1) 6 mod 7). Note: You do not need to calculate 1 x), 2 x), or 4 x) as they will be multiplied by 0. 6
Figure 2: Minions using error correction codes [http://despicableme.wikia.com/wiki/despicable_me_wiki]. b) Kevin wants to send a message of 60 ordered packets to Stuart. Those packets will first go through a hungry dragon who will eat at most 1 of all packets do not ask why the dragon loves eating packets). 5 The remaining packets will then go through a powerful but malicious witch who will change the data of at most 1 of all packets. Given this scenario, how many packets should Kevin send so that Stuart can 8 recover the message? Answer: We observe that the worst case is when 1/5 packets are missing and then 1/8 packets are corrupted. Assume m is the number of all packets, m must satisfy )) )) 7 4 1 4 8 5 m) 8 5 m) 60. Solving the inequality can get m 100. Note: Students can get bonus points by trying to minimize the number of packets and answering 97. This is true because the more precise inequality is 7 8 4 5 m) 1 8 4 5 m) 60. Note: Students can also solve the problem by interpreting at most 1 8 of all packets as at most 1 8 of all original packets. This will result in 4 5 m) 1 ) ) 1 8 m) 8 m) 60. Solving the inequality can get m 110. The optimal solution for this is 107. 7
7. TRUE or FALSE Second Round 40 points, 10 points for each part) For any of the following statements, claim TRUE or FALSE first. If you claim TRUE, prove it. If you claim FALSE, disprove it e.g., provide a counterexample). a) a is an odd number if and only if a 2 is an odd number. TRUE FALSE Answer: TRUE or FALSE, see Note below). It is an if and only if statement, so proving two directions is required. Use direct proof to prove if a is an odd number, then a 2 is an odd number. If a is an odd number, a 2k + 1 for some integer k. Then, a 2 2k + 1) 2 4k 2 + 4k + 1 22k 2 + 2k) + 1, which is an odd number. Use proof by contraposition to prove if a 2 is an odd number, then a is an odd number. If a is not an odd number, a 2k for some integer k. Then, a 2 2k) 2 4k 2 22k 2 ), which is not an odd number. We prove the claim by proving its contrapositive. After proving the two directions, the statement is proved. Note: Students can get bonus points by answering FALSE with counterexample a 3. 8
b) If a 0 0; a 1 1; then a n 2 n 1 for any integer n 0. a n a n 1 + 2a n 2 + 2 for any integer n 2, TRUE FALSE Answer: TRUE. Use strong induction with two base cases to prove the statement. Base case n 0 and n 1): a 0 0 2 0 1; a 1 1 2 1 1. Inductive hypothesis: assume a i 2 i 1 for all i, 0 i k. Inductive step: a k+1 a k + 2a k 1 + 2 2 k 1 + 22 k 1 1) + 2 2 k 1 + 2 k 2 + 2 2 k+1 1. By the principle of induction, the statement is proved. 9
c) For all integers a,b,c where c > 0, if a has no multiplicative inverse mod c, then ax b mod c) has no solution. TRUE FALSE Answer: FALSE. Let a 2, b 0, c 4. 2 has no multiplicative inverse mod 4 because gcd2, 4) 2 1, but 2x 0 mod 4) has two solutions, 0 and 2. 10
d) Given n n 1) integers x 1,x 2,...,x n and a prime p, x 1 + x 2 +... + x n ) p x p 1 + xp 2 +... + xp n mod p). TRUE FALSE Answer: TRUE. First, to prove, for any integer a, a p a mod p). If a 0 mod p), then a p 0 p 0 a mod p). If a 0 mod p), then, by the Fermat s Little Theorem, a p a p 1 a 1 a a mod p). As a result, LHS x 1 + x 2 +... + x n ) p x 1 + x 2 +... + x n mod p); RHS x p 1 + xp 2 +... + xp n x 1 + x 2 +... + x n mod p). Therefore, LHS RHS mod p). 11
8. Simple But Not Easy 10 points) Prove that, for any positive integer n, 3 + ) n 5 + 3 n is divisible by 2 n. Answer: Use strong induction with two base cases to prove the statement. Base case n 1 and n 2): 3 + ) 1 5 + 3 1 6 is divisible by 2 1 2; 28 is divisible by 2 2 4. Inductive hypothesis: assume Inductive step: 3 + ) i 5 + 3 i is divisible by 2 i for all i, 1 i k. 3 + ) 2 5 + 3 2 3 + ) k+1 5 + 3 ) k+1 5 3 + k + 3 ) k 3 + ) 5 + 3 )) 5 3 ) 5 3 + ) k 5 3 + ) 5 3 ) k 5 ) 2 k a 6) 3 ) 5 3 + ) 5 3 + ) k 1 5 3 + ) 5 3 ) 5 3 k 1 for some integer a 2 k+1) 3a) 4 3 + ) k 1 5 4 3 k 1 for some integer a 2 k+1) 3a) 4 3 + ) k 1 5 + 3 ) ) k 1 5 for some integer a 2 k+1) ) 3a) 4 2 k 1 b for some integers a,b 2 k+1) 3a) 2 k+1) b) for some integers a,b 2 k+1) 3a b) for some integers a,b. By the principle of induction, the statement is proved. 12
9. TRUE or FALSE Ultimate and Bonus Round 15 bonus points) For the following statement, claim TRUE or FALSE first. If you claim TRUE, prove it. If you claim FALSE, disprove it. For any preference lists of 3 men and 3 women, it is impossible to have 5 or more stable pairings in the stable marriage problem. TRUE FALSE Answer: TRUE. There are total 3! 6 possible pairings. We will use proof by contradiction to prove the statement. Assume there are 5 or more stable pairings. Given the assumption, we first claim that, for any pair of a man and a woman, it must be in at least one stable pairing. We can prove this claim by another proof by contradiction: Assume the pair is not in any stable pairing. Then, there are only 4 possible pairings remaining 2 possible pairings are canceled out). For example, if 1,A) is not in any stable pairing, then there are only 4 possible pairings {1,A),2,B),3,C)} and {1,A),2,C),3,B)} are canceled out). It is a contradiction, so the claim is proved given the original assumption). By the claim, a man is paired with each woman in at least one stable pairing, so his optimal woman is the first woman in his preference list, and his pessimal woman is the last woman in his preference list. Without loss of generality we can switch the labels between 1,2,3 or between A,B,C), we can assign the preference lists left) and determine the rest preference lists right) as follows: Men Preference Lists Men Preference Lists 1 A >? > B 1 A > C > B 2 B >? >? 2 B > A > C 3 C >? >? 3 C > B > A Similarly, by the claim, a woman is paired with each man in at least one stable pairing, so her optimal man is the first man in her preference list, and her pessimal man is the last man in her preference list. To match preference lists of men, we can determine the preference lists as follows: Women Preference Lists A 3 > 2 > 1 B 1 > 3 > 2 C 2 > 1 > 3 However, {1,A),2,C),3,B)}, {1,B),2,A),3,C)}, and {1,C),2,B),3,A)} are not stable pairings because 2,A), 1,C), and 3,B) are rogue couples, respectively. As a result, it is a contradiction, so it is impossible to have 5 or more stable pairings. 13