CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, 2016 Instructions: CS1800 Discrete Structures Final 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. You have two hours to complete the exam. Section Title Points Section 1[12 points] Binary and Hex Section 2 [8 points] Logic and Circuits Section 3 [12 points] Modular Arithmetic and Prime Factors Section 4 [8 points] Sets Section 5 [14 points] Counting Section 6 [12 points] Probability Section 7 [12 points] Sorting, Searching, Sums Section 8 [14 points] Recurrences, Induction, Big-O Section 9 [8 points] Graphs Total Name: NU ID#: Section #: 1
Section 1 [12 pts. (4 each)]: Binary and Hex 1. How many bits are necessary to represent the number 1,000,000 in binary? (You do not need an extra bit for the sign.) 2. If a hex number consisting of 10 digits that are all letters (i.e., values greater than 9, for example, AFEFFABCDE or AAAAAFFFFF) is converted to binary, what is the maximum number of 0 bits that could be in the binary representation? 3. Sum 11100000 and 00100111, assuming two s complement is being used to represent negative numbers. Give the result in decimal. (The last 1 of the first number aligns with the first 1 of the second.) 2
Section 2 [8 pts. (3,2,3)]: Logic and Circuits 1. Use De Morgan s Law to rewrite (A B) (A B) so that the first clause does not use OR and the second clause does not use AND. 2. If C = {x : x A x / B} and D = {x : x / A x B}, what logical operator should go in the blank in the following description? C D = {x : x A x B} (Choose one of: AND, OR, XOR, NAND, NOR) 3. Draw a circuit that takes a 4-bit number and produces its one s complement (a number with all its bits flipped from 0 to 1 and vice versa). Assume a, b, c, d are the input bits from most to least significant, and a, b, c, d are the corresponding output bits; label these in your diagram. 3
Section 3 [12 pts. (4 each)]: Modular Arithmetic and Prime Factors 1. Recall that Fermat s Little Theorem states a p 1 = 1 (mod p) if p is prime, and that if the statement is not true for a, a serves as a witness that p is not prime. (If p is not prime, not every a is a witness.) Determine whether a = 11 is a witness for p = 12, using repeated squaring to find a p 1. You must show your work, including the result of finding a p 1. 2. Find the GCD of 1,000,002 and 60. 3. What is the GCD of 15 20 and a googol (one followed by a hundred zeros)? (You do not need to multiply it out.) 4
Section 4 [8 pts. (3, 5)]: Sets 1. If the universe is Z and N is the natural numbers including 0, describe the complement of N using set builder notation. 2. Use the union, intersection, and complement operators (but not, for example, set difference) to describe the set containing only items that are in exactly one of sets A, B, and C. 5
Section 5 [14 pts. 4, 4, 6]: Counting 1. A website requires users to have usernames with exactly 8 characters, 7 of which must be lowercase letters, and the eighth (which can occur at any position) must either be an uppercase letter or a period. How many possible usernames are there? (You don t need to multiply out the terms.) 2. At a family gathering of 8 people, one relative insists on taking one photo of every possible combination of people, ranging from each person alone to all eight people at once. (Only one photo is necessary per different collection of people, and every photo has at least one person in it. Nobody needs to stand behind the camera; it s on a timer.) How many photos must be taken? 3. Scrabble is a board game in which each player has a rack of 7 letters and tries to come up with high-scoring words to make with them. A friend has written a Scrabble-playing program that is very slow. Examining the code, it looks like the program checks, for every number of tiles k ranging from 1 to 7, all possible permutations of all possible collections of k tiles chosen from the 7 tiles on the rack, checking to see whether each permutation of each collection is a valid word. Write a formula that is a summation from k = 1 to 7 that describes how many permutations this program must check for a given set of 7 tiles. (You can assume the tiles are distinct, and ignore tiles that may already be on the board. Note that 0! is technically 1.) 6
Section 6 [12 pts. 6, 6]: Probability 1. What is the probability of rolling a sum of 4 or less on two six-sided dice? 2. Factory A produces twice as many self-driving cars per year as Factory B, and also has a lower rate of defects: only 3 in 100 cars produced there has a defect, while 6 in 100 cars at factory B have defects. Assume these are the only two factories that produce self-driving cars. Suppose you find a self-driving car produced this year, and it has a defect. What is the probability that it came from factory A? (If it helps you think about the problem, you can assume 3000 self-driving cars have been produced this year. For full credit, show your work using Bayes Theorem.) 7
Section 7 [12 pts. (4 each)]: Sorting, Searching, Sums 1. Consider an array of n distinct values in which the first n 1 values are sorted, and the last element is not. (It could be smaller than the first element, larger than element n 1, or anywhere in between.) Give the worst-case number of comparisons that Insertion Sort will perform in this scenario. You can give your answer in terms of big-theta if you wish to ignore low-order terms and constants. 2. What is the sum of the integers from -60 to 40 inclusive? 3. It so happens that every step of Euclid s algorithm reduces the larger of the two numbers to half its size (or smaller). Use this fact to give a big-o bound on the number of steps Euclid s algorithm must take overall, letting N be the larger of the two original numbers. 8
Section 8 [14 pts. (6, 4, 4)]: Recurrences, Induction, Big-O 1. Prove by induction that n i=1 3n 3 n+1. 2. It s possible to perform a Mergesort that divides the input into four arrays or lists to sort recursively instead of two. The merge of these still takes linear time. Give a recurrence that describes the worst-case running time of this algorithm. You don t have to solve for the running time. 3. Is 4 N = O(3 N )? Use the definition of big-o to show why or why not. 9
Section 9 [8 pts (4 each)]: Graphs 1. List the order in which vertices would be visited for the first time in a depth-first search starting from B in the graph above. If multiple vertices could be explored next, assume the DFS visits the vertex earlier in alphabetical order first; for example, from B, the DFS will visit F before G. 2. Recall that a spanning tree is a tree that connects all the vertices of the graph, and a minimal spanning tree is a spanning tree such that there is no spanning tree on the graph of smaller total weight. Does a minimal spanning tree always contain a cheapest (minimum weight) path between any two nodes in the graph? If so, explain why. If not, give a counterexample that uses four vertices or fewer, circling two vertices with a shortest path that is not in the minimal spanning tree. 10