Disrete Strutures, Test 2 Mondy, Mrh 28, 2016 SOLUTIONS, VERSION α α 1. (18 pts) Short nswer. Put your nswer in the ox. No prtil redit. () Consider the reltion R on {,,, d with mtrix digrph of R.. Drw the d () For the reltion R from prt (), find the mtrix of R R. The mtrix of R R is given y the mtrix produt M R M R, where M R is the mtrix from prt (). Then reple ll nonzero entries with 1s. So ompute M R M R = is then. = 2 0 1 0. Now the nswer () Find the inverse funtion of f(x) = x + 9 (where the domin nd odomin re oth the set of rel numers). y = x + 9, so x = 1 (y 9), nd f 1 (x) = 1 x. (d) Let f nd g e funtions on the set of it-strings, defined y f(s) = 0s1 nd g(s) = s10. Compute f(g(11)). f(g(11)) = f(1110) = 011101. 4 (e) Compute (n 1). Your nswer should e in the form of n integer. n=1 4 (n 1) = (1 1) (2 1) ( 1) (4 1) = 0 1 8 27 = 0. n=1 1
(f) For R the reltion in prt (), write down the reltion R in terms of set of ordered pirs. R = {(, ), (, ), (, ), (, ), (d, ). (g) Let g e funtion from the integers to the integers given y g(n) = n/2. Is g one-to-one or onto or oth or neither? g is onto ut not one-to-one. g is onto sine for every integer n, g(2n) = n, nd so n is the the rnge of g. g is not one-to-one sine for exmple g(0) = g(1) = 0. (h) Let h e the funtion from {1, 2,, 4 to {,, given y {(1, ), (2, ), (, ), (4, ). Drw its rrow digrm. 1 2 4 (i) For the funtion h from prt (h), ompute h(). h() =. 2. (6 pts) Write n lgorithm min index(s, n) whih returns the index of the first ourrene of the smllest vlue of the sequene s 1,..., s n. So if s is 7, 0, 5, 0, 8, the output would e 2. min index(s,n){ j=1 // index of smllest vlue to e returned for i=2 to n{ if (s i < s j ) j=i return j. (8 pts) Consider the following lgorithm f f(s,n){ for i=1 to n-1 { if (s i < s i+1 ) return flse return true () Wht is the output for s = 10, 9, 5, 0 nd n = 4? Tre your steps. true. In the for loop, i goes from 1 to. For i = 1, we hek s 1 < s 2 is flse sine 10 9. For i = 2, we hek s 2 < s is flse sine 9 5. For i =, we hek s < s 4 is flse sine 5 0. So the for loop exists, nd the return vlue is true. 2
() Wht is the output for s = 7, 5, 0, 6, 9 nd n = 5? Tre your steps. flse. In the for loop, i goes from 1 to 4. For i = 1, we hek s 1 < s 2 is flse, sine 7 5. For i = 2, we hek s 2 < s is flse, sine 5 0. For i =, we hek s < s 4 is true, sine 0 < 6. So flse is returned from inside the for loop. () Desrie ll the sequenes for whih the return vlue is true. In other words, wht does this lgorithm ompute in terms of sequenes? This lgorithm returns true for sequenes whih re noninresing. In other words, we hve to hve s i s i+1 for ll i from 1 to n 1. 4. (24 pts) True/Flse. Cirle T or F. No explntion needed. () T F If R is the reltion whose digrph is elow, then R is trnsitive. d T. A quik justifition is to note tht R is equivlent to the prtil order of divides on {1, 2,, 4, under the mp {,,, d {1, 2, 4,. We know prtil orders re ll trnsitive. Otherwise, ompute the mtrix M R nd the mtrix 1 1 1 1 1 1 1 1 produt M R M R = 0 1 1 0 0 1 1 0 = 0 0 0 1 1 2 2 0 1 2 0 0 0 0 1 1 1 1 1 0 1 1 0 0 0 0 1. So the mtrix of R R is. Sine these mtries re the sme, R is trnsitive. (We need only hek tht for every 1 in the mtrix M R R, there is orresponding 1 in M R.) Alterntely, we n inspet the digrph to show tht for every pth of length 2, there is diret pth (of length 1) etween the orresponding verties.
i=1 () T F If R, S re oth reflexive reltions on set X, then R S is reflexive. T. Sine R nd S re oth reflexive, we hve x X, (xrx xsx). This is just the sme s x(r S)x, nd so R S is reflexive. () T F If R, S re oth prtil orders on set X, then R S is prtil order. F. For for exmple R is nd S is on the integers, then R S is just the reltion Z Z, whih is not prtil order (sine it is not ntisymmetri). (d) T F If R is prtil order on set X, then R 1 is lso prtil order. T. Chek: R 1 is reflexive sine xr 1 x is the sme s xrx, whih is lwys true sine R is reflexive. R 1 is ntisymmetri, sine if x, y X, then xr 1 y yr 1 x is the sme s yrx xry. Sine R is ntisymmetri, this implies y = x. Therefore, R 1 is ntisymmetri s well. We showed in Quiz 6, question 4, tht R trnsitive implies R 1 trnsitive. Thus R 1, sine it is reflexive, ntisymmetri, nd trnsitive, is prtil order. (e) T F Let f e funtion from the rel numers R to R, given y f(x) = x 2. Then f is ijetion. T. It inverse is f 1 (x) = 1 (x + 2). (f) T F Let g e funtion from the integers Z to Z, given y g(n) = n 2. Then g is ijetion. F. g is not onto, sine there is for exmple no integer n so tht g(n) = n 2 = 0. (The only rel solution is n = 2, whih is not n integer.) (g) T F Let the domin of disourse e the set of strings on the set X = {0, 1 of its. Then x y( xy = y ). T. x = λ the empty string works. (h) T F Let the domin of disourse e the set of strings on the set X from prt (g). Then x y( xy = y ). F. x = 0 is ounterexmple (note x = 1). Then xy = x + y = 1 + y is never equl to y. 10 (i) T F i 2 is even. (This one n e done without lultor.) F. The sum 1 2 + 2 2 + 2 + 4 2 + 5 2 + 6 2 + 7 2 + 8 2 + 9 2 + 10 2 is the sum of 5 odd numers nd 5 even numers, whih must e odd. (j) T F The reltion R from prt () is symmetri. F. For exmple, R ut R. 4
(k) T F There is n equivlene reltion on the lphet with extly 5 distint equivlene lsses. T. For exmple, onsider the equivlene reltion whose equivlene lsses onsist of {,,, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v nd {w, {x, {y, {z. (l) T F There is n equivlene reltion on the lphet with extly 0 distint equivlene lsses. F. The equivlene reltion must orrespond to prtition of the lphet, whih hs 26 letters. Sine elements of the prtition (whih re the equivlene lsses) re nonempty disjoint susets, there n e t most 26 distint equivlene lsses. 5