# Solutions to Second Midterm Exam

### Directions:

• Answer the problems on the exam pages.
• There are five problems on pages 2-7, for 100 total points plus 10 extra credit. Actual scale was A=90, C = 54.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.

Question text is in black, solutions in blue.

```  Q1: 20 points
Q2: 20 points
Q3: 20 points
Q4: 20 points
Q5: 20 points plus 10 extra credit
Total: 100 points plus 10 extra credit
```

Questions 1 and 2 deal with the Fibonacci sequence from Discussion #5. Recall that the function F from naturals to naturals is defined recursively, by the rules F(0) = 0, F(1) = 1, and (for n > 1) F(n) = F(n-1) + F(n-2). As we calculated in the discussion, F(2) = 1, F(3) = 2, F(4) = 3, and F(5) = 5.

• Question 1 (20): Define SE(n) to be the sum of the even-numbered Fibonacci numbers from F(0) through F(2n). -- that is, SE(n) = ∑ni=0 F(2i). (Thus, for example, SE(2) = F(0) + F(2) + F(4) = 0 + 1 + 3 = 4.) Prove, by ordinary induction on n, that SE(n) = F(2n+1) - 1.

Base case: n = 0, SE(n) = SE(0) = 0, F(2n+1) - 1 = F(1) - 1 = 0.

Inductive case: Assume SE(n) = F(2n+1) - 1. By the definition, SE(n+1) = SE(n) + F(2n+2). By the IH, this is F(2n+1) - 1 + F(2n+2), and by the Fibonacci rule, this is F(2n+3) - 1 = F(2(n+1)+1) - 1 as desired, completing the induction.

• Question 2 (20): Prove by ordinary induction that for any natural n, F(6n) is congruent to 0 modulo 4 (that is, F(6n) ≡ 0 (mod 4)) and F(6n+1) is congruent to 1 modulo 4 (that is, F(6n+1) ≡ 1 (mod 4)). (Hint: Your induction should use both statements about n together to prove both statements about n+1.)

Base case: n=0, F(6n) = F(0) = 0 and 0 is congruent to 0 mod 4. F(6n+1) = F(1) = 1, and 1 is congruent to 1 mod 4.

