CMPSCI 250: Introduction to Computation

David Mix Barrington

Fall, 2004

CMPSCI 250 Solutions to Practice Midterm #2

Solutions Posted 26 October 2004

Actual midterm will be 28 October 2004

There are six questions for 100 total points. Questions are in black, solutions in blue.

Question 5 (a) as corrected on 26 Oct 2004.

Question 1 (10): Prove ∃a:∀b:(b≥a)→[∃c:(b<3c)∧(3c<2b)]. This can be done without mathematical induction.

Let a be 4. (Why? Because 3 doesn't work, as there is no multiple of 3 between 3 and 6.) Let b be arbitrary, and assume that b ≥ a. One of the three numbers b+1, b+2, or b+3 must be a multiple of 3. Let c be the natural such that this number is 3c. Clearly b < 3c, and since b ≥ 4 it is also true that 3c < 2b. So we found a c that satisfies the conditions, and we have proved the statement in square brackets. Since b was arbitrary, we have proved the implication. Since we found a value of a that works, we have proved the entire statement.

Question 2 (10): Prove by induction that for all naturals n, (n+1)/2≤n. Here the "/" is the Java integer division operator.

We use ordinary induction on n. Let P(n) be the statement "(n+1)/2 ≤ n". For the base case, P(0) is the statement "(0+1)/2 ≤ 0", which is true because 1/2 = 0 with Java integer division.

For the inductive case, assume that (n+1)/2 ≤ n. We want to prove that (n+2)/2 ≤ n+1. By adding 1 to both sides of the inductive hypothesis we get (n+1)/2 + 1 ≤ n+1. Since (n+1)/2 + 1 = (n+3)/2, we know that (n+2)/2 ≤ (n+3)/2 ≤ n+1, which is what we wanted to prove. We have completed the inductive case and thus completed the proof.

Question 3 (20): This problem concerns the three naturals 64, 77, and 91.

Question 4 (20): Prove ∀a:∀b:(b>0)→[∃q∃r:(a=qb+r)∧(r<b)]. (Hint: Let b be arbitrary, assume b>0, and use strong induction on a, with P(a) being the predicate in square brackets.)

We can let b be arbitrary to start, since we can switch the order of the two ∀ quantifiers at the beginning. So let b be arbitrary, assume b > 0, and use strong induction on a. For the base case, P(0) says that there exist q and r such that qb+r = 0. This is true because we may take q=0 and r=0. So now for the strong inductive case assume that any a with a ≤ n can be written as qb+r for some q and r with r < b. We need to show that n+1 can be written as sb+t for some naturals s and t, with t < b. There are several ways to prove this, but I find it easier to divide it into two cases. If n+1 < b, we may let s=0 and t = n+1, and we have n+1 = sb+t and t < b. On the other hand, if n+1 ≥ b, then n+1-b is a natural that is ≤ n. So the strong inductive hypothesis tells us that n+1-b = qb+r for some naturals q and r with r < b. Now we can let s = q+1 and t = r, and we have n+1 = sb+t and t < b. This completes the strong inductive case and thus completes the proof.

Question 5 (20): Define the function f from strings in {a,b}* to strings in {0,1}* by the following rules:

Prove the following, where u is in {a,b}* and w is in {0,1}*:

Question 6:(20) Define a directed ternary tree (DTT) by the following rules:

Recall that a leaf is a node with no arcs out of it. Prove that in any DTT, the number of leaves is twice the number of non-leaves, plus one.

We proceed by induction on all DTT's. For any DTT R, let N(R) be the that the number of non-leaves in R, let L(R) be the number of leaves in R, and let P(R) be the statement "L(R) = 2N(R) + 1". The base case is P(B), where B is the DTT given by the base case of the definition, with one node that is a leaf. Since N(B) = 0 and L(B) = 1, P(B) is true.

For the inductive case, assume that S, T, and U are all DTT's such that P(S), P(T), and P(U) are all true. Let R be the tree constructed from S, T, U, and a new node x according to the inductive case of the definition. To prove P(R), we must calculate N(R) and L(R). Since x is not a leaf and is the only new node, and the leaves and non-leaves of S, T, and U remain leaves and non-leaves respectively in R, we have that N(R) = 1 + N(S) + N(T) + N(U) and that L(R) = L(S) + L(T) + L(U). By the inductive hypothesis applied to S, T, and U, L(R) is also equal to (2N(S) + 1) + (2N(T) + 1) + (2N(U) + 1) = 2(N(S) + N(T) + N(U)) + 3 = 2(N(S) + N(T) + N(U) + 1) + 1, so P(R) is true and the induction is complete.

Last modified 26 October 2004