# Solutions to Second Midterm Exam

#### 4 April 2013

Question text is in black, solutions in blue.

### Directions:

• Answer the problems on the exam pages.
• There are six problems, some with multiple parts, for 100 total points plus 10 extra credit. Actual scale was A = 90, C = 60.
• Some useful definitions precede the questions below.
• No books, notes, calculators, or collaboration.
• In case of a numerical answer, an arithmetic expression like "217 - 4" need not be reduced to a single integer.

```  Q1: 10 points
Q2: 20 points
Q3: 15 points
Q4: 15 points
Q5: 20 points
Q6: 20+10 points
Total: 100+10 points
```

### Definitions Used on the Exam:

• Remember that natural number always means "non-negative integer".

• The scope of any quantifier is always to the end of the statement it is in.

• Questions 1-3 use a set of dogs D that includes the four named dogs Ace, Biscuit, Cardie, and Duncan. In Questions 1 and 2 these are the only dogs in D, but in Question 3 there may be others. The predicate F(x, y) means "dog x and dog y are friends". We assume that F is antireflexive (meaning ∀x: ¬F(x, x)) and symmetric (meaning ∀x: ∀y: F(x, y) ⇔ F(y, x)). These two assumptions mean that F may be modeled as a simple (undirected) graph.

• The three statements of Question I are:
• (I) Ace is friends with every dog except himself.
• (II) ∃x:∃y:∃z: (x ≠ y) ∧ (x ≠ z) ∧ (y ≠ z) ∧ F(x, y) ∧ (¬F(x, z)) ∧ (¬F(y, z))
• (III) Biscuit is friends with exactly one dog.

• A Family of Directed Graphs: In Question 6, we define a directed graph Gn for each natural number n. Gn models part of a road network like that of Manhattan Island in New York City. There are 2n + 2 vertices in Gn, named a0, a1,..., an and b0, b1,..., bn. There is an arc (directed edge) from ai to ai-1 and from bi to bi+1 for every i such that those vertices are both in Gn. There is an arc from ai to bi for every even i, and an arc from bi to ai for every odd i. There are no other arcs. Here is a diagram for G3:

``````
[a0] <---- [a1] <---- [a2] <---- [a3]
|          ^          |          ^
|          |          |          |
|          |          |          |
V          |          V          |
[b0] ----> [b1] ----> [b2] ----> [b3]
``````

• A directed graph is defined to be strongly connected if for any two vertice u and v in the graph, there is a (directed) path from u to v.

• Question 1 (20): Translate each statement as indicated, using the set of dogs {Ace, Biscuit, Cardie, Duncan} and the predicate F(x, y) meaning "dog x and dog y are friends".

• (a, 3) (to symbols) (Statement I) Ace is friends with every dog except himself.

∀x: (x ≠ a) → F(a, x). Many people used ∧ instead of →, losing most of the points. You could debate whether ¬F(a, a) follows from the English statement -- it certainly follows from the antireflexivity of F. I accepted ∀x: (x ≠ a) ⇔ F(a, x) as well.

• (b, 3) (to English) (Statement II) ∃x:∃y:∃z: (x ≠ y) ∧ (x ≠ z) ∧ (y ≠ z) ∧ F(x, y) ∧ (¬F(x, z)) ∧ (¬F(y, z))

There exist three dogs, all different, such that the first and second are friends, but neither the first nor second is friends with the third.

• (c, 4) (to symbols) (Statement III) Biscuit is friends with exactly one dog.

The simplest expression is probably ∃x:∀y: F(b, y) ⇔ (y = x). Another possibility is ∃x: F(b, x) ∧ ∀y: (y ≠ x) → ¬F(b, y). Many people wrote just ∃x: F(b, x) which only says "Biscuit is friends with at least one dog. I didn't define the notation "∃!x:" for "there exists exactly one x" in lecture, so I only gave three points out of four for using it.

