G51APS Coursework 2: Algorithmic Problem Solving, Univ. of Nottingham, 2010/2011, Study notes of Mathematics

The second coursework for the module g51aps in computer science at the university of nottingham. It includes various algorithmic problems, such as matchstick games, logic puzzles, and induction problems. Students are required to answer all questions and submit their solutions by the deadline for feedback.

Typology: Study notes

2010/2011

Uploaded on 09/08/2011

russel85
russel85 🇬🇧

4.6

(5)

285 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
G51APS, Algorithmic Problem Solving
Coursework 2, 2010/2011
School of Computer Science
University of Nottingham
November 1, 2010
Abstract
This document details the second coursework for the module G51APS. The course-
work does not count towards the final assessment but, if submitted by the deadline,
will be marked and returned for feedback purposes.
Answer ALL questions.
1 Games
In these questions, we use the general rules for matchstick games. (A game is lost when a
player cannot move, and, at each turn, matches may only be removed from one pile.)
(i) (1 mark) A game is played with a single pile of matches. In each move, 1, 2 or 6
matches may be removed. For each n, 0 n < 21, determine whether a pile of n
matches is a winning or losing position.
(ii) (2 marks) For each n, 0 n < 21, determine the mex number of a pile of matches.
(iii) (2 marks) If the mex number of a position in a game is known, it is possible to
determine whether or not it is a winning position. How is this done? Explain your
answer: use the -and -characterisations of losing and winning positions.
(iv) (5 marks) Consider a game which is the sum of two games. In the left game, 1, 2,
3 or 4 matches may be removed at each turn. In the right game, 1, 2 or 6 matches
may be removed. In the sum game, a move is made by choosing to play in the left
game, or choosing to play in the right game.
The table below shows a number of different positions in this game. A position is
given by a pair of numbers: the number of matches in the left pile, and the number
of matches in the right pile.
1
pf3
pf4
pf5

Partial preview of the text

Download G51APS Coursework 2: Algorithmic Problem Solving, Univ. of Nottingham, 2010/2011 and more Study notes Mathematics in PDF only on Docsity!

G51APS, Algorithmic Problem Solving

Coursework 2, 2010/

School of Computer Science

University of Nottingham

November 1, 2010

Abstract This document details the second coursework for the module G51APS. The course- work does not count towards the final assessment but, if submitted by the deadline, will be marked and returned for feedback purposes.

Answer ALL questions.

1 Games

In these questions, we use the general rules for matchstick games. (A game is lost when a player cannot move, and, at each turn, matches may only be removed from one pile.)

(i) (1 mark) A game is played with a single pile of matches. In each move, 1, 2 or 6 matches may be removed. For each n, 0 ≤ n < 21, determine whether a pile of n matches is a winning or losing position.

(ii) (2 marks) For each n, 0 ≤ n < 21, determine the mex number of a pile of matches.

(iii) (2 marks) If the mex number of a position in a game is known, it is possible to determine whether or not it is a winning position. How is this done? Explain your answer: use the ∀-∃ and ∃-∀ characterisations of losing and winning positions.

(iv) (5 marks) Consider a game which is the sum of two games. In the left game, 1, 2, 3 or 4 matches may be removed at each turn. In the right game, 1, 2 or 6 matches may be removed. In the sum game, a move is made by choosing to play in the left game, or choosing to play in the right game. The table below shows a number of different positions in this game. A position is given by a pair of numbers: the number of matches in the left pile, and the number of matches in the right pile.

Left Game Right Game “losing” or winning move 10 20? 13 20? 12 5? 5 5? 37 43?

Table 1: Fill in entries marked “?”

For each position, state whether it is a winning or a losing position. For winning positions, give the winning move in the form Xm where “X” is one of “L” (for “left game”) or “R” (for right game), and m is the number of matches to be removed. You may assume that the pattern you observe in your solution to (iii) is repeated for all larger numbers of matches.

