Assignment 10 - Computer Science Department

Computer Science 30
Assignment 10
due date on calendar
1. Use JFLAP to construct a DFA that accepts all strings that have exactly
one a and two or more b’s.
The DFA below counts the number of a’s on the horizontal axis and the
number of b’s on the vertical (diagonal, actually) axis. The label on the
state is a pair indicating the number of a’s and b’s seen so far. The three
states on the right edge could be coalesced into a single state, if desired.
a
a
q0
a
q1
q2
(2+,0)
(1,0)
(0,0)
b
b
b
a
q3
(0,1)
a
q4
(0,2+)
a
b
b
b
q6
q5
(2+,1)
(1,1)
b
a
b
q7
(1,2+)
a
a,b
q8
(2+,2+)
2. Use JFLAP to construct a six-state DFA which accepts a string if it has
a number of a’s that is a multiple of 2 or a multiple of 3 (or both).
Description: Start with six states, labeled 0 through 5. Think of state j as
representing the remainder upon division by 6 of number of a’s seen so far.
The start state is 0, and the final states are 0, 2, 3, and 4. The transition
upon reading an a is from state j to (j + 1) mod 6. The transition upon
reading any other letter is from state j back to state j.
a
q2
a
q0
q3
a
a
q1
a
q5
a
q4
3. Use JFLAP to construct a DFA which accepts a string of 0’s and 1’s if,
when interpreted as a binary number, is a multiple of 3. (This is not trivial;
think about it before you start to build the DFA.)
Description: Start with three states, labeled 0 through 2. Think of them as
representing the remainder upon division by 3 of the number so far. The
state 0 is the start state and the only accepting state. The transition upon
reading a 0 is from state j to state (2j) mod 3. The transition upon reading
a 1 is from state j to state (2j + 1) mod 3.
0
1
1
q0
1
4. Balanced Parens Turing Machine
0
q1
q2
0