• Question 2 (15): These questions use the definitions, assumptions, and predicates from Question 1, which are also listed above. Those facts give you enough information to determine all the values of F(x, y) for any dogs x and y.

• (a, 10) Draw the simple (undirected) graph for the relation F -- that is, draw a vertex for each of the four dogs and an edge between x and y if and only if F(x, y) is true.

The graph has nodes a, b, c, and d and edges (a, b), (a, c), (a, d), and (c, d). The last edge exists because statement II cannot be satisfied by having dogs x and y be either Ace or Biscuit, but it is true, so Cardie and Duncan must be the x and y and this implies F(c, d) is true. The three edges involving a follow from Statement I and the two non-edges (b, c) and (b, d) follow from Statement III, since Biscuit's only friend must be Ace. Many of you omitted the edge (c, d) -- in this case I graded parts (b) and (c) of this problem based on your answer to part (a).

The correct graph in (a) is not bipartite. Since a, c, and d form a triangle, we cannot split them into two sets without two nodes in the same set having an edge between them. (They also form an odd cycle, which makes the graph not bipartite by a theorem proved in lecture.)

The correct graph is not a tree. The nodes a, c, and d form a cycle, and trees have no cycles.

• Question 3 (15): This question involves a set of dogs D that includes the four named dogs but possibly others. Assume that F is antireflexive and symmetric (as defined above) and assume Statements I and III from Question 1 but not Statement II. Prove the following statement using quantifier rules:

∃x: ∃y: ∃z: (x ≠ y) ∧ (x ≠ z) ∧ (y ≠ z) ∧ [(F(x, y) ∧ F(x, z) ∧ F(y, z)) ∨ ((¬F(x, y)) ∧ (¬F(x, z)) ∧ (¬F(y, z)))]

or in English, "There exist three distinct dogs such that either every pair is friendly or every pair is unfriendly". (Hint: Let two of your dogs be Cardie and Duncan and use an argument by cases to determine your third dog.)

Let x be Cardie and let Y be Duncan, as suggested. We argue by cases:

Case I: F(c, d) is true. Let z be Ace. We have that F(a, c) and F(a, d) are true by UI from Statement I. Then we also have F(c, a) and F(d, a) by UI on the symmetry property and Modus Ponens. We have that F(c, d) is true by the assumption for the case. Thus "F(c, d) ∧ F(c, a) ∧ F(d, a)" is true by Conjunction, and "[F(c, d) ∧ F(c, a) ∧ F(d, a)] ∨ [¬F(c, d) ∧ ¬F(c, a) ∧ ¬F(d, a)]" is true by Addition. The desired statement is thus true by three uses of EG quantifying z, y, and x in that order.

Case II: F(c, d) is false. Let z be Biscuit. By Statement III, ∃u:∀v: F(b, v) ⇔ (v = u). By EI, let s be the dog such that ∀v: F(b, v) ⇔ (v = s). By UI, specifying v to a, we get F(b, a) ⇔ (a = s) . We know F(a, b) by UI from Statement I, and since F(b, a) follows from F(a, b) by UI from Symmetry and Modus Ponens, a must be equal to s and we know that ∀v: F(b, v) ⇔ (v = a). From this it follows that F(b, c) and F(b, d) are false, and by Symmetry, UI, and Modus Ponens again we know that F(c, b) and F(d. b) are false. By Conjunction we get "¬F(c, d) ∧ ¬F(c, b) ∧ ¬F(d, b)". We get the final statement from this just as in Case I, by Addition and then three uses of EG.

• Question 4 (15): Suppose we are searching for a target number, where we guess a number and are told that it is too low, exactly right, or too high. We know that our number n is an integer in the range from x to y, inclusive, and that there are n integers in that range for some n > 0.

Let P(k) be the statement "If n ≤ 2k - 1, then we can find the number with k guesses". Prove P(k) by induction for all positive integers k.

