Midterm Mockup
Midterm Mockup
1. [10 points] Write the grammar (just state the production rules) for the following language (Σ = {0, 1}):
L = w ∈ {0, 1}∗
w starts with 0 and does not contain two consecutive 0’s or 1’s .
Page 1 of 4
CSc 135 Midterm Mockup Exam
3. [15 points] Prove that the following language is regular by designing a DFA (no need to include the
trap state) that recognizes it:
∗ w contains an even number of a’s, an odd number of b’s,
L = w ∈ {a, b} .
and does not contain the substring ab
Draw the transition graph of the DFA.
Hint: note that the strings in the language does NOT contain ab. What does that mean? – Use the
answer to this question to help you in designing the DFA.
4. Write the regular expression that generates each of the following languages (Σ = {0, 1}):
(a) [10 points]
L = w ∈ {0, 1}∗
w contains at least two 0’s and at most one 1 .
5. [15 points] Consider the DFA with the following transition function (the first row specifies the states
and the first column specifies the symbols – for example, δ(q0 , 0) = q4 ):
δ q 0 q1 q2 q 3 q4 q5 q 6
0 q 4 q3 q6 q 6 q0 q1 q 1
1 q 1 q0 q0 q 4 q3 q4 q 0
q0 is the initial state and q1 , q3 and q6 are the final states.
Use the state reduction algorithm we discussed to eliminate inaccessible states, and find and merge
indistinguishable states. Make sure to write down your process and draw the transition graph of the
final (reduced/simplified) DFA.
6. Consider the following CFG and perform each of the operations that follows:
S → A | Ab | AB
A → Ca | λ
B → Abb | bD
C→λ
D → aB
Use the “|” (or) notation whenever necessary similar to the grammar written above to make the
production rules as compact as possible.
(b) [8 points] Remove the unit-productions from the grammar in the previous part. Also, draw the
dependency graph.
(c) [9 points] Remove the useless variables from the grammar in the previous part. Also, draw the
dependency graph.