HW 2
HW 2
• If w is any string, then wR (the reversal of w) is w written backwards, that is, comprising
the symbols of w in reverse order.
• A string x is a prefix of a string y iff there exists a string z such that y = xz.
• A string x is a suffix of a string y iff there exists a string z such that y = zx.
a
0 1
b
b a a
b
2 3
b
(a) For each of the strings below, say which state the DFA is in after reading the string, and
say whether or not the DFA accepts the string.
(b) Give two different strings of length 4 that each make the DFA go from state 0 to state 1.
2. Draw a DFA with alphabet {0, 1} that accepts a binary string x iff x has odd length, i.e., iff
|x| is odd.
1
3. Let A be the DFA given by the following tabular form:
0 1
→ ∗q0 q0 q1
q1 q2 q0
q2 q1 q2
(A accepts a binary string iff it represents a multiple of 3.) Recall the DFA described in class
(here we’ll call it B) that accepts a binary string iff the string ends with 1:
A B
1
0 1
Recall the product construction from class. Draw the diagram for the product of A and B so
the resulting DFA recognizes the language L(A) ∩ L(B).
4. Describe a DFA B that accepts a string over the alphabet {a, b, c} iff its first and last symbols
are different.
5. Consider the following two languages over the alphabet {a, b}:
6. Give the transition diagram for a DFA over the alphabet Σ = {a, b, c} that accepts a string
w iff w contains ab as a substring but does not contain abb as a substring. What is the least
number of states you need?
7. (Optional) This exercise is adapted from Exercise 2.2.1 on pages 52–53, which is formulated
somewhat vaguely. Consider the marble-rolling toy (redrawn from Figure 2.8):
2
A B
x1 x2
x3
C D
A marble is dropped at A or B. Levers x1 , x2 , and x3 cause the marble to fall either to the
left or to the right. whenever a marble encounters a lever, it causes the lever to reverse after
the marble passes, so the next marble will take the opposite branch.
Model this toy as a finite automaton. An input to the atomaton is a string over the alphabet
{A, B}, which represents a sequence of marbles being dropped into the toy. The toy is initially
in the configuration above before any marbles are dropped (so that the first ball will exit at
C regardless of where it is dropped). Say that a sequence of marble drops is accepted exactly
in the case that if one additional marble were to be dropped in, it would go out through D
regardless of where it was dropped.