Inductive case. Assume that F(6n) ≡ 0 and F(6n+1) ≡ 1, both modulo 4. We can compute the value of the following Fibonacci numbers mod 4: F(6n+2) = F(6n+1) + F(6n) ≡ 1 + 0 = 1; F(6n+3) = F(6n+2) + F(6n+1) ≡ 1 + 1 = 2; F(6n+4) = F(6n+3) + F(6n+2) ≡ 2 + 1 = 3; F(6n+5) = F(6n+4) + F(6n+3) ≡ 3 + 2 ≡ 1; F(6n+6) = F(6n+5) + F(6n+4) ≡ 1 + 3 ≡ 0; and F(6n+7) = F(6n+6) + F(6n+5) ≡ 0 + 1 = 1. We have proved that F(6(n+1) is congruent to 0 and that F(6(n+1)+1) is congruent to 1, where again all these congruences are modulo 4.

• Question 3 (30+10): In my pocket I have a large number of dollar bills and exactly six cents in change. Chocolate bars cost \$1.43 each. I want to buy some number x of chocolate bars such that I can pay for them with my six cents of change and some of my dollar bills -- that is, I want x(1.43) to be exactly 0.06 more than some natural number.
• (a,5) Formulate an equation in modular arithmetic that expresses my goal for the number x.

I want 143 x to be congruent to 6, modulo 100. Since 143 is congruent to 43, I can rewrite this as 43x ≡ 6 (mod 100).

• (b,5) Carefully state the Inverse Theorem and explain how it applies to this situation.

The Inverse Theorem says that if a and m are two positive naturals, a has an inverse modulo m if and only if a and m are relatively prime. An inverse of a modulo m is a natural b such that ab is congruent to 1, modulo m.

• (c,10) Prove that the integers 43 and 100 are relatively prime.

By the Euclidean Algorithm, 100 = 2(43) + 14, 43 = 3(14) + 1. Since we reached 1, we know the original numbers have a gcd of 1 and are thus by definition relatively prime.

• (d,10) Find both an inverse of 43, modulo 100, and an inverse of 100, modulo 43. Use one of these to find a natural number x that meets my goal stated above (and in part (a)).

The extended Euclidean Algorithm gives me the successive equations 100 = 1*100 + 0*43, 43 = 0*100 + 1*43, 14 = 1*100 - 2*43, and 1 = -3*100 + 7*43. So 7 is an inverse of 43, modulo 100, and -3 or 40 are inverses of 100, modulo 43.

• (e,10 XC) Suppose now that the choclolate bars cost a cents and I have b cents worth of change in my pocket, where a is a natural and b is a natural less than 100. Exactly what conditions on a and b will guarantee that there exists an x such that I can buy x chocolate bars for some number of dollars plus b cents? I want an "if and only if" condition, so that if a and b meet your condition then x exists, and if they don't meet your condition then x doesn't exist. (Hint: If the process you used in (d) is not possible, how might you still be able to solve the problem?)

If a is relatively prime to 100, I can make any b by the technique we used in part (d). If a and 100 have a gcd g that is greater than 1, we can make b if and only if b is a multiple of g. To prove this, note first that every linear combination of a and m must be divisible by g. We can make g cents modulo m with some number of chocolate bars because the extended Euclidean Algorithm allows us to find a linear combination of a and m to make every number that occurs in the ordinary Euclidean Algorithm, including the final such number which is g. We can then make b, if b is any multiple of g, by multiplying this linear combination by the right factor b/g.

• Question 4 (30): This problem deals with a directed graph G where each node Ni,j is given by a pair of naturals i and j. We can picture G with node Ni,j drawn at the position x=i and y=j in the usual Euclidean plane. There are four kinds of arcs (directed edges) in G:
• For all even i and all j, there is an arc from Ni,j north to Ni,j+1.
• For all odd i and all j, there is an arc from Ni,j south to Ni,j-1.
• For all even j and all j, there is an arc from Ni,j east to Ni+1,j.
• For all odd j and all i, there is an arc from Ni,j west to Ni-1,j.

(Note: This directed graph models the pattern of one-way streets in large parts of Manhattan Island.) It is not important to the problem how far G extends.

Here is an ASCII-art picture of part of G:

```N03 <--- N13 <--- N23 <--- N33 <--- ...
^        |        ^        |
|        |        |        |
|        v        |        v
N02 ---> N12 ---> N22 ---> N32 ---> ...
^        |        ^        |
|        |        |        |
|        v        |        v
N01 <--- N11 <--- N21 <--- N31 <--- ...
^        |        ^        |
|        |        |        |
|        v        |        v
N00 ---> N10 ---> N20 ---> N30 ---> ...
```

Recall the inductive definition of paths in a directed graph:

• (1) For any node x, there is a path of length 0 from x to x.
• (2) If there is a path α of length k from x to y, and an arc e from y to z, then there is a path αe of length k+1 from x to z.
• (3) The only paths are those constructed from (1) and (2). Thus if a predicate P(α) is true for the empty path, and P(α) → P(αe) for any such path α and arc e, then P(α) is true for all α.
Here are the questions:
• (a,10) Prove by induction on all paths that if α is a path from N0,0 to Ni,j, then the length of α is greater than or equal to i+j.

For the base case, the length-0 path goes to N0,0 and the length 0 is in fact greater than or equal to i+j = 0.

For the inductive case, let β be a path obtained by adding one edge to a path α and assume that our conclusion holds for α. If β ends at Ni,j, then α must end at Ni-1,j, Ni+1,j, Ni,j-1, or Ni,j+1. In all four cases, the IH tells us that the length of α is at least i+j-1. The length of β is one greater than the length of α, and thus is at least i+j.

• (b,10) Explain (informally but carefully) why there is a path of length exactly i+j from N0,0 to Ni,j if i is even, if j is even, or if both are even.

If i is even, I can go east from N0,0 to Ni,0, using i steps, then go north to Ni,j in j steps because the edges with that value of i ("avenues") go north. If j is even, I can go from N0,0 north to N0,j and then go east (on an even-numbered "street") to Ni,j, using i+j edges in all. If both i and j are even, I could use either path.

• (c,10) Prove by induction on all paths that if α is a path from N0,0 to Ni,j and i and j are both odd, then the length of α is greater than or equal to i+j+2. You may use the result of part (a).

For the base case, the empty path does not go to such a node, and so we have nothing to prove. In the inductive case, let α be a path from N0,0 to Ni,j with i and j both odd, and let α be some path β followed by a single edge. By the definition of the graph, β must end at either Ni+1,j or Ni,j+1, because these are the sources of the only edges that end at Ni,j. By the result of part (a), the length of β is at least i+j+1. Since α is β plus one more edge, its length is at least i+j+2.

This is sort of a strange induction, because it never uses the inductive hypothesis. We still need to prove the result for all paths, but the result of (a) is enough to get our conclusion -- we don't need to talk about a path to another odd-odd node.