CMPSCI 250: Introduction to Computation

Solutions to Second Midterm Exam

David Mix Barrington

13 November 2013

Directions:

Question text is in black, solutions in blue.

  Q1: 10 points
  Q2: 15 points
  Q3: 15+10 points
  Q4: 30 points
  Q5: 30 points
Total: 100+10 points

Definitions and Other Notes:

N is the set of naturals, {0, 1, 2, 3,...}.

Question 3 uses an inductively defined function from {a, b}* to N. We define f(λ) = 0, and for any string w we define f(wa) = f(w) + 1 and f(wb) = 2f(w).

Question 4 uses the following inductive definition of "set expression":

  1. An atomic set expression has a value that is a set of int values.
  2. If E and F are set expressions, so are E ∪ F, E ∩ F, and E-bar, denoting the union of E and F, the intersection of E and F, and the complement of E respectively.
  3. Nothing else is a set expression.

Question 4 assumes that we have defined a real-Java class IntSet whose objects are sets of int values. The only method of this class that you will need is public boolean isIn (int x), which returns true if and only if the int value x is in the calling set. Note that Question 4 will ask you to write a different method isIn, for the SetExpression class.

We also have the following real-Java class for set expressions:

public class SetExpression {
   public static final int UNION = 1;
   public static final int INTERSECTION = 2;
   public static final int COMPLEMENT = 3;
   boolean isLeaf;
   IntSet leafValue;
   SetExpression left, right;
   int op;

   // usual constructors, getters, and setters

Question 5 uses the following labeled undirected graph:

  [a] ---1--- [s] ---1--- [f]
   |           |           |
   3           6           9
   |           |           |
  [b] ---1--- [d] ---1--- [g]
   |           |           |
   3           6           9
   |           |           |
  [c] ---1--- [e] ---1--- [h]

Last modified 13 November 2013