CPSC 070 Aswer Keys Test # October 1, 014 1. (a) (5) Defie (A B) to be those elemets i set A but ot i set B. Use set membership tables to determie what elemets are cotaied i (A (B A)). Use set membership elemets are cotaied i (B (A B)). A B B-A A (B A) A B A-B B (A B) 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 0 0 There are o elemets i A (B A). Null set. There are o elemets i B (A B). Null set (b) (5) What ca you say about the sets A ad B give the iformatio below. You should use statemets like A B or A = B or B A or No coclusio or A B = φ or A = φ or B = φ. A B = A? A B = A? A B = B A? A B = A? A B = B A? B = φ or B A A B A = B A B = φ No coclusio. (5) List the values of the sets below. Let A = { : P 5} = {1,4,9,16,5} ad B = { 4 : P 5} = {1,16,81,56,65} A B = {1, 4, 16, 5, 81, 56, 65} B A = {81, 56, 65} A B = {1, 16} A B = {4, 9, 5, 81, 56, 65} A B = {4, 9, 5} 3. (10) Cosider sets A = { 1, 3, 7 }, B={ a, b } ad C={ &, ^ }. Eumerate the members of the Cartesia product: B A C : {(a,1,&), (a,1,^), (a,3,&), (a,3,^), (a,7,&), (a,7,^), (b,1,&), (b,1,^), (b,3,&), (b,3,^), (b,7,&), (b,7,^)} C B A : {(&,a,1), (&,a,3), (&,a,7), (&,b,1), (&,b,3), (&,b,7), (^,a,1), (^,a,3), (^,a,7), (^,b,1), (^,b,3), (^,b,7)} A C B : {(1,&,a), (1,&,b), (1,^,a}, (1,^,b}, (3,&,a), (3,&,b), (3,^,a), (3,^,b), (7,&,a), (7,&,b), (7,^,a), (7,^,b)}
4. (a) (10) Explai clearly why the fuctio: f(x) = e x or f(x) = x or f(x) = 10 x from the set of real umbers to the set of real umbers is ot ivertible, but if the codomai is restricted to the set of positive real umbers, the resultig fuctio is ivertible. Your reasos should be very clear ad specific. (Hit: sketch the graph.) f(x) = 10 x : Sice the fuctio s codomai is oly o the positive real umbers, attemptig to ivert this fuctio would result i somethig that is ot a fuctio from R R, sice the iverse would be udefied for egative iput. If we limit the codomai to oly positive reals, the iverted fuctio s domai is limited to ol positive reals ad it is defied o all iput withi this domai. (Adrew Zhag) f(x) = x : For a fuctio to be ivertible, it must be oe- to- oe ad oto. For all egative real umbers (say x = - ), x = 1/. x will ever be egative ad therefore does t map to egative R i the codomai. It s ot ivertible (ca t take the iverse). However, whe the codomai is oly positive real umbers, x will yield a value for all real umbers that always maps to that codomai (positive real umbers). (Mary Grace Gle) (b) (5) As suggested i part (a) above, let the codomai of f(x) be restricted to the set of positive real umbers. Let g(y) be the iverse of f(x) described above. Defie g(y). That is: f(x) = e x f(x) = x f(x) = 10 x g(y) = l(y) for domai R + ad codomai R g(y) = log(y) for domai R + ad codomai R g(y) = log10(y) for domai R + ad codomai R 5. Use mathematical iductio to show that: i = +1 1 i=0 (5) Basis Step: Let =0. Left had side: i = 0 = 1 Right had side: 0+1 1 = 1 = 1 i=0 Therefore, the equatio is true for =0. (10) Iductive Step: Assume equatio is true for =k. Prove true for =(k+1). k k+1 Assume: i = k+1 1 To prove: i = (k+1)+1 1 = (k+) 1
Proof: k+1 k i = i + k+1 = ( k+1 1) + (k+1) by the assumptio above = * ( k+1 ) 1 = (k+) 1 Therefore, the equatio is true for all k. + 1 k ar a ar =, r 1 k = 0 6. (15) Cosider the followig closed form solutios to sums: r 1 1 j = 0 + 1+... + = ( + 1)/ 3 ( + ) j= 0 k = k = 1 4 Use the formulas above to evaluate the followig sums. Show clearly how you arrived at your aswer. Specify which formula you used. (a) Use equatio above. 19 8 36 + 40 + 44 + 48 + + 516 = 4 (9 + 10 + + 19) = 4 ( i i ) = 4[(19*130/) (8*9/)] 19 9 40 + 44 + 48 + 5 + + 516 = 4 (10 + 11 + + 19) = 4 ( i i ) = 4[(19*130/) (9*10/)] 19 10 44 + 48 + 5 + 56 + + 516 = 4 (11 + 1 + + 19) = 4 ( i i ) = 4[(19*130/) (10*11/)] (b) Use equatio 1 above. 1 + 3 + 9 + 7 + 81 + 43 + + 79 = 3 0 + 3 1 + 3 +3 3 + + 3 6 => a=1, r=3, =6 = (3 7 1)/ 1 + 3 + 9 + 7 + 81 + 43 + + 187 = 3 0 + 3 1 + 3 +3 3 + + 3 7 => a=1, r=3, =7 = (3 8 1)/ 1 j j= 0 = 0 + 1 +... + = ( + 1)( + 1)/6
Expad the followig double summatio ad calculate the sum. 3 (c) (i j) = [(i 0) + + (i 1) + (i ) + (i 3)] = (4i 6) i=1 j=0 i=1 i=1 = 4 i 6 = 4(1 + ) (6) = 1 1 = 0 i=1 i=1 3 3 3 (i j) = [(i 0) + (i 1) + (i )] = (3i 3) i=1 j=0 i=1 i=1 3 3 = 3 i 3 = 3(6) 9 = 9 i=1 i=1 3 (i j) = [(i 1) + (i ) + (i 3)] = (3i 6) i=0 j=1 = 3 i 6 = 3(1 + ) 3(6) = 9 18 = 9 7. (10) Software Correctess. The goal of oe of the verificatio coditios that arise i verifyig a example piece of code is the followig, where S ad S are some strigs: ( S' + 1) Max_Depth; The gives are: I. S Max_Depth; II. S > 0; III. S = <X> o S ; Which of the above gives are ecessary ad sufficiet to prove the goal? (a) I oly, (b) II oly, (c) III oly, (d) I ad II oly, (e) I ad III oly Aswer: (a) 5 pts, (c) 5 poits, (e) 10 poits 8. (10) Specify the order of complexity of each of the followig algorithms. Select amog: O(1), O(log ), O(), O( log ) O( ), O( 3 ), O( ), O(!), Noe of the above. O() Calculatig the average of a array of itegers. O(1) Fidig the largest value i a sorted array of itegers. O(log ) Fidig a specific value i a sorted array of itegers. O( ) Sortig a array of itegers usig Bubble Sort. O( ) Pritig the values of a ( x ) array. O() Takig the sum of the diagoal of a ( x ) array. O( ) Pritig all values of a - bit register. O(!) Pritig all permutatios of the elemets of a set with values.
O( ) O() Takig the sum of the diagoal of a ( x ) array plus all values above the diagoal. Pritig the elemets of oe of the diagoals of a ( x x ) array. 9. (10) Evaluate the expressios below. Your aswer should ivolve oe or more of the followig letters: M, G, T, Z, P, E, K, Y. The first oe has bee doe for you. 9 = 51M log(64p) * 3 = log( 6 * 50 ) * ( 5 ) = log( 56 ) * 10 = 56K log(t/18k) = log( 40 / 17 ) = log( 3 ) = 3 (M / G) * (Y / K) = ( 0 / 30 ) * ( 80 / 10 ) = (1 / 10 ) * ( 70 ) = 60 = E ( 57 / 16 10 ) * 51 = ( 57 / ( 4 ) 10 ) * 9 = ( 57 / 40 ) * 9 = 6 = 64M Number of ways you ca aswer a T/F test with 48 questios. = 48 = 56T 39 = 51G log(64y) * 8 4 = log( 6 * 80 ) * ( 3 ) 4 = log( 86 ) * 1 = 86*4K = 344K Number of ways you ca aswer a T/F test with 68 questios. = 68 = 56E log(p/18k) = log( 50 / 17 ) = log( 33 ) = 33 (M / G) * (P / G) = ( 0 / 30 ) * ( 50 / 30 ) = (1 / 10 ) * ( 0 ) = 10 = K ( 77 / 3 8 ) / 51 = ( 77 / ( 5 ) 8 ) / 9 = ( 77 / 40 ) / 9 = 37 / 9 = 8 = 56M 19 = 51K log(64p) * 3 4 = log( 6 * 50 ) * ( 5 ) 4 = log( 56 ) * 0 = 56M ( 67 / 3 8 ) / 51 = ( 67 / ( 5 ) 8 ) / 9 = ( 67 / 40 ) / 9 = 7 / 9 = 18 = 56K Number of ways you ca aswer a T/F test with 8 questios. = 8 = 56M log(p/64m) = log( 50 / 6 ) = log( 4 ) = 4 (M / K) * (Z / G) = ( 0 / 10 ) * ( 70 / 30 ) = ( 10 ) * ( 40 ) = 50 = P