CS442, Spring 2006, HW #5 Answers 1. (i) Cleaning up after a party : it depends on the mess, probably there's work for more than 3 "processors" cleaning up at the same time (so "no bound"). (ii) Writing a sonet : one "processor" : sonets are usually written by a single author because their tight structure is not amenable to sharing. (iii) Collecting firewood : no bound. (iv) Writing thank you notes after a big wedding: even though it's a lot of work and the work can be done in paralell by a lot of processors, only the bride and the groom should write thank you notes :) (so "2"). (v) If the list is big and the items are diverse, a lot of "processors" may work in parallel. 2. (i) We have 15 characters, 4 (smallest power of 2 that is bigger than 15) bits/character to encode all the characters. (ii) 11101111000011100011000100001101100101111011010100010. With spaces for easier reading: 111011 (m) 110 (e) 0001 (l) 110 (e) 001 () 100 (k) 010 (a) 0001 (l) 101 (i) 100 (k) 101 (i) 111011 (m) 010 (a) 100 (k) 010 (a). Note that the message is Hawaiian for "Merry Christmas". (iii) aloha (Hawaiian for "shalom"). (iv) For the passage mentioned in the beginning of the problem we need: 389x3 + 321x3 + 123x3 + 113x3 + 108x3 + 102x3 + 82x4 + 67x4 + 61x5 + 59x6 + 53x6 + 23x6 + 6x6 + 4x6 + 2x6=5251 total bits. The total number of characters is 1513, so there will be 5251/1513 = 3.47 < 4 bits/character. 4. What the "mate" code from the lecture does is: each of the child's bits is either the corresponding bit of its mom or the corresponding bit of its dad. More formally: bit i of the child is randomly chosen between bit i of Mom and bit i of Dad. So, if we look at the sequences of bits corresponding to Mom and the child and look at a certain bit (the bit at index i, for example), the alternatives are: - they are different: this means that bit i of the child was Dad's i-th bit (because it couldn't have come from Mom!), so Dad's i-th bit is the i-th bit of the child. - they are the same, so Dad's i-th bit can be anything because -> if Dad's i-th bit is the same, no matter how the "mate" code chooses between Mom and Dad, the bit is the same. -> if Dad's i-th bit is different, the code may have chosen the mom to be the one from which the bit is copyed in the child's i-th bit, revealing nothing about the value of Dad's bit. So, we know for sure the values of Dad's bits at the bit positions where Mom and Child are different. Dad will look like: x1111yz0, where x,y and z can be 0 or 1. Dads are given by all the possible combinations of {0,1}s for x, y and z. So, we get the following possible Dads: 01111000, 01111010, 01111100, 01111110, 11111000, 11111010, 11111100, 11111110. 5. (i) If we take the frequencies and construct the tree following the algorithm, we get the following tree: 0 _______ 1513______ 1 / \ / 634 / /\1 / / 313 / / /\1 / / / 190 879 / / /\1 / \1 0 / 0/ / 88 / 490 / / / /\1 0/ 0/ \1 / / 0/ / 35 / / 228 / / / / /\1 / 262 \1 / / / 0/ / 12 / / \1 120 / / / / 0/ /\1 / 0/ 149 0/ \1 / / / / / 0/ 6 / / 0/\ / 0/\ / / / / / / /\1 s k l u i h n a o e m p w v 389 113 82 67 108 61 59 321 123 102 53 23 6 2 4 character code -------------------- 00 k 0100 l 01010 u 01011 i 0110 h 011110 n 011111 a 10 o 110 e 1110 m 11110 p 111110 w 1111110 v 11111110 11111111 (ii) We'll need 389x2 + 321x2 + 123x3 + 113x4 + 108x4 + 102x4 + 82x4 + 67x5 + 61x6 + 59x6 + 53x5 + 23x6 + 6x7 + 4x8 + 2x8=4591 bits Bits/char = 4591/1513 = only 3.034 bits per character! 6. We need the following output: a b a and not b ---------------------------- 0 0 0 0 1 0 1 0 1 1 1 0 Let the weights be: wa = a -> output wb = b -> output w1 = 1 -> output f(a,b) = wa x a + wb x b + w1 x 1 f(a,b) has to be >=0 for a = 1 and b = 0 <0 for all the other possible values of a and b So, we have to find wa, wb and w1 so that : - wa + w1 > 0 - wa + wb < 0 - wb + w1 < 0 - w1 < 0 We can take for example wa= 4, wb = -5, w1 = -3. 7. A robot that's learning in the real world must decide, at each moment, what to do. Like the character in the poem, it can only try one of these options and the other it will never get to experience directly.