CS1800 Discrete Structures Fall 2017 October, 2017 CS1800 Discrete Structures Midterm Version A Instructions: 1. The exam is closed book and closed notes. You may not use a calculator or any other electronic device. 2. The exam is worth 100 total points. The points for each problem are given in the problem statement and in the table below. 3. You should write your answers in the space provided; use the back sides of these sheets, if necessary. 4. SHOW YOUR WORK FOR ALL PROBLEMS. 5. You have two hours to complete the exam. Section Title Points Section 1[14 points] Binary and Hexadecimal Section 2 [13 points] Logic Section 3 [15 points] Proof Section 4 [18 points] Modular Arithmetic & Algorithms Section 5 [10 points] Modular Cryptosystems Section 6 [10 points] Sets and Counting Section 7 [20 points] Permutations and Combinations Total Name: CS1800 (Lecture) Instructor: 1
Section 1 [14 pts: 4, 5, 5]: Binary, Octal, and Hexadecimal 1. Convert the binary number 100010101001 to decimal and hexadecimal. Solution: 2217 10, 8A9 16 2. Suppose that we prohibit leading zeroes in all number representations. In other words, 2017 would be a valid decimal number, but 02017 would not; 3AF would be a valid hexadecimal number, but 003AF would not; and so on. Now suppose that you are given a length 4 hexadecimal number where leading zeroes are prohibited, and you convert this number to binary. What is the minimum and maximum number of bits in the binary representation, again assuming that leading zeroes are prohibited? Explain. Solution: The least significant 3 hex digits correspond to 12 bits. The most significant hex digit can be 1 to 4 bits. Thus, the answer is 13-16 bits. 3. Convert the decimal number 46 to 8-bit 2 s complement. Convert the number 13 to 8-bit 2 s complement. Now perform the operation 46 13 in 8-bit 2 s complement. Verify that your result in 8-bit 2 s complement is correct, i.e., 33. Solution: 00101110, 11110011, 00100001, 32 + 1 = 33. 2
Section 2 [13 pts: 4, 4, 5]: Logic 1. Recall that a NAND b is (a b). Construct the truth table for (a NAND b) NAND c. Solution: Let F = (a NAND b) NAND c. a b c F 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 1 2. Give the Boolean formula for (a NAND b) NAND c using only the variables a, b, c and operators and. Now apply DeMorgan s Law as much as possible to simplify this expression. Solution: ( (a b) c) = (a b) c 3. Simplify the expression ((a b) ( a b)) a. Solution: This is actually simply (a XNOR b) a, and since XNOR requires its inputs to be the same to be satisfied, this is a b. One could also derive the simplification as: ((a b) ( a b)) a (a b) ( a b) a ( a b) (a b) a a (a b) a b 3
Section 3 [15 pts (8,7)]: Proofs 1. Prove that if a is relatively prime to n, then there is some b such that ((n a)(n b)) mod n = 1. Solution: Multiplying out, we get (n a)(n b) = n 2 an bn + ab, which mod n is equal to just ab. If a is relatively prime to n, we know it has a multiplicative inverse mod n. By the definition of a multiplicative inverse, this is a number b such that ab mod n = 1. Thus, the multiplicative inverse is the number desired. 2. Prove that ( )( n n q ( q t q) = n t t)( q), assuming n t q. Solution: Both sides count in how many ways can we choose a football team of q and a hockey team of t q from a set of n students. LHS: choose the football team first, then the hockey team from remaining students RHS: choose both teams as a set of size t q + q first, then choose the football team out of the selected set; the hockey team is what has been selected the first time but not the second time Algebra solution: ( )( ) n n q n! (n q)! = q t q q!(n q)! (n t)!(t q)! = n! q!(n t)!(t q)! = n! t! t!(t q)! q!(t q)! = ( n t )( t q ) 4
Section 4 [18 pts: 5,3,3,5,2]: Modular Arithmetic and GCD algorithms 1. Calculate 5 33 mod 7 via repeated squaring. Solution: 5 2 = 25 = 4 5 4 = 4 2 = 16 = 2 5 8 = 2 2 = 4 5 16 = 4 2 = 16 = 2 5 32 = 2 2 = 4 5 33 = 4 5 mod 7 = 20 mod 7 = 6 2. Perform the Euclidean algorithm (not extended) to find gcd(1233, 54). Solution: gcd(1233, 54) = gcd(54, 45) = gcd(45, 9). 9 divides 45, so the gcd is 9. 3. Using the result of the previous problem, what is lcm(1233,54)? (You can leave your answer unsimplified.) Solution: (1233*54)/9 = 1233*6 = 7398. 4. Perform the Extended Euclid algorithm to find x and y such that 19x + 17y = 1. Solution: a b x y d 19 17-8 9 1 17 2 1-8 1 2 1 0 1 1 1 0 1 0 1 5. Using the result of the previous problem, what is the multiplicative inverse of 17 mod 19? Solution: By the previous question s result, 9. 5
Section 5 [10 pts: 4,6]: Modular Cryptosystems 1. What is the smallest possible RSA public key value e 2 that works for n = 101 103 = 10403? Solution: The number needs to be relatively prime to φ(n) = 100 102 = 10200. 2 and 5 clearly don t work, so 4 also isn t relatively prime; a quick division shows 3 doesn t work either; but 7 doesn t go in evenly, so it s 7. 2. Consider valid linear ciphers of the form ax + b mod 35. (A cipher is valid if it is possible to create a unique decryption function. The null cipher a = 1, b = 0 is also considered valid here.) (a) How many different values are possible for b? (b) How many different values are possible for a? (c) How many different linear ciphers of this form are possible? Solution: (a) b can be anything in [0,34], so 35. (b) a must be relatively prime to n, so φ(35) = 4 6 = 24. (c) 24 35 = 840. 6
Section 6 [10 pts: 3,3,4]: Sets and Counting 1. Simplify ((A B) (C B)) A. Solution: 2. If A = 10, B = 6, and A B = 4, what is the size of P((A B) (A B))? Solution: 2 10+6 4 4 = 2 8 = 256 3. A deck of 52 cards contains cards with 13 possible values, 4 of each. How many cards must be drawn to guarantee a three-of-a-kind? Solution: 27, by the generalized pigeonhole principle. 7
Section 7 [20 pts: 3,5,8,4]: Permutations and Combinations For this section, you can leave your answers unsimplified. 1. How many top-5 rankings (1st through 5th place) are possible with 12 contestants? Solution: P(12,5) = 12*11*10*9*8 2. How many 5-digit pins are possible if exactly two digits are the same, with no other digits repeated? ( Solution: 5 ) 2 = 10 locations for the repeated digits, 10 possibilities for its identity, and the other digits are 9*8*7. 10 2 9 8 7 = 50400. 3. 20 students are told to split into four study groups: one of size 7, two of size 5, one of size 3. In how many different ways can they form the groups? (There s no ordering to the groups - arrangements are considered the same if everybody s teammates would be the same.) Solution: Choose the first group ( ( ) 20 7 ways) then the second group from remaining students ( ( ) ( 13 5 ways) and the third group ( 8 5) ways); the last group has no choice but the remaining 3. Apply product rule: ( ) ( 20 7 13 ) ( 5 8 ) 5 = 20! 7!5!5!3!. But every grouping has been counted twice, because the two groups of 5 are interchangeable without changing the answer. So the final answer is 1 20! 2 7!5!5!3!. 20! Solution variation: pics the groups of sizes 7,3,10 in 7!3!10!, Then compute the number of ways to split 10 into two subsets of 5 each (like weights partition problem ). That is 1 10 ) 2( 2 ways. 4. A book with 200 pages is to be organized into 8 chapters, but the editor does not like any chapter smaller than 10 pages. In how many ways can the pages be grouped into chapters to satisfy the editor constraint? Solution: This is balls in bins with the condition that the bin-counts have to be at least 10. So its not really 200 pages that are distributed since 8*10 of them are guaranteed as minimum 10 in each of the 8 chapters. The total ways to do this is to distribute 200-80 pages into 8 chapters; that is ( ) 120+8 1 8 1. To get the actual chapter sizes we take any resulted bin-count and add 10 to each bin. 8