CMPSCI 250: Introduction to Computation
Final Exam
David Mix Barrington
16 December 2010
Directions:
- Answer the problems on the exam pages.
- There are four problems
for 130 total points.
Actual scale is A=102, C=66.
- If you need extra space use the back of a page.
- No books, notes, calculators, or collaboration.
Q1: 35 points
Q2: 35 points
Q3: 40 points
Q4: 20 points
Total: 130 points
Question 1 (35): Here are three situations in which you are to construct
induction proofs.
- (a, 10) Define a function f from naturals to naturals by the
rules f(0) = 0 and, for n > 0, f(n) = n - f(n-1). Prove that for
all odd n, f(n) = (n+1)/2, and that for all even n, f(n) = n/2.
(You can use ordinary induction on n and proof by cases, or
separate inductions for odd and even n.)
- (b, 15) Define a function g from naturals to naturals as
computed by the following pseudo-Java method:
natural g (natural n) {
if (n == 0) return 0;
return n + g(n/2);}
where "/" is Java integer division, with no remainder, so that for
example "7/2" is 3. Prove that for all positive naturals n, the
method terminates on input n and outputs a number g(n) which is less
than 2n. (You should use strong induction.)
- (c, 10) Define a function h from strings to strings (over
the alphabet {a, b, c,..., z}) by the following rules:
- h(λ) = λ
- If w is a string and a is a letter, h(wa) =
h(wR)a
where "wR" denotes the reversal of w (w written
backwards).
Compute the string h("cardie").
Prove that for any string w, h(w) is a string whose length is
the same as the length of w. (You can use either induction on
strings or ordinary induction on the length of w.)
- Question 2 (35): This problem concerns a set C of
customers at Zane's Noodle Bowl, and the set V of vegetables
that a customer may order for their soup there. Let R ⊆ C
× V be the relation such that the pair (c,v) is in R if
and only if customer c orders vegetable v. (Equivalently, R(c,
v) is the predicate "customer c orders vegetable v".) Also, S
is a binary relation on customers, that is, a subset of C
× C, so that S(c, c') is translated into English as "c and
c' are similar".
- (a, 10) Translate the following statements as
indicated, using the predicates R and S, constant symbols w
and k of type "customer" for "William" and "Kate", and
constant symbols of type "vegetable" for "bean sprouts" and
"tofu".
- (I, to English) ∀c: R(c,b) → R(c,t)
- (II, to symbols) Either William or Kate, or both,
ordered bean sprouts, but Kate did not order tofu.
- (III, to English) ∀c: ∀c':S(c,c') ↔
(∀v: R(c, v) ↔ R(c', v))
- (b, 10) Prove, assuming that statements I and II are
true, that William ordered tofu. (This involves propositional
logic on the four statements R(w, b), R(w, t), R(k, b), and
R(k, t), along with two uses of the Specification Rule for
quantifiers.)
- (c, 15) Prove, using quantifier proof rules and the
definition in Statement III, that S is an equivalence
relation.
- Question 3 (40): Let Σ be the alphabet {a, b} and
let R be the regular expression (a+b)(a+ba+bb)*. Let M be
a λ-NFA with state set {1, 2, 3, 4}, start state 1, final
state set {4}, and transitions (1, a, 2), (1, b, 2), (2, a, 2), (2,
b, 3), (3, a, 2), (3, b, 2), and (2, λ, 4).
- (a, 5) Argue convincingly that L(M) = L(R). You may want to
use some of the constructions we covered in lecture, or you may want
ot argue informally first that L(R) ⊆ L(M) and then that L(M)
⊆ L(R).
- (b, 10) Using the construction from lecture on M, build an
ordinary NFA N such that L(N) = L(M).
- (c, 10) Using the Subset Construction, build a DFA D such
that L(D) = L(N).
- (d, 5) Either prove that your D is minimal or find a minimal
DFA D' such that L(D) = L(D').
- (e, 5) Find a DFA D'' such that L(D'') is the complement of
L(D'), that is, such that for any string w, (w ∈ L(D'')) ↔
(w ∉ L(D')).
- (f, 5) Using the construction from lecture, find a regular
expression R' such that L(R') = L(D'').
- Question 4 (20): If u and v are any two strings in {a,
b}*, we say that u and v are anagrams if and only
if v can be made by rearranging the letters of u. That is, u and v
must have the same number of a's, and u and v must have the same
number of b's. (For example, the strings "aabbbaa" and "baaaabb"
are anagrams.) Define the language X, over the alphabet {a, b, c},
to be the set {ucv: u and v are anagrams}. (Remember that u and v
must
be strings in {a, b}*. For example, the string
"aabbbaacbaaaabb" is a member of X.)
- (a, 10) Is there a regular expression denoting X? Prove
your answer.
- (b, 10) Argue informally that the language X is Turing
decidable. (Remember that in designing a Turing machine, you can
make the alphabet as large as you want as long as it is finite.)
Last modified 21 December 2010