You are on page 1of 2

DCP3122 Introduction to Formal Languages, Spring 2015 2-Apr-2015

Homework 2 - Solution
Instructor: Prof. Wen-Guey Tzeng

1. Find all strings in L((a + b)∗ b(a + ab)∗ ) of length less than four.
Ans. b, ab, ba, bb, aab, bbb, abb, bab, baa, aba, bba.

2. Find a regular expression for the set {an bm : (n + m) is even}.


Ans. (aa)∗ (bb)∗ + a(aa)∗ b(bb)∗ .

3. What language do the expression (∅∗ )∗ and a∅ denote?


Ans. L((∅∗ )∗ ) = (L(∅∗ ))∗ = (∅∗ )∗ = {λ}∗ = {λ}, L(a∅) = L(a)L(∅) = ∅.

4. Find a regular expression for L = {w ∈ {0, 1}∗ : w has exactly one pair of consecutive zeros}.
Ans. (1 + 01)∗ 00(1 + 10)∗ .

5. Let Σ = {a, b, c}. Give a regular expression for the all strings containing no more than three
a’s.
Ans. (b + c)∗ + (b + c)∗ a(b + c)∗ + (b + c)∗ a(b + c)∗ a(b + c)∗ + (b + c)∗ a(b + c)∗ a(b + c)∗ a(b + c)∗ .

6. Let Σ = {0, 1}. Write a regular expression for all strings not ending in 01.
Ans. λ + 0 + 1 + (0 + 1)∗ (00 + 10 + 11).

7. Find an NFA that accepts the language L(ab∗ aa + bba∗ b∗ ).


Ans. The following graph represents the NFA M = ({q0 , q1 , . . . , q9 }, {a, b}, δ, q0 , {q9 }) that
accepts L(ab∗ aa + bba∗ b∗ ), where δ is described as in the graph.

8. Find a DFA that accepts L = L(ab∗ a∗ ) ∩ L((ab)∗ ba).


Ans. L = L(ab∗ a∗ ) ∩ L((ab)∗ ba) = {abba}. The following graph represents the DFA M =
({q0 , q1 , . . . , q5 }, {a, b}, δ, q0 , {q4 }) that accepts L, where δ is described as in the graph.

1-1
9. Find the minimal DFA that accepts L(a∗ bb) ∪ L(ab∗ ba).
Ans. The following graph represents an NFA MN = ({q0 , q1 , . . . , q6 }, {a, b}, δ, q0 , {q6 }) that
accepts L(a∗ bb) ∪ L(ab∗ ba), where δ is described as in the graph.

We then transform MN into a DFA MD = ({q012 , q14 , q1 , q3 , q345 , q456 , q6 , q45 , qx }, {a, b}, δ, q012 , {q6 , q456 })
that accepts L(a∗ bb) ∪ L(ab∗ ba), where δ is described as in the graph.

By using the mark procedure, we can finally partition the state set as {q012 }, {q14 }, {q1 },
{q3 }, {q345 }, {q456 }, {q6 }, {q45 }, and {qx }. Thus, such a DFA is minimal.

10. Find a regular expression for the language accepted by the following automata.

Ans. a∗ ba∗ .

11. Find a regular grammar that generates the language L(aa∗ (ab + a)∗ ).
Ans. The grammar G = ({S, A, B}, {a, b}, S, P ) with productions S → aA, A → aA|B, B →
abB|aB|λ.

12. Find a regular grammar that generates the set of all real numbers in C.
Ans. The grammar G = ({S, A, B, C, D}, {+, −, ., 0, 1, . . . , 9}, S, P ) with productions S →
+(0 + 1 + . . . + 9)A| − (0 + 1 + . . . + 9)A, A → (0 + 1 + . . . + 9)A|(0 + 1 + . . . + 9)B, B → .C,
C → [0 − 9]C.

1-2

You might also like