0% found this document useful (0 votes)
191 views2 pages

HW2 Solutions 2015 Spring

This document contains the solutions to homework problems for a course on formal languages. The problems involve finding regular expressions and grammars for various languages, as well as constructing finite state automata. The solutions demonstrate techniques for manipulating regular expressions and describing the transitions in finite state machines.

Uploaded by

abrar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views2 pages

HW2 Solutions 2015 Spring

This document contains the solutions to homework problems for a course on formal languages. The problems involve finding regular expressions and grammars for various languages, as well as constructing finite state automata. The solutions demonstrate techniques for manipulating regular expressions and describing the transitions in finite state machines.

Uploaded by

abrar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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
as.
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