Discrete Structures, Final Exam Monday, May 11, 2009 SOLUTIONS 1. (40 pts) Short answer. Put your answer in the box. No partial credit. [ ] 0 1 (a) If A = and B = 1 0 [ ] 0 0 1. 0 1 1 [ 0 1 1 0 0 1 ], compute A B. (b) The following digraph represents a tree. Which vertex is its root? C. (c) For the tree given below, list all the siblings of v 2. v 1, v 6. (d) Draw the Hasse diagram of the poset (P(S), ) for S = {x, y}. (e) Two fair dice are rolled. What is the probability that the sum of the two rolls is even? 1/2. One way to see this is to list out all the 36 possibilities and note that 18 of them have an even sum (so the probability is 18/36 = 1/2. Alternately, 1
you can reason as follows: If the two dice are rolled separately, then no matter what the first die says, there is a 1/2 probability of the second die making the sum even: if the first die is odd, then there is a 1/2 chance that the second die is odd also, making the sum even; on the other hand, if the first die is even, there is a 1/2 chance that the second die is even also, making the sum even again. So no matter what the first die gives, there is a 1/2 chance of having the second die make the sum even. (f) What is the number of nonisomorphic binary positional trees of height 2? 21. This takes a little work. First of all, consider the case of nonisomorphic binary positional trees of height 1: There are 3 = 2 2 1 cases here, represented by the pictures below. (Note the fourth case, where the root has neither a left nor a right node, is height 0, not height 1). Once we have analyzed the height-1 trees, we need to analyze how to add another level to make them height-2. For the two height-1 trees with just one offspring from the root, there are each 3 ways to do this (corresponding to tacking on the height-1 trees to the single leaf). The remaining height-1 tree is different: it has 2 leaves, and so there are 4 places to put level-2 offspring (each leaf has a left and right place). This means there are 2 4 = 16 ways to put in these offspring, but we must rule out the single case of no level-2 offspring to leave us with 15. So in total there are 2(3) + 15 = 21 possible nonisomorphic binary positional trees of height 2. (g) Compute the combination 6 C 4. Your answer should be in the form of an integer. 6 C 4 = 6! = 720 = 15. 4!2! 24 2 (h) Let T be a tree with root v 0. If w is a vertex of the tree different from v 0, what is the in-degree of T at w? 1. 2
(i) What is the Θ class of n(n lg n+ 3 n+1500)? Your choices are Θ(n lg n), Θ(n), Θ(n 5 6), Θ(n 1 2), Θ(n 3 2 lg n) and Θ(1). Θ( n(n lg n + 3 n + 1500)) = Θ(n 3 2 lg n + n 5 6 + 1500n 1 2) = Θ(n 3 2 lg n). (The last equality is because the second and third terms have lower Θ class than the first: Note Θ(n 3 2 lg n) > Θ(n 3 2) since Θ(lg n) > Θ(1). Moreover, Θ(n 3 2) > Θ(n 5 6) > Θ(n 1 2) = Θ(1500n 1 2) by comparing the exponents of the powers of n.) (j) Given the digraph of the Moore machine below, what is f 10 (s 0 )? s 1. (k) List all the acceptance states of the Moore machine above. s 2, s 3. (l) What is the number of ways the letters of the word carp can be permuted? Express your answer as an integer. 24. The word carp has 4 distinct letters, and so the number of permutations is 4! = 24. (m) If a 0 = 3, a 1 = 2, and a n is defined recursively by a n = 2a n 2 + a n 1 for n 2, what is a 3? a 3 = 2a 1 + a 2 = 2(2) + (2a 0 + a 1 ) = 4 + [2(3) + 2] = 12. (n) If M = 1 0 1 0 0 1 0 1 0 of R in the box. is the matrix of a relation R on {1, 2, 3}, draw the digraph (o) What is the matrix of the symmetric closure of the relation R from part (n)? 1 0 1 0 0 1. This is the same as M M. 1 1 0 (p) What is the matrix of the transitive closure of the relation R from part (n)? 1 1 1 0 1 1. You can compute this using Warshall s algorithm, or 0 1 1 the formula M M 2 M3, or by simply looking at the digraph to see that there 3
are paths from 1 to 2 (1 3 2), from 2 to 2 (2 3 2), and from 3 to 3 (3 2 3). (q) What is the number of four-letter passwords, consisting of all lowercase letters, that can be formed? (You do not have to simplify your answer.) 26 4. This is because repetition is allowed and order matters. So for each letter of the password, there are exactly 26 choices. (r) Draw the Hasse diagram of a poset which is not a lattice. This poset is not a lattice since a, b have no LUB. (s) Write the decimal number 13 in binary (base two). 13 = (1101) 2. (t) If f 0 and f 1 are functions in a finite-state machine with inputs {0, 1}, then the composition f 0 f 1 is equal to (your answer should be one of: f 0, f 1, f 01, f 10 ). f 10. 2. (a) (4 pts) Write the labeled positional binary tree corresponding to the fully parenthesized expression (((x + 2)/((3 4) (y y))) + 5) (b) (4 pts) Write the result of a POSTORDER search on the tree in part (a) above. x 2 + 3 4 y y / 5 + 3. (5 pts) Given the standard ordering on digits 0 < 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9, write the following strings of digits in lexicographic order. (This is not necessarily the same as numerical order.) 107 1073 5233 905 93 1073 107 93 5233 905 4
4. (a) (3 pts) Fill in the blanks in the following table n (2n) mod 5 (2n + 1) mod 5 0 0 1 1 2 3 2 4 0 3 1 2 4 3 4 (b) (7 pts) Draw the digraph of a Moore machine which accepts only those positive binary integers (strings of 0 s and 1 s) which are divisible by 5. The input set should be {0, 1}, and you will need five states s 0, s 1, s 2, s 3, s 4. The state s i should be represent binary integers which are equal to i mod 5. (Hint: If n is an integer written in binary, then the concatenation n 0 represents 2n in binary, while n 1 represents 2n + 1 in binary. Relate this to the table above.) 5. (12 pts) Consider the Moore machine with acceptance state T = {s 2 } and state transition table 0 1 s 0 s 1 s 1 s 1 s 1 s 2 s 2 s 2 s 2 (a) Draw the digraph of this Moore machine. 5
(b) Describe in words the language of the Moore machine above. All strings of bits which contain at least one 1 which is not the first bit. (c) Give a regular expression on {0, 1} whose regular set is the language of the Moore machine above. (0 1)0 1(0 1). (d) Write, in BNF, a phase structure grammar which gives the same language as the Moore machine above. s 0 ::= 0 s 1 1 s1 s 1 ::= 0 s 1 1 s2 s 2 ::= 0 s 2 1 s2 Λ 6. (8 pts) Consider the Boolean function f = f(x, y, z, w) given by this table x y z w f 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 (a) In the space below, draw the Karnaugh map for f. (b) Use the Karnaugh map from part (a) above to find a Boolean expression for f. Your expression should be as simple as possible. Justify your answer. (x y z ) (y w ). 7. (4 pts) Consider the relation R on A = {a, b, c, d, e} whose matrix is 1 0 0 0 1 0 1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 1 Is R an equivalence relation on A? If so, write down the partition of A corresponding to R. If not, explain why not. 6.
R is an equivalence relation corresponding to the partition {{a, e}, {b, c}, {d}} of A. 8. (6 pts) Let A = { 1, 0, 1}, a subset of the integers, and consider the mathematical structure (A, +, ), where + and are addition and multiplication. (a) Is A closed under? Why or why not? A is closed under since the product of each two elements of A is again an element of A. (b) Is A closed under +? Why or why not? A is not closed under + since e.g. 1 + 1 = 2 / A. 9. (8 pts) Consider S = {1, 2, 3, 6, 12} with the partial order of divisibility. (a) Draw the Hasse diagram of the poset S. (b) Is the poset S a lattice? Why or why not? S is a lattice, since the GLB and LUB always exist for each pair of elements of S. 10. (40 pts) True/False. Circle T or F. No explanation needed. For questions (a)-(e) below, consider the following master syntax diagram for a phase structure grammar G. 7
(a) T F abc L(G). F. Each string in the language must end in d. (b) T F abbcabbbcd L(G). F. You can never produce just two b s in a row (only an odd number). (c) T F ab(bb) c(ab(bb) c) d is a regular expression whose regular set is equal to L(G). T. (d) T F L(G) is a finite set of strings on {a, b, c, d}. F. L(G) is an infinite set, since for example any ab 2n+1 cd L(G) for n = 0, 1, 2, 3,.... (e) T F L(G) is a Type 3 language. T. It corresponds to a regular set, which implies it must be a Type 3 language. (f) T F If H = (V, S, v 0, ) is a phase structure grammar given by V = {v 0, x, y}, S = {x, y}, given by v 0 xv 0 x, v 0 y, then L(H) = {x n yx n n = 0, 1, 2,... }. T. The production must end in y, and identical numbers of x s are supplied on either side of y by repetitions of v 0 xv 0 x. (g) T F For H the grammar from part (f), the language L(H) is a Type 3 language. F. Any Type 3 language corresponds to a Moore machine, which has a finite number of states. Since the number of x s on either side of the y is the same for each string in the language, then the Moore machine would have to count the number of x s before the y and then produce the same number of x s afterward. Each different number of x s would require its own state (one state for each n = 0, 1, 2, 3,...) This cannot be accomplished by a finite-state machine. (h) T F If p, q are Boolean variables which are both true, what is (p q) q? F. (T T) T = (F T) T = T T = F T = F. (i) T F If h is the mod 11 function, then h(80) = 8. F. h(80) = 80 mod 11 = 3 8. (j) T F n! has lower Θ class than 10 n. F. As we discussed in class, n! has higher Θ class than any exponential function of n, since n! lim n =. 10 n 8
(k) T F The expression 6 3 + 3 2, in postfix notation, evaluates to be a prime number. T. Evaluate in postfix: 6 3 + 3 2 = 9 3 2 = 9 6 = 3, which is prime. (l) T F A tree, when considered as a relation on the set of its vertices, is always transitive. F. In a tree T, atb btc at/ c. (m) T F If B is a finite Boolean algebra represented by the three Boolean variables x, y, z, then the minterm of 001 is x y z. T. (n) T F Every linearly ordered set is a lattice. T. In a linearly ordered set, it is easy to show that GLB(a, b) = min(a, b) and LUB(a, b) = max(a, b). (o) T F If A is a subset of a universal set U, then Ā A =. T. (p) T F The greatest common divisor of 48 and 92 is 2. F. The GCD of 48 and 92 is 4. (q) T F Every finite poset has at least one minimal element. T. (r) T F Consider the phase structure grammar K with starting state v 0 and BNF given by v 0 ::= 01 0 w w ::= 11 w 1 v0 Then 011101 L(K). T. v 0 0w 011w 0111v 0 011101. (s) T F For K the grammar in part (r), 0w 011w. T. (t) T F For K the grammar in part (r), the language L(K) is the regular set of the regular expression 0(10 1110) 1. F. This regular expression excludes e.g. 01111101, which is in the language. A correct regular expression is 0(1(11) 0) 1. 9