



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The algorithmic problem solving exam from the university of nottingham, school of computer science, level 1 module, autumn 2009-2010. The exam includes multiple-choice questions related to algorithmic problem solving concepts such as invariants, logical expressions, and game theory.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Time allowed 1 hour 30 minutes
Candidates must NOT start writing their answers until told to do so. Model Solutions
G51APS Turn over
Question 1: a) Assignment Expression Invariant? n := n+1 n mod 3 No, 0 mod 3 6 = 1 mod 3 n := n+21 n mod 7 Yes m , n := m+1 , n− 2 6 ×m + 3×n Yes m , n := m+1 , n− 2 3 ×m + 6×n No, 3×1 + 6× 2 6 = 3×2 + 6× 0 d , e := d , ¬e d = e No, (f alse = true) 6 = (f alse = f alse) Table 0.1 Fill in entries marked “?”
The second expression is an invariant of the assignment, since: (n mod 7)[n := n+21] = { assignment rule } (n+21) mod 7 = { 21 is a multiple of 7 } n mod 7. The third expression is an invariant of the assignment, since: (6×m + 3×n)[m , n := m+1 , n−2] = { assignment rule } 6 ×(m+1) + 3×(n−2) = { arithmetic } 6 ×m + 6 + 3×n − 6 = { arithmetic } 6 ×m + 3×n. b) (i) pg ≡ ¬ps (ii) ig ≡ (ig ≡ ¬is) (iii) is ≡ (is⇐pg) (iv) The following calculation shows that the portrait is in the gold casket. The inscription on the silver casket is false. We can’t say anything about the inscription on the gold casket. (pg ≡ ¬ps) ∧ (ig ≡ (ig ≡ ¬is)) ∧ (is ≡ (is⇐pg)) = { associativity and negation } (pg ≡ ps ≡ f alse) ∧ ((ig ≡ ig) ≡ is ≡ f alse) ∧ (is ≡ (is⇐pg)) = { reflexivity } (pg ≡ ps ≡ f alse) ∧ (is ≡ f alse) ∧ (is ≡ (is⇐pg)) = { definition of ⇐ } (pg ≡ ps ≡ f alse) ∧ (is ≡ f alse) ∧ (is ≡ is ≡ is ∨ pg) = { substitution of equals for equals, reflexivity } (pg ≡ ps ≡ f alse) ∧ (is ≡ f alse) ∧ (true ≡ pg)
Left Game Right Game “losing” or winning move Q 7 losing K 17 1 B 9 losing N 32 2 D 9 A or 2 Table 0.2 Fill in entries marked “?”
Question 3: a) (i) The assignment is: g , b , c := g− 1 , b+2 , c− 1 (ii) The expression 2 ×g + b is a valid example. (iii) The expression that denotes the total number of chameleons is g+b+c. We prove that it is an invariant of the assignment as follows: (g+b+c)[g , b , c := g− 1 , b+2 , c−1] = { assignment rule } (g−1)+(b+2)+(c−1) = { arithmetic } g+b+c. b) (This question is derived from the courseworks.) Two strategies for taking the two slowest across are to take them separately, using the fastest to carry the torch, or to let them cross together, using the two fastest to return the torch to the initial bank. In this case, it is better to let them cross together. This gives the sequence: 〈p 1 ,p 5 〉, [p 1 ] ,〈p 15 ,p 20 〉, [p 5 ] (Angle brackets indicate a crossing in one direction, square brackets a crossing in the other direction.) After this sequence, just the two slowest have reached the opposite bank, and the torch is at the initial bank. Now the two slowest are p 8 and p 10. For these, the optimal strategy is to let them cross separately, with the fastest carrying the torch. This gives the sequence: 〈p 1 ,p 8 〉, [p 1 ] ,〈p 1 ,p 10 〉, [p 1 ] The process is completed by p 1 and p 5 crossing together: 〈p 1 ,p 5 〉. The total time taken is 5+1+20+5+8+1+10+1+5 , i.e. 56 minutes.
Question 4: a) (i) Consider the two closest neighbours A and B (the pair of closest neighbours is unique, since all distances are different). Because there is no one closer to A than B and no one closer to B than A , they must shoot each other. This leaves the third person dry. (ii) Assume that for an odd number n of people, suitably located so that, for each of them, all the others are at a different distance away, we have that one lucky person does not get wet after the firing signal. This is the induction hypothesis. We now have to prove that the property holds for n+2 people (remember that n is odd). Consider the two closest neighbours A and B (the pair of closest neighbours is unique, since all distances are different). Because there is no one closer to A than B and no one closer to B than A , they must shoot each other. This leaves us with n people, where n is odd and for each person, each of the others is still a different distance away. Therefore, the induction hypothesis implies that there is some person X who does not get wet. Note that the presence of A and B , who shoot each other, would not induce anyone to shoot X; if anything, the only effect of introducing A and B would be to draw off the fire of those members who happen to have A or B as their nearest neighbour. In any case, X remains dry. (Since the claim holds for n = 3 (see part (i)), the conclusion follows by induction for all odd n .) b) (i) N 1 6 ≡ O 2 (ii) N 2 6 ≡ O 3 (iii) O 4 6 ≡ L 2 (iv) The following calculation shows how to deduce the final positions. (N 1 6 ≡ O2) ∧ (N 2 6 ≡ O3) ∧ (O 4 6 ≡ L2) = { conjunction distributes over inequivales } ((N 1 6 ≡ O2) ∧ N 2 6 ≡ (N 1 6 ≡ O2) ∧ O3) ∧ (O 4 6 ≡ L2) = { conjunction distributes over inequivales } (N 1 ∧ N 2 6 ≡ O 2 ∧ N 2 6 ≡ N 1 ∧ O 3 6 ≡ O 2 ∧ O3) ∧ (O 4 6 ≡ L2) = { pm ∧ pn ≡ m = n and pn ∧ qn ≡ p = q } (f alse 6 ≡ f alse 6 ≡ N 1 ∧ O 3 6 ≡ f alse) ∧ (O 4 6 ≡ L2) = { f alse is the unit of inequivales } (N 1 ∧ O3) ∧ (O 4 6 ≡ L2) = { conjunction distributes over inequivales } N 1 ∧ O 3 ∧ O 4 6 ≡ N 1 ∧ O 3 ∧ L 2 = { pm ∧ pn ≡ m = n and f alse is the unit of inequivales } N 1 ∧ O 3 ∧ L 2. So, according to the calculation, Nancy won the race, Lucy was second, and Opey was third. Since there are four girls, we can also deduce that Minnie was last.
G51APS End