CMPS 260 Spring 2024
April 17 exam: Sample Solutions

1. Let L1 be the language over the alphabet {a,b} containing precisely those strings that end with b and have an even number of occurrences of a.
More formally, L1 = { xb | x ∈ {a,b}* and #a(x) is even }

(a) Present a (preferably, minimal) DFA that accepts L1.
(b) Present a regular expression that denotes L1.

Solution:
(b*ab*a)* b+
(a) DFA (b) Regular Expression


2.
M1 M2
Consider the DFA's M1 and M2 pictured to the right.

(a) In the space below, fill in the missing entries in the table that describes the semi-DFA M obtained by applying the cartesian product construction. (A semi-DFA is a DFA except that the final/accepting states are left unspecified.) It is understood that [p0,q0] is the start/initial state, due to p0 (respectively, q0) being the initial state of M1 (resp., M2). (You can draw the transition diagram describing M in the space to the right, but it is not required.)

Solution:

δ
stateab
[p0,q0] [p0,q0] [p1,q1]
[p0,q1] [p0,q0] [p1,q1]
[p1,q0] [p1,q0] [p0,q1]
[p1,q1] [p1,q0] [p0,q1]

(b) Which state(s) of M should be designated as final/accepting for the resulting DFA to accept the intersection of L(M1) and L(M2)?

Solution: [p1,q0]

(c) Which state(s) of M should be designated as final/accepting for the resulting DFA to accept the union of L(M1) and L(M2)?

Solution: [p0,q0], [p1,q0], [p1, q1]

(d) Suppose that [p0,q1] were the lone state in M to be designated as final/accepting. What language is accepted by that DFA? (Try to express it in terms of L(M1), L(M2), and set operators, as opposed to referring to a's and b's.)

Solution: Notice that [p0,q1] is the only state missing from the answer to (c), the language of which is the union of L(M1) and L(M2). It follows that the answer to this part is the complement of the union of L(M1) and L(M2). Equivalently, it is the intersection of the complements of L(M1) and L(M2).


3. Let L3 be the language over the alphabet {a,b} containing precisely those strings that either have aba as a suffix or do not have baa as a substring. Present an NFA that accepts L3.

Hint: Make use of the relaxed requirements of NFA's (compared to DFA's) to make the task easier. Among these are λ-transitions, not having to explicitly show the dead state (or transitions going to it), and multiple transitions from the same state with the same label.

Solution:


4.
Present a regular expression that describes the language accepted by the DFA shown to the right.

Hint: As building blocks, devise regular expressions describing

Solution: The first two building blocks mentioned in the hint are, respectively, a and bb*a. Their union is a + bb*a (which simplifies to b*a), describing all strings by which to first arrive at q1 from q0.

The third building block is also b*a, describing all strings by which to first arrive at q0 from q1.

The concatenation of the first two, b*ab*a, describes all strings by which to first return to q0 having left it earlier. To describe all the strings by which to get to q0 (the lone accepting state) from itself (the initial state), leaving and returning any number of times, it suffices to apply Kleene closure, thereby resulting in the solution (b*ab*a)*. Informally, this describes the set of strings over {a,b} that have an even number of a's and, if non-empty, end with a.

The astute reader will recognize the similarity of the language of this problem and that of Problem 1.


5. Let M be a six-state minimal DFA with input alphabet {a} and having only one final/accepting state.

(a) Suppose that L(M) is finite. Describe L(M), exactly. (There is only one possibility.)

Solution: The only DFA consistent with this description is the one shown below, which accepts { aaaa }.

Why is this the unique DFA consistent with the description? In the first place, the lone accepting state could not occur on a cycle or else the accepted language would be infinite. In the second place, if the accepting state were any among λ, a, aa, or aaa, then all the (two or more) states that followed it would be dead and thus the DFA would not be minimal.

(b) Suppose that L(M) is infinite and that aa is the shortest member of L(M). Then L(M) is one of three possible languages. Describe them, exactly.

Solution: The three DFAs consistent with this description are the ones shown below. Their languages are also shown.

L = L(aa(a6)* ) = { a6k+2 | k≥0 }
L = L(aa(a5)* ) = { a5k+2 | k≥0 }
L = L(aa(a4)* ) = { a4k+2 | k≥0 }