(iv) (5 marks) Consider a game which is the sum of two games. The left game is the one shown in fig. 1. In the right game, 1, 2 or 6 matches may be removed. In the sum game, a move is made by choosing to play in the left game, or choosing to play in the right game. The following table shows a number of different positions in this game. A position is given by a pair: the label of a node in the left game, and the number of matches in the right game. Complete the table by filling in, for each position, “losing” if the position is a losing position, or the label of one of the nodes in fig. 1, or the number 1, the number 2 or the number 3. If a label is entered, it means move to the node with that label in the left game, and if a number is entered it means remove that number of matches in the right game. (For example, “N” means move from the current position in the left game to the position labelled “N”; “1” means remove 1 match from the pile of matches.)

Left Game Right Game “losing” or winning move Q 7? K 22? F 9? L 9? D 8?

Table 2: Fill in entries marked “?”

For each position, state whether it is a winning or a losing position. For winning positions, give the winning move in the form Xm where “X” is one of “L” (for “left game”) or “R” (for right game), and m is the number of matches to be removed. You

may assume that the pattern you observe in your solution to (iii) is repeated for all larger numbers of matches.

2 Logic Puzzles

In a court case, there are two juvenile defendants, referred to as X and Y. It is known that exactly one of the defendants is guilty. The defendants know which of them is guilty, but the truth of their statements cannot be relied upon. The defendants make the following statements:

X: I am innocent. Y: Exactly one of us is telling the truth.

When answering the following questions, use the abbreviations GX and GY for X is guilty and Y is guilty, respectively, and SX and SY for X’s statement and Y’s statement (is true), respectively.

(i) (1 mark) Express formally the fact that exactly one of the defendants is guilty. Do not use disjunction or conjunction in your answer.

(ii) (2 marks) Express formally what fact you can infer from each of the defendants statements.

(iii) (2 marks) Using your answers to (i) and (ii), determine as much information as you can about the four quantities GX , GY , SX and SY. Make clear any cases in which you cannot determine the value.

3 Induction

In order to answer this question, you should first read section 3.5 of the lecture notes. The question below is about getting 2×n people across a bridge, section 3.5 deals with the problem when n is 2. A group of 2×n people wishes to cross a bridge. It is dark, and it is necessary to use a torch when crossing the bridge, but they only have one torch between them. The bridge is narrow and only two people can be on it at any one time. Each person takes a different amount of time to cross the bridge; when two cross together they must proceed at the speed of the slowest. The people are all numbered from 1 to 2×n, and person i takes ti minutes to cross. The torch must be ferried back and forth across the bridge, so that it is always carried when the bridge is crossed. You may assume that the people are ordered according to the time they take to cross, with person 1 being the fastest and person 2×n being the slowest. You may also assume that n is at least 1 (so there are at least two people).

(i) (5 marks) Describe an algorithm, based on induction on n, to get a group of 2×n people across the bridge. What is the base case and what is the induction hypothesis? Hint: The base case is trivial. Use section 3.5 of the lecture notes for the induction step. Note that you are not required to prove that the algorithm results in the optimal crossing time for arbitrary n but when specialised to the case n = 2 it should indeed be optimal.

(ii) (5 marks) Use the algorithm described in (i) to solve the problem with four people, who individually cross in 1, 5, 7, and 8 minutes. Use the notation pt for the person who takes time t to cross. So, p 1 is the one who takes 1 minute to cross, p 5 is the person who takes 5 minutes to cross, etc. Full marks can only be obtained by giving an algorithm that minimises the total time taken.

(iii) (5 marks) What is total time taken if in addition to the four people in (ii), four more people who individually cross in 10, 20, 30 and 40 minutes join the original group. Your answer should be based on the use of induction and results obtained earlier in (ii).

4 What to Submit and When

Your solutions should be submitted to the School Office by 3.00pm on Friday, 3rd De- cember. Feedback on this coursework will be made available in the lecture on Wednesday, 8th December.