Since we are using induction on positive integers, our base case is k = 1. P(1) says that if n ≤ 21 - 1 = 1, then we can find our number with one guess. This is true since we may guess the only number that is in the range.

Now assume the IH, which says that a range of up to 2k - 1 numbers may be searched with k guesses. We need to search a range of up to 2k+1 - 1 numbers with k + 1 guesses to prove P(k+1) and complete the induction.

Let x and y be the endpoints of an arbitrary range of n integers, with n ≤ 2k+1 - 1. Our first guess will be (x + y)/2. If this is correct we have finished with 1 guess, and 1 ≤ k + 1. Otherwise we know either that the target is in the low range or that it is in the high range. Each of these ranges has at most n/2 = 2k - 1 integers in it. By the IH, we can search this range with at most k more guesses, completing the original search with at most k + 1 guesses as desired.

I got many bad answers that tried to prove the statement "n ≤ 2k + 1" by induction, without any reference to guesses or ranges. Induction proofs are about something -- many are about numbers but this one is about guesses and ranges, as you can tell by the reference to guesses and ranges in the statement P(k).

• Question 5 (20): Consider the following two-player game played on a grid where each square is labeled by a pair of natural numbers. The square (i, j) is i units each and j units north of the square (0, 0). We begin the game with a chess rook on some square (i, j). The players alternate moves, and a move consists of moving the rook either west or south some number of squares, thus subtracting a positive integer from either i or j. The first player who cannot move loses, so moving to (0, 0) wins the game.

