CS442, Spring 2006, HW #4 Answers 1. It is not satisfiable. There is no way we can set values for a,b and c to make the formula be true. The easy (but tedious) way to check the answer is to try all 8 combinations. A more complex proof is to notice that "a" must be false (there is a "not a" clause). Since there is a "a or c" clause and "a" is false, "c" must be true. But, there's also a "a or not c" clause, so "c" must be false. Since it can't be both, the formula cannot satisfied. 2. (i) valid. (ii) not valid. (iii) valid 3. (i) Show 2 consecutive numbers in the list that are not in order (if such 2 numbers exist, the list is out of order). (ii) Show 2 repeated letters in the word (say the index of the letters in the word, for example, for the word "letter", indicate 3&4 (3rd and 4th letter)). (iii) Show the solution. (iv) Indicate the 3 words: 2 words and the third one being their concatentation. It is easy to check that the 3rd word is the concatentation of the 2 words and that all three are in the list. 4. Be creative. 5. (i) We have the words : spa, ran, shape, apt score = 4. (ii) If we switch "AN" and "AY" we get : ray, shape, spa, apt, yes, score = 5. You could also say that swapping "SK" and "AY" we get: has, shape, spa, apt, pay, score = 5. 6. while(condition) stays in the loop as long as condition is true. If condition is always true, the program will never halt. (i) condition is (n == n+1). This one is never true (no matter how you pick an integer n, it will never be equal to n+1) ANSWER: for any value of n, tuna1 will halt. (ii) condition is (n>10) so the program will halt if n ever gets < or = 10. Now, we have to look if that's ever possible. If it's impossible that n ever gets <=10, tuna2 will never halt. We will look at what happens inside the loop : n=n-1, so at each step, n decreases by 1. If, at the beginning, n is bigger than 10, tuna2 will loop (at each step decreasing n by 1) until n will eventually reach 10 and then it will stop looping, because the condition will become false; if at the beginning n <=10, tuna2 will stop because the condition is false. ANSWER: For any value of n, tuna2 will halt (iii) condition is (n < 40). What happens inside the loop: n is decreased by 1 at each step; if n is bigger or equal to 40 in the beginning, tuna3 will halt, because the condition is not true; if n<40 in the beginning, tuna3 will never stop because at each step n becomes smaller and smaller and there's no way it can get bigger or equal to 40, so that to make tuna3 halt. ANSWER : for n>=40 tuna3 halts. 7. L /\ L W /\ /\ W W L L /\ /\ /\ /\ L L L L L W L W /\ | | | | | /\ \ L W W W W W L L W L 8. (i) mystery1 (ii) mystery3 (iii) mystery2