CMPSCI 250: Introduction to Computation

Solutions to Second Midterm Exam Spring 2016

David Mix Barrington

Exam given 30 March 2016

Solutions posted 10 April 2016

Directions:

  Q1: 20 points
  Q2: 15 points
  Q3: 40 points
  Q4: 25+10 points
Total: 100+10 points

Question text is in black, solutions in blue.

Here are definitions of some terms, sets, predicates, and statements used on this exam.

Remember that the scope of any quantifier is always to the end of the statement it is in.

Remember that a natural is a non-negative integer, so that the set N or all naturals is {0, 1, 2, 3,...}.

A binary string is a string over the alphabet {0, 1}, and the reversal wR of a binary string w is defined by the rules λR = λ and (wa)R = awR.

An undirected graph is said to be bipartite if it is possible to partition its nodes into two sets R and B, such that every edge of the graph has one endpoint in R and one in B. Equivalently, the nodes may be colored red and blue such that no edge connects red to red or blue to blue.

On a two-dimensional grid, the Manhattan distance between two points (a, b) and (c, d) is the minimum length of any path from one point to the other that follows the edges of the grid, that is, |a - c| + |b - d|.

The following scenario is used in Question 4. On a shelf in our house there are two containers of dog treats, one with large treats for Cardie and one with small treats for Duncan. Every day Cardie gets five large treats and Duncan gets seven small treats. If there are fewer than 20 large treats in Cardie's container at the beginning of the day, we add 48 more. If there are fewer than 20 small treats in Duncan's container at the beginning of the day, we add 90 more. (For example, suppose there are 23 treats in Cardie's container at the start of Day 0. Then there are 23 - 5 = 18 there at the start of Day 1, and 18 + 48 - 5 = 61 at the start of Day 2.

The function c(n) denotes the number of treats in Cardie's container at the start of Day n, and the function d(n) denotes the number of treats in Duncan's container at the start of Day n.

The n by n knight graph has an n by n square array of nodes, labeled as in chess positions with rows 1, 2,..., n and columns a, b,..., so the for example node d3 is in the third row and the fourth column. There is an undirected edge between two nodes whenever a chess knight can move from one to the other. (Chess knights move either two squares horizontally and one vertically, or one horizontally and two vertically.

This page shows pictures of the 3 by 3, 4 by 4, 5 by 5, and 6 by 6 knight graphs. (Note that neither the 1 by 1 nor the 2 by 2 knight graphs have any edges at all.) The 3 by 3 knight graph has 8 edges, and the 4 by 4 knight graph has 24.

Thus if f(n) is the number of edges in the n by n knight graph, we have all the values for n ≤ 4. By an analysis we won't explain here, for all n with n ≥ 4, f(n+1) is equal to f(n) + 20 + 4(2n - 7). You will need this formula for Question 2.

This page has a 4 by 4 knight graph with labels, which are not exactly the labels we are using. We are calling the nodes a1, a2,..., d4, and we will normally put the a nodes in a column rather than a row, but the 4 by 4 kn1ght graph you will search in Question 3 otherwise looks the same as this one.

Last modified 10 April 2016