Prove that the first player has a winning strategy starting from (i, j) if and only if i ≠ j. (Hint: Let P(k) be the statement: "If k is the minimum of i an dj, then the first player has a winning strategy starting from (i, j) if and only if i ≠ j." Then prove P(k) for all natural numbers k by strong induction. But if you can't do the strong induction, make the most convincing argument you can.) problems:

Most of you had what was more or less the correct strategy, but I got rather few correct strong induction proofs. I'll give two here, the first using my suggested statement P(k) above, and the other using a different P(k).

Using my P(k), our base case is to prove P(0), since we are told to prove P(k) for all natural numbers. P(0) says that if the minimum of i and j is 0, then Player I wins the game starting at (i, j) if and only if i ≠ j. This means that he loses the game starting at (0, 0) and that he wins starting from (i, 0) or from (0, j) if i or j is positive. We are given that he loses from (0, 0), and in the other case he can move directly to (0, 0) and win, so P(0) is true.

Now we assume that P(m) is true for all m with m ≤ k, as our strong inductive hypothesis. We first prove that the first player loses the game starting at (k + 1, k + 1). Her first move must be to (i, k + 1) or (k + 1, j) for some i or j less than k + 1. The second player can then move to (i, i) or (j, j), whereupon she wins (and thus the first player loses) by the strong inductive hypothesis which implies P(i) and P(j). Now consider the game starting from (i, k + 1) or (k + 1, j) with i or j greater than k + 1. The first player can move to (k + 1, k + 1), and this is a winning move for her because she then becomes the second player in the game we just analyzed as a win for the second player. This proves P(k + 1) and completes the strong induction.

Suppose instead we used the statement Q(k), which says "If i and j are each ≤ k, then the first player wins from (i, j) if and only if i ≠ j". We can prove this statement by ordinary induction. Q(0) says that the first player loses if starting at (0, 0), and we are given that this is true. Now assume that Q(k) is true and look at Q(k + 1). Let i and j be arbitrary natural numbers, each ≤ k + 1. If both are ≤ k, we have our conclusion from the IH, which is Q(k). If i = k + 1 or j = k + 1 but not both, the first player can move to (j, j) in the first case or to (i, i) in the second case, whereupon she becomes the second player in a game that Q(k) tells us is a win for the second player. If i = j = k + 1, the first player must move to (i, k + 1) or (k + 1, j) with i or j less than k + 1, and the second player then wins by the analysis we just did. This proves Q(k + 1) from the IH and completes the ordinary induction.

• Question 6 (20+10): These three questions use the family of directed graphs Gn defined above.

• (a, 10) For any natural number n, Gn+1 can be made from Gn by adding exactly two more vertices, an+1 and bn+1, and exactly three more arcs, (an+1, an), (bn, bn+1), and either (an+1, bn+1) or (bn+1, an+1). From these facts, prove (by induction on n) that each graph Gn has exactly 3n + 1 arcs.

Let e(n) be the number of edges in the graph Gn -- we are asked to prove ∀n: e(n) = 3n + 1. The base case is n = 0, where e(0) = 1 = 3(0) + 1 because we are told that there are only the vertices a0 and b0 and only the edge (a0, bo). Assume as the IH that e(n) = 3n + 1. We are told that Gn+1 has exactly three more edges than Gn. So we can compute that e(n+1) = (3n + 1) + 3 = 3n + 4, and since 3n + 4 = 3(n + 1) + 1, we have completed the inductive step and proved e(n) = 3n + 1 for all naturals.

Again, a proof that does not talk about graphs and edges cannot get us a result about graphs and edges.

• (b, 10) Explain why Gn is strongly connected (as defined above) if and only if n is odd. You may be informal if you are convincing.

An "if and only if" proof breaks up into two halves. We must prove that Gn is strongly connected when n is odd, and that it is not strongly connected when n is even.

When n is odd, there is a directed cycle from a0 first to b0, then through all the bi's to bn, then to an, then through all the ai's back to a0. We may get from any node to any other node by following this cycle, since it contains all the nodes. So the graph is strongly connected.

When n is odd, the node bn has two arcs into it (from bn-1 and from an) and no edges out, so it has no path to any other node and the graph is not strongly connected. We could also note that an has two arcs out and none in, and so has no path from any other node.

• (c, 10XC) Let f(k) be the number of k-step paths in the graph G3 from the vertex a0 to itself. Determine f(k) for as many values of k as you can. For full credit, give a general rule that gives f(k) for any natural number k, and prove your rule (preferably by induction).

There is exactly one path with no edges from any node to itself, so f(0) = 1. By inspection of the graph we see that f(1), f(2), and f(3) are all 0 and that f(4) is 1, by the path from a0 to b0 to b1 to a1 and back to a0. There are also four-step paths from a0 to b3 and vice versa, but not from either of those two nodes to any other node.

Just to give you another induction example, let's prove that if k equals 4m + 1, 4m + 2, or 4m + 3, then there are no paths of length k from a0 to either itself or to b3. We work by induction on m. The base case is m = 0, for which we dealt with the cases of k = 1, k = 2, and k = 3 by inspection of the graph. Now assume the IH for m and look at the cases of k = 4(m + 1) + 1, k = 4(m + 1) + 2 , and k = 4(m + 1) + 3. In each case, we assume that there is a path of that length and get a contradiction. Look at the alleged path and consider the node four arcs from the end of the path. This node has a path of length four to either a0 or b3, so it is itself either a0 or b3. But this contradicts the IH.

Now let's look at f(k) for k divisible by 4. We have observed that f(0) = 1 and f(4) = 1. We can see that f(8) = 2, since we can go either from a0 to a0 to a0 or from a0 to b3 to a0 by a pair of four-step paths. In fact to choose a path of length 4m from a0 to itself, we just have to choose where the path is after 4, 8, 12,..., and 4(m-1) steps. This is m - 1 binary choices, as at each of these points it is at either a0 or b3. So f(4m) = 2m-1, for any positive m.

Some people observed that I could in principle construct the 8 by 8 adjacency matrix for G3, raise it to the k'th power, and read off f(k) from the (a0, a0) entry. I gave five points out of ten for this answer, which after all does not really give you f(k) in